Chapter 1
Chapter 1
Ashok
Core Java
Material
By Mr. Ashok
1
Ashok IT, Phone: +91 9985396677 , Email: [email protected], www.ashokitech.com
Core Java Mr. Ashok
Chapter – 1
• Java Introduction
• Java Features
• Java Installation
• Java Program Execution Flow
• Java Programming Elements
• Java Programs Development
• Compilation
• Execution
• Translators
• JVM Architecture
2
Ashok IT, Phone: +91 9985396677 , Email: [email protected], www.ashokitech.com
Core Java Mr. Ashok
What is Java
-> Java is a programming language
-> Java developed by James Gosling & his team in 1991 at Sun Microsystem Company
-> Initially they named it as ‘OAK’ programming language
-> In 1995, OAK language renamed to JAVA
Note: Oracle Corporation acquired Sun Microsystem in 2010. Now java is under license of
Oracle corporation
-> Java is a free & open-source software
-> 3 billion devices run on Java language
-> Java is one of the most popular languages in the world
-> Java can run on any platform (It is platform independent)
3
Ashok IT, Phone: +91 9985396677 , Email: [email protected], www.ashokitech.com
Core Java Mr. Ashok
2) Platform Independent: Unlike other programming languages such as C, C++ etc which
are compiled into platform specific machines. Java is guaranteed to be write-once, run-
anywhere language.
When we compile java code it will generate bytecode. This bytecode is platform
independent and can be run on any machine, plus this bytecode format also provide
security. Any machine with Java Runtime Environment can run Java Programs.
4
Ashok IT, Phone: +91 9985396677 , Email: [email protected], www.ashokitech.com
Core Java Mr. Ashok
5
Ashok IT, Phone: +91 9985396677 , Email: [email protected], www.ashokitech.com
Core Java Mr. Ashok
➔ After installing java, we can see below two folders (JDK & JRE)
Note: After installing java software, we need to set PATH for java software to use it.
Step-2) Set Path for Java
-> Go To Environment Variables
-> Go To System Environment Variables
-> Edit Path
-> Add path up to JDK bin directory
6
Ashok IT, Phone: +91 9985396677 , Email: [email protected], www.ashokitech.com
Core Java Mr. Ashok
Step-3) Verify PATH Setup (Open command prompt and execute below command)
Note: If you are getting message like above that means, java installation and PATH setup is
success.
Step-1: We will write source code and we will save that code in a file using .java extension
Step-2: We will compile source code using java compiler (it will generate byte code)
Step-3: We will execute .class file ( JVM will convert byte code into machine code & gives
output)
7
Ashok IT, Phone: +91 9985396677 , Email: [email protected], www.ashokitech.com
Core Java Mr. Ashok
-> Package statement is used to group our classes. At most we can write only one package
statement in one java program and package statement should be the first statement in the
program.
-> Import statements are used to import one program into another program. We can write
multiple import statements in one program (It depends on requirement). We should write
import statements after package statement only.
-> Class is the most import part in java program. Class is a plan to define program elements.
Inside class we will write variables and methods.
-> Variables are used to store the data. We can write any no. of variables inside a class.
-> Methods are used to perform action. Application business logic we will write inside
methods. A can class can have any no. of methods.
Developing First Java Program
Step-1: Open any text editor (notepad / notepad ++ / edit plus)
Step-2: Write below java program
8
Ashok IT, Phone: +91 9985396677 , Email: [email protected], www.ashokitech.com
Core Java Mr. Ashok
➔ We are able to see .class file that means our program compilation is successful.
-> We are able to see “Welcome To Ashok IT” as output of our program that means our
program executed successfully.
Note: In Realtime, we will use IDE to develop java programs/ project.
9
Ashok IT, Phone: +91 9985396677 , Email: [email protected], www.ashokitech.com
Core Java Mr. Ashok
Translators
-> Translators are used to convert from one format to another format
-> We have 3 types of translators
1) Interpreter
2) Compiler
3) Assembler
-> Interpreter will convert the program line by line (performance is slow)
-> Compiler will convert all the lines of program at a time (performance is fast)
-> Assembler is used to convert assembler programming languages into machine language
JVM
-> JVM stands for Java Virtual Machine (We can't see with our eyes)
-> JVM will be part of JRE software
-> JVM is responsible for executing java programs
-> JVM will allocate memory required for program execution & de-allocate memory when it
is not used
-> JVM will convert byte code into machine understandable format
JVM Architecture
10
Ashok IT, Phone: +91 9985396677 , Email: [email protected], www.ashokitech.com
Core Java Mr. Ashok
11
Ashok IT, Phone: +91 9985396677 , Email: [email protected], www.ashokitech.com