You are on page 1of 10

What is Java?

JAVA was developed by Sun Microsystems Inc in 1


991, later acquired by Oracle Corporation.It was de
veloped by James Gosling and Patrick Naughton.

It is a simple programming language. Writing, com


piling and debugging a program is easy in java. It h
elps to create modular programs and reusable cod
e.

< • •
Java Virtual Machine (JVM)

This is generally referred as JVM. Before, we discuss a


bout JVM lets see the phases of program execution. Ph
ases are as follows: we write the program, then we com
pile the program and at last we run the program.

l.Writing of the program is of course done by java progr


ammer like you and me.
•Compilation of program is done by javac compiler, jav
ac is the primary java compiler included in java develop
ment kit (JDK). It takes java program as
input and generates java bytecode as output.
•In third phase, JVM executes the bytecode generated
by compiler. This is called program run phase.
ByteCode

As discussed above, javac compiler of JDK compiles t


he java source code into bytecode so that it can be ex
ecuted by JVM.The bytecode is saved in a .class file
by compiler.

<•
. .
7

<.... ...-- -

/
Java Development Kit ( JDK )

While explaining JVM and bytecode, Ihave used the ter


m JDK. Let's discuss about it.As the name suggests thi
s is complete java development kit that includes JRE (J
ava Runtime Environment), compilers and various tools
like JavaDoc, Java debugger etc.
In order to create, compile and run Java program you w
ould need JDK installed on your computer.
Java Runtime Environment ( JRE )

JRE is a part of JDK which means that JDK includes JRE.


When you have JRE installed on your system, you can run
a java program however you won't be able to compile it. JR
E includes JVM, browser plugins and applets support. Whe
n you only need to run a java program on your computer, y
ou would only
need JRE.
Lets understand what above program consists of and
its keypoints.

class :class keyword is used to declare classes in Ja


va

public :It is an access specifier. Public means this fu


nction is visible to all.
static : static is again a keyword used to make a function
static. To execute a static function you do not have to cre
ate an Object of the class.The main() method here is calle
d by JVM,without creating any object for class.

void :It is the return type, meaning this function will not ret
urn anything.

main : main() method is the most important method in a J


ava program.This is the method which is executed, hence
all the logic must be inside the main() method. If a java cl
ass is not having a main() method, it causes compilation
error.
StringO args : This represents an array whose type i
s String and name is args. We will discuss more abo
ut array in Java Array section.

System.out.println :This is used to print anything on th


e console like printf in C language.
Steps to Compile and Run your first J
ava program

Step l: Open a text editor and write the code as above.

Step 2: Save the file as Hello.java

Step 3: Open command prompt and go to the directory w


here you saved your first java program assuming it is sav
ed in C drive.

<..
<
,
Step 4: Type javac Hello.java and press Return(Enter
KEY) to compile your code.This command will call the
Java Compiler asking it to compile the specified file.If t
here are no errors in the code the command prompt w
ill take you to the next line.

Step 5: Now type java Hello on command prompt to r


un your program.

Step 6: You will be able to see Hello world program pr


inted on your command prompt.

You might also like