First Java Program using Notepad

You can write Java program using any IDE like Netbeans, Eclipse etc or you can directly write Java program using Notepad and can compile using CMD (command prompt)


Let’s write the First Java Program using Notepad

Step 1. Create a text document with name

Step 2. open the created file and write the following code


Now open the CMD

Go to the path where your is kept then give the file name to compile it



You can see the command javac

Here by this command we are calling java compiler to compile file

Now press enter and this creates a new file with name Hello.class

To run the file type java Hello i.e. java <Class Name>


Note: You have to set the path first to run the java program if your program is any where except bin folder.

Introduction to Java

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995.

It is intended to let application “write once, run anywhere” (WORA), means code that run one machine/platform does not need to be recompiled to run on another.



  1. It should be ‘Simple’ Object oriented and familiar
  2. It should be robust and secure
  3. It should be architecture neutral and portable
  4. It should be executed with high performance
  5. It should be interpreted, threaded and dynamics



The Java compiler is actually divided into two parts

  1. Java Compiler
  2. JVM


1. Java Compiler

Java compiler is use to compile java programs i.e. file with extension “.java”

Java compiler takes .java file as input and produce .class file as output.

This .class file is platform neutral.


2. Now the JVM comes.

JVM stands for Java Virtual Machine.

JVM loads the class files and either interprets the bytecode or just-in-time compiles it to machine code and then possibly optimizes it using dynamic compilation.


Just-in-time Compiler (JIT)

JIT is the part of the Java Virtual Machine (JVM) that is used to increase the speed whenever the byte code is converted into machine code. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.

JVM is different for different machines.


You can consider the following way example to understand.

Suppose there is a building with ground and the first floor. The compiler is sitting in ground floor which welcomes or accepts the .java file and compiles it to .class file (byte code).

Now this byte code goes to the JVM that is on the first floor where the JVM do its work.





JRE stands for Java Runtime Environment. JRE contains JVM plus set of classes and interfaces which are loaded to create the environment i.e. the Java Runtime Environment.



JDK stands for Java Development Kit. JDK contains JRE along with various development tools like Java libraries, Java source compilers, Java debuggers, bundling and deployment tools.


Now here question arises that what is the overall picture or functionality of JDK, JVM, and JRE?

Answer to this question is the following figure.  Now it’s the time to complete the figure.



How to set classpath

Lets see how to set classpath and why there is a need to set classpath.

Suppose you are working on a java project using notepad or without using any IDE then to make the additional necessary jar files available to your project, you need to set each jar file by giving full path of the jar file in the classpath.

You can define your all the jar file once and no need to give classpath every time you start command prompt , this can be done as follows:

Right click on my computer > properties > advanced system settings >Environment variables >


Click on “New” below user variables.



Variable name: classpath

Variable value: specify complete path like C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar;.


click ok.


Now you will see a new variable with name classpath and in value the specified path of jar file with name
If you wan to add another jar , for this click edit > add semicolon <;> then path of other jar.