Introduction to Java

Why is Java platform independent? Why not C & C++?

  • When you run a C native code, it will be executed immediately. Whereas in the case of Java, when you run the byte code, the byte code will first be converted into native code and then be will executed.

  • When we say that java is platform independent, it means that the byte code is independent of any platforms.

  • When you create a .exe, it captures a machine code, where as when we create a byte code it does not capture machine code.

  • Java programming language was developed by the Sun Microsystems and was launched in 1995. The language has had many versions, the latest being Java SE 8, and still finds relevance in the industry.


Human readable code with java syntax (.java file) ⇒ (javac compiler) ⇒ Byte Code (.class file) ⇒ (java interpreter) ⇒ native code

The components involved in writing program up to getting the output are:

  • java.exe set up file

  • Javac compiler, which checks syntax

  • Java interpreter, which understands only byte code and converts it to native code

  • Human readable code with proper java syntax, i.e. the Java File

  • Byte code - after the compiler compiles the Java File, i.e. Class file

  • Native code - We see output same in background is native code out of all these, only the byte code is platform independent

The Java compiler is a programme which is implemented in C and C++ with the name javac.exe. It compiles the text file into a platform independent java file.

The compiler is responsible for the following tasks:

  • Checking syntactical mistakes or Syntax Error.

  • Converting source code into byte code with the help of JVM.

  • Adding additional code to your code if required. This can be observed by using a de- compiler, which is called cavaj.

Java interpreter is a programme which is implemented in C and C++ and goes by the name java.exe. It basically reads the byte code and executes it.

This java interpreter is responsible for the following tasks:

  • Converting the byte code to native code line by line.

  • Executing the native code.

The full form of JIT is Just In Time. It is a programme written in C and C++ with the name Java.exe, and is provided from Java 2 version. The JIT compiler’s task is the same as Java interpreter’s. It converts the entire byte code into native code once and then executes the same.

JVM, or Java Virtual Machine, is a specification provided by Sun whose implementation provides the environment to run our Java Applications.

JVM implementations are called JRE (JAVA RUNTIME ENVIRONMENT) [The next section will give you further details about JVM].

The Java Development Kit (JDK) is a software development environment used for developing Java applications and applets. It includes the Java Runtime Environment (JRE), an interpreter/ loader (java), a compiler (javac), an archive (jar), a documentation generator (java doc) and other tools needed in Java development. People new to Java may be confused about whether to use the JRE or the JDK.

To run Java applications and applets, simply download the JRE. However, to develop Java applications and applets as well as run them, the JDK is useful.

Java developers are initially presented with two JDK tools, java and javac. Both can be run from the command prompt. Java source files are simple text files saved with a .java extension. After writing and saving the Java source code, the javac compiler is invoked to create a .class file. Once the .class file is created, the 'java' command can be used to run the java program.

For developers who wish to work in an integrated development environment (IDE), a JDK bundled with Net beans can be downloaded from the Oracle website. Such IDEs speed up the development process by introducing point-and-click and drag-and- drop features for creating an application.

There are different JDKs for various platforms. The supporting platforms include Windows, Linux and Solaris. Mac users need a different software development kit, which includes adaptations of some tools found in the JDK.

Click on the installer called Java.exe setup Select radio button I accept ……..

  1. Install
  2. Finish
  3. Create First Simple Program in Java

Open notepad write as shown below:

Save with the name Hello.java

javac Hello.Java    // Compile File

We may get some error after this on command prompt.

java program error on command prompt

This is because we have not set the path for java and DOS is unable to understand what javac is. We will now configure our system to recognize javac by setting a path like shown below. When you set the path on the command line (see below), it is temporary.

set temporary path of java on command prompt

You can set the path permanently in the system environment variables like this:

  • Right click on My computer, Click on Properties

  • Click on Advanced System Settings

  • Click on Advanced tab

  • Click on Environment Variables

Add two variables (path and classpath) as shown in the diagram below:

set the path permanently of java bin in the system environment variables

set the path permanently of java lib in the system environment variables
  • A ‘C’ program is platform dependent

  • A Java(.class file) program is platform independent

  • The Java compiler is platform dependent

  • Java interpreter is platform dependent

  • JVM is platform dependent

  • JRE is platform dependent