1. INTRODUCTION ON JAVA PROGRAMMING
MS. K.NANTHINI
ASSISTANT PROFESSOR,
KONGU ENGINEERING COLLEGE,
ERODE, TAMILNADU,
2. Overview
-Programming language and computing platform
-first released by Sun Microsystems in 1995
-Java is a simple, general-purpose, object-oriented, robust, secure, architecture-neutral,
portable, high-performance, multithreaded computer language
-JDK
-JRE
-JVM
write once, run anywhere" (WORA)
3. History
-James Gosling from Sun Microsystems and his team began designing the first version of Java
aimed at programming home appliances
-Name:Oak-Green-Java
4. Java Platform
A platform is the hardware or software environment in
which a program runs.
Popular Platforms : Microsoft Windows, Linux, Solaris OS,
and Mac OS - combination of the operating system and
underlying hardware
But Java is software-only platform that runs on top of other
hardware-based platforms
-Components
7. Components of Java Architecture
Java Virtual Machine:
The JVM is a Java platform component that provides an environment for executing Java
programs. JVM interprets the byte code into machine code which is executed in the machine in
which the Java program runs.
Java Runtime Environment:
The JRE software builds a runtime environment in which Java programs can be executed. The JRE
is the on-disk system that takes your Java code, combines it with the needed libraries, and starts
the JVM to execute it. The JRE contains libraries and software needed by your Java programs to
run
Java Development Kit:
The Java Development Kit (JDK) is a software development environment used to develop Java
applications and applets
9. (Cont.,)
Class Loader: Class loader is a subsystem of JVM. It is used to load class files. Whenever we run
the java program, class loader loads it first.
Class method area: It is one of the Data Area in JVM, in which Class data will be stored. Static
Variables, Static Blocks, Static Methods, Instance Methods are stored in this area.
Heap: A heap is created when the JVM starts up. It may increase or decrease in size while the
application runs.
Stack: JVM stack is known as a thread stack. It is a data area in the JVM memory which is
created for a single execution thread. The JVM stack of a thread is used by the thread to store
various elements i.e.; local variables, partial results, and data for calling method and returns.
10. (Cont.,)
Native stack: It subsumes all the native methods used in your application.
Execution Engine:
JIT compiler
Garbage collector
JIT compiler: The Just in Time is a part of the runtime environment. It helps in improving the
performance of Java applications by compiling bytecodes to machine code at run time. The JIT
compiler is enabled by default. When a method is compiled, the JVM calls the compiled code of that
method directly. The JIT compiler compiles the bytecode of that method into machine code,
compiling it “just in time” to run.
Garbage collector: As the name explains that Garbage Collector means to collect the unused
material. Well, in JVM this work is done by Garbage collection. It tracks each and every object
available in the JVM heap space and removes unwanted ones.
11. Types of Java Applications
-Application Programs
-Applet Programs
12. Features
- Simple, Object Oriented, and Familiar
- Robust and Secure
- Architecture Neutral and Portable
- High Performance
- Interpreted, Threaded, and Dynamic
13. Drawbacks
- Slow performance
- Automatic memory management
- Different JVM for different platform
- No support for low-level programming
- Poor features in GUI
14. Setting Java
- Download the latest version of JDK (Java Development Kit) on your machine
- set environment variable to point to correct installation directory
- An Environment variable is an object on a computer that stores a value(key-value pair), which
can be referenced by one or more software programs in Windows
- Path and Class Path :
PATH is an environment variable which is used to locate JDK binaries like "java" or "javac"
command used to run java program and compile java source file.
CLASSPATH environment variable is used by System or Application ClassLoader to locate and
load compile Java bytecodes stored in .class file
16. Stucture of Java Program
Documentation Section
Package Statement
Import Statements
Interface Statement
Class Definition
Main Method Class
Main Method Definition
18. Points to remember
You have to keep in mind that,
Java code is case sensitive
To write a Java program, you must have to define class first
The name of the class in Java (which holds the main method) is the name of the Java program,
and the same name will be given in the filename
19. Program Explanation
public class Hello The public word means that it is accessible from any other classes.
/* Comments */ The compiler ignores comment block.
Braces Two curly brackets {...} are used to group all the commands, so it is known that the commands
belong to that class or method.
public static void main •When the main method is declared public, it means that it can also be used by code outside
of its class, due to which the main method is declared public.
•The word static used when we want to access a method without creating its object, as we
call the main method, before creating any class objects.
•main is a method; this is a starting point of a Java program.
String[] args It is an array where each element of it is a string, which has been named as "args". If your Java
program is run through the console, you can pass the input parameter, and main() method
takes it as input.
System.out.println(); This statement is used to print text on the screen as output. All Java statement ends with a
semicolon.
20. Java Data Types
Tells the compiler what type of variable it as and what type of data it is going to store.
- Data type specifies the size and type of values.
Primary Data Type
Java supports eight primitive data types: byte, short, int, long, float, double, char and boolean.
These eight data types are classified into four groups:
◦ Integer,
◦ Relational Numbers(Floating point)
◦ Characters
◦ Boolean(Conditional).
Non-Primitive Data Types
Classes,Interface, Arrays etc.
21. (Cont.,)
Type Contains Default Size Range
byte Signed integer 0 8 bit or
1 byte
-27 to 27-1 or
-128 to 127
short Signed integer 0 16 bit or
2 bytes
-215 to 215-1 or
-32,768 to 32767
int Signed integer 0 32 bit or
4 bytes
-231 to 231-1 or
-2147,483,648 to
2147,483,647
long Signed integer 0 64 bit or
8 bytes
-263 to 263-1 or
-
9223,372,036,854,755,8
08 to
9223,372,036,854,755,8
07
22. (Cont.,)
Type Contains Default Size Range
float IEEE 754 floating
point
single-precision
0.0f 32 bit or
4 bytes
±1.4E-45 to
±3.40282347E+38
F
double IEEE 754 floating
point
double-precision
0.0 64 bit or
8 bytes
±439E-324 to
±1.797693134862
3157E+308
23. (Contd.,)
Type Contains Default Size Range
char Unicode character
unsigned
u0000 16 bits or
2 bytes
0 to 216-1 or
u0000 to uFFFF
Type Contains Default Size Range
boolean true or false false 1 bit true or false
24. Java Variables
1. Declaration - eg. int width, height=5;
2. Initialization - static and dynamic initialization
3. Rules of Declaring variables
4. Scope of Variables - limit, as far as the variable can be used
5. Local variables - A variable that is declared within the method
6. Instance variables - A non-static variable that is declared within the class
7. Class/Static variables - A variable that is declared with static keyword in a class