0% found this document useful (0 votes)
14 views15 pages

OOP Lec2

Uploaded by

unkkggo104
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views15 pages

OOP Lec2

Uploaded by

unkkggo104
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Lecture No.

2
First Java Program | Hello World Example
In this lecture, we will learn how to write the simple program of Java.
We can write a simple hello Java program easily after installing the JDK.
To create a simple Java program, you need to create a class that contains
the main method.
Let's understand the requirement first.
The requirement for Java Hello World Example

For executing any Java program, the following software or application


must be properly installed.
• Install the JDK if you don't have installed it, download the JDK and
install it.
• Set path of the jdk/bin directory.
http://www.javatpoint.com/how-to-set-path-in-java
• Create the Java program
• Compile and run the Java program
Creating Hello World Example
Save the above file as Simple.java
Let's create the hello java program:
javac
To compile:
• class Simple{ Simple.java
To execute: java Simple
• public static void main(String args[])
•{ Output:
Hello Java
• System.out.println("Hello Java");
• }
•}
Compilation Flow:
• When we compile Java program using javac tool, the Java compiler
converts the source code into byte code.
Parameters used in First Java Program
Let's see what is the meaning of class, public, static, void, main, String[],
System.out.println().
• class keyword is used to declare a class in Java.
• public keyword is an access modifier that represents visibility.
• It means it is visible to all.
• static is a keyword. If we declare any method as static, it is known as the static
method. The core advantage of the static method is that there is no need to
create an object to invoke the static method. The main() method is executed by
the JVM, so it doesn't require creating an object to invoke the main() method. So,
it saves memory.
Parameters used in First Java Program…
• void is the return type of the method. It means it doesn't return any
value.
• main represents the starting point of the program.
• String[] args or String args[] is used for command line argument. We
will discuss it in coming section.
• System.out.println() is used to print statement. Here, System is a
class, out is an object of the PrintStream class, println() is a method of
the PrintStream class. We will discuss the internal working of
System.out.println() statement in the coming section.
Difference between JDK, JRE, and JVM

• 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.
• The JVM performs the following main tasks:
• Loads code
• Verifies code
• Executes code
• 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:
• Standard Edition Java Platform
• Enterprise Edition Java Platform
• Micro Edition Java Platform
• 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
• 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?
• 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 Oracle 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, an instance of JVM is created.
What JVM does
The JVM performs following operation:
• Loads code
• Verifies code
• Executes code
• Provides runtime environment
JVM provides definitions for the:
• Memory area
• Class file format
• Register set
• Garbage-collected heap
• Fatal error reporting etc.
Practice
• Write a simple program of java that should add two numbers
• Write a simple program of java that shoult print (9,8,7,6,5,4,3,2)
• Write a simple program of java that should display your bio data.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy