1.2. Java First Programm
1.2. Java First Programm
Java Program
Let us look at a simple code that will print the words Hello World.
Dynamic
Java is a dynamic language. It supports the dynamic loading of classes. It means
classes are loaded on demand. It also supports functions from its native languages,
i.e., C and C++. Java supports dynamic compilation and automatic memory management
(garbage collection).
1. #include <iostream>
3. int main() {
5. return 0;
1. class Simple{
3. System.out.println("Hello Java");
4. }}
Compilation Flow:
When we compile Java program using javac tool, the Java compiler converts the source code into
byte code.
To write the simple program, you need to open notepad by start menu -> All Programs -> Accessories -
> Notepad and write a simple program as we have shownbelow:
As displayed in the above diagram, write the simple program of Java in notepad and saved it as
Simple.java. In order to compile and run the above program, you need to open the command prompt
by start menu -> All Programs -> Accessories -> command prompt. When we have done with all the
steps properly, it shows the following output:
Difference between JDK, JRE, and JVM
1. A summary of JVM
2. Java Runtime Environment (JRE)
3. Java Development Kit (JDK)
We must understand the differences between JDK, JRE, and JVM before proceeding further
to Java. See the brief overview of JVM here.
If you want to get the detailed knowledge of Java Virtual Machine, move to the next page.
Firstly, let's see the differences between the JDK, JRE, and JVM.
JVM
JVM (Java Virtual Machine) is an abstract machine. It is called a virtual machine because it
doesn't physically exist. It is a specification that provides a runtime environment in which Java
bytecode can be executed. It can also run those programs which are written in other languages
and compiled to Java bytecode.
JVMs are available for many hardware and software platforms. JVM, JRE, and JDK are platform
dependent because the configuration of each OS is different from each other. However, Java is
platform independent. There are three notions of the JVM: specification, implementation,
and instance.
o Loads code
o Verifies code
o Executes code
o Provides runtime environment
JRE
JRE is an acronym for Java Runtime Environment. It is also written as Java RTE. The Java
Runtime Environment is a set of software tools which are used for developing Java applications.
It is used to provide the runtime environment. It is the implementation of JVM. It physically
exists. It contains a set of libraries + other files that JVM uses at runtime.
The implementation of JVM is also actively released by other companies besides Sun Micro
Systems.
JDK
JDK is an acronym for Java Development Kit. The Java Development Kit (JDK) is a software
development environment which is used to develop Java applications and applets. It physically
exists. It contains JRE + development tools.
JDK is an implementation of any one of the below given Java Platforms released by Oracle
Corporation:
The JDK contains a private Java Virtual Machine (JVM) and a few other resources such as an
interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation generator
(Javadoc), etc. to complete the development of a Java Application.
JVM (Java Virtual Machine) Architecture
1. Java Virtual Machine
2. Internal Architecture of JVM
JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime
environment in which java bytecode can be executed.
JVMs are available for many hardware and software platforms (i.e. JVM is platform dependent).
What is JVM
It is:
What it does
The JVM performs following operation:
o Loads code
o Verifies code
o Executes code
o Provides runtime environment
o Memory area
o Class file format
o Register set
o Garbage-collected heap
o Fatal error reporting etc.
JVM Architecture
Let's understand the internal architecture of JVM. It contains classloader, memory area,
execution engine etc.
2.Several Operators
int i=integer.MAX_VALUE;
System.out.println(i);
i=i+1;
System.out.println(i);
System.out.println(integer.MAX_VALUE);
}}
3.VARIABLES & STRINGS IN JAVA
public class String{
public static void main(String []args){