3 - Content - Introduction To Java, JVM, JDK PDF
3 - Content - Introduction To Java, JVM, JDK PDF
3a.1 Objective
Introduction to Java
History of Java
Brief to Java Platform, JVM, JDK, JRE
Installation of JDK and its configurations
Run a sample program
3a.2 Content
Sun Microsystems was acquired by the Oracle Corporation in 2010. Now oracle is owning
Java.
Java is Simple:There are various features that makes the java as a simple language.
because Java is easy to learn and developed by taking the best features from other
languages mainly like C and C++.
Java is Platform Independent-Java provides the facility to "Write once -Run any
where"(Known as platform independent).
Java is Robust-Java has the strong memory allocation and automatic garbage collection
mechanism. It carries out type checking at both compile and runtime making sure that every
data structure has been clearly defined and typed. compiler checks the program for any
error and interpreter checks any run time error that every data structure is clearly defined
and typed. Java manages the memory automatically by using an automatic garbage
collector. all the above features makes Java language robust.
As desirable as dynamic, networked programs are, they also present serious problems in the
areas of security and portability
TCS Internal
Let us begin by writing our first Java program that prints a message "Hello, world!" to the
display console, as follows:
◦ Hello World program in java
Step 1: Write the Source Code: Enter the following source codes using a programming text
editor (such as TextPad or NotePad++ for Windows or gedit for UNIX/Linux/Mac) or an
Interactive Development Environment (IDE) (such as Eclipse or NetBeans - Read the
respective "How-To" article on how to install and get started with these IDEs – to see more
about IDE refer the Glossary).
Save the source file as "Hello.java". A Java source file should be saved with a file extension
of ".java". The filename shall be the same as the classname - in this case "Hello".
// Write simple Hello Program in Java
Step 2: Compile the Source Code: Compile the source code "Hello.java" into portable
bytecode "HelloWorld.class" using JDK compiler "javac". Start a CMD Shell (Windows) or
Terminal (UNIX/Linux/Mac) and issue this command:
before run java file you should set the path and classpath
path: to instruct compiler that where your JDK is installed
How to set the path:
set PATH=.;C:\Program Files\Java\jdk1.5.0\bin(for example:
C:\Program Files\Java\jdk1.5.0\bin (Provided your jdk installed in the given path)
See the below screen shots in order to run any java program in command prompt mode
TCS Internal
Figur
e -1 How to run Java Program in Command Prompt Mode
Summary:
Java is platform Independent and Portable.
Java is Robust and secured.
Java is pure object oriented language.
Java does compilation as well Interpretation.
Java latest version of JDK 7(Current version is being used in Industry)
JDK and JRK has to be installed in order to Java program.
Diamond Syntax
JVM is:
A specification where working of Java Virtual Machine is specified. But
implementation provider is independent to choose the algorithm. Its implementation has
been provided by Sun and other companies.
An implementation Its implementation is known as JRE (Java Runtime
Environment).
Runtime Instance Whenever you write java command on the command prompt to
run the java class, and instance of JVM is created.
The JVM performs following operation:
Loads code
Verifies code
Executes code
Provides runtime environment.
The below diagram will explain in details how JVM converts java file into class and byte code.
JVM Architecture:
TCS Internal
3a.2.7 JDK - Java Development Kit
A Java Development Kit (JDK) is a program development environment for writing Java
applications. It consists of a run time environment that sits on top of the operating system
layer and also the tools and programming that developers need to compile, debug, and run
applications written in the Java language.
The JDK (Java Development Kit) is used for developing java applications. The JDK includes
JRE, set of API classes, Java compiler, Webstart and additional files needed to write Java
applications. The JDK (Java Development Kit) contains software development tools which are
used to compile and run the Java program. Both JDK and JRE contains the JVM
Figure -1 JDK
Download JDK 5 or above setup for installation. Link to download latest version of java, jdk 7 is given
below.
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Set the environment variables CLASSPATH and JAVA_HOME after JDK installation.
Command Prompt is a feature of Windows that provides an entry point for typing MS-DOS (Microsoft
Disk Operating System) commands and other computer commands. The most important thing to know
is that by typing commands, you can perform tasks on your computer without using the Windows
graphical interface.
When you're using Command Prompt, the term command prompt also refers to the right angle bracket
(>, also known as the greater than character) that indicates the command line interface can accept
commands. Other important information, such as the current working directory (or location) where the
command will be run, can be included as part of the command prompt.
For example, if you open the Command Prompt window and see the C:\> command prompt with a
blinking cursor to the right of the right angle bracket character (>), you know that the command you
enter will be run on the entire C drive of your computer.
Open the Command Prompt window by clicking the Start button Picture of the Start button, clicking
All Programs, clicking Accessories, and then clicking Command Prompt.
Steps to run a java program is described in chapter 3b. We will provide you a sample Java program for
execution.
Create a java file “TestClass.java” and put the sample code given below in it. We will study more on
how to write a Java class later in this course. This is just to understand how to compile a Java program
file and how to execute it using command prompt.
class TestClass {
TCS Internal
public static void main(String args[])
{
System.out.println("TestClass is running fine.");
}
}
After execution of TestClass, you should get the message on the command prompt as "TestClass is
running fine". Have you got the output on command prompt / console.
http://en.wikipedia.org/wiki/Java_Development_Kit
http://www.javatpoint.com/difference-between-jdk-jre-and-jvm
TCS Internal