DEV Community

Cover image for 1.1 simple hello world program
Raghav Khanna
Raghav Khanna

Posted on

1.1 simple hello world program

NOTE- THIS IS SECOND PART OF MY FIRST ARTICLE ABOUT JAVA YOU CAN CHECK IT BY FOLLOWING MY PROFILE. CHHERS...!

1.2. Hello world Java program
// a small Java program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
1.3. Java virtual machine
The Java virtual machine (JVM) is a software implementation of a computer that executes programs like a real machine.

The Java virtual machine is written specifically for a specific operating system, e.g., for Linux a special implementation is required as well as for Windows.

jvmintroduction10
Java programs are compiled by the Java compiler into bytecode. The Java virtual machine interprets this bytecode and executes the Java program.

1.4. Java Runtime Environment vs. Java Development Kit
A Java distribution typically comes in two flavors, the Java Runtime Environment (JRE) and the Java Development Kit (JDK).

The JRE consists of the JVM and the Java class libraries. Those contain the necessary functionality to start Java programs.

The JDK additionally contains the development tools necessary to create Java programs. The JDK therefore consists of a Java compiler, the Java virtual machine and the Java class libraries.

1.5. Development Process with Java
Java source files are written as plain text documents. The programmer typically writes Java source code in an Integrated Development Environment (IDE) for programming. An IDE supports the programmer in the task of writing code, e.g., it provides auto-formating of the source code, highlighting of the important keywords, etc.

At some point the programmer (or the IDE) calls the Java compiler ( javac ). The Java compiler creates the bytecode instructions. These instructions are stored in .class files and can be executed by the Java Virtual Machine.

1.6. Garbage collector
The JVM automatically re-collects the memory which is not referred to by other objects. The Java garbage collector checks all object references and finds the objects which can be automatically released.

While the garbage collector relieves the programmer from the need to explicitly manage memory, the programmer still need to ensure that he does not keep unneeded object references, otherwise the garbage collector cannot release the associated memory. Keeping unneeded object references are typically called memory leaks.

1.7. Classpath
The classpath defines where the Java compiler and Java runtime look for .class files to load. These instructions can be used in the Java program.

For example, if you want to use an external Java library you have to add this library to your classpath to use it in your program.

Top comments (1)

Collapse
 
erraghavkhanna profile image
Raghav Khanna

Comments and improvement suggestions are welcome ❀