SlideShare a Scribd company logo
1 of 29
Introduction
Java
JAVA
• Java is a programming language and a platform.
• Java is a high level, robust, object-oriented and secure programming
language.
• Java was developed by Sun Microsystems in the year 1995.
• James Gosling is known as the father of Java. Before Java, its name
was Oak. Later, James Gosling and his team changed the name from
Oak to Java.
Features of Java
• The primary objective of Java programming language was to make it portable, simple and secure
programming language.
• Simple
• Object-Oriented
• Portable: Java is portable because it facilitates you to carry the Java bytecode to any platform. It
doesn't require any implementation.
• Platform independent: Java code is compiled by the compiler and converted into bytecode. This
bytecode is a platform-independent code because it can be run on multiple platforms.
• Secured: Java is best known for its security. With Java, we can develop virus-free systems.
• Robust: : It uses strong memory management, exception handling and the type checking
mechanism is there in Java
• Interpreted:
• Multithreaded: A thread is like a separate program, executing concurrently. We can write Java
programs that deal with many tasks at once by defining multiple threads.
• Dynamic: Java is a dynamic language. It supports the dynamic loading of classes. It means classes
are loaded on demand.
Applications of Java
• Desktop Applications such as acrobat reader, media player, antivirus,
etc.
• Web Applications such as irctc.co.in, javatpoint.com, etc.
• Enterprise Applications such as banking applications.
• Mobile
• Embedded System
• Smart Card
• Robotics
• Games, etc.
Java Program compilation and Execution
• Java can be considered both a
compiled and an interpreted
language because its source code is
first compiled into a binary byte-code.
• This byte-code runs on the Java
Virtual Machine (JVM), which is
usually a software-based interpreter.
JVM
• JVM (Java Virtual Machine) is an abstract machine. It is called a
virtual machine. It is a specification that provides a runtime
environment in which Java bytecode can be executed.
• The JVM performs the following main tasks:
• Loads code : Classloader is a subsystem of JVM which is used to load
class files. Whenever we run the java program, it is loaded first by
the classloader.
• It Verifies code and Executes code
• Provides runtime environment
JRE
• JRE: 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.
JDK
• The Java Development Kit (JDK) is a software
development environment that offers a
collection of tools and libraries necessary for
developing Java-based software applications.
• JDK contains:
• Java Runtime Environment (JRE),
• An interpreter/loader (Java),
• A compiler (javac),
• An archiver (jar).
Data Types
• Data types specify the different sizes and values that can be stored in
the variable.
• All variables must be declared before its use.
• There are two types of data types in Java:
• Primitive data types: The primitive data types include boolean, char,
byte, short, int, long, float and double.
• Non-primitive data types: The non-primitive data types
include Classes, Interfaces, and Arrays.
Primitive Data Types
• There are 8 types of primitive data types:
• Boolean data type: The Boolean data type is used to store only two possible
values: true and false. This data type is used for simple flags that track
true/false conditions.
Boolean one = false ;
• byte data type: it is an 8-bit signed integer. Its value-range lies between -128
to 127. Its minimum value is -128 and maximum value is 127.
• Its default value is 0.
• byte a = 10;
• char data type: The char data type is a single 16-bit character.
• The char data type is used to store characters.
• Char BCA=‘a’;
Cont..
• short data type: The short data type is a 16-bit signed integer.
• Its value-range lies between -32,768 to 32,767 .
• Its minimum value is -32,768 and maximum value is 32,767.
• Its default value is 0.
• int data type: The int data type is a 32-bit integer. Its value-range lies between (-2^31) to
(2^31 -1) . Its minimum value is - 2,147,483,648 and maximum value is 2,147,483,647.
• Its default value is 0.
• int a = 144;
• long data type: The long data type is a 64-bit integer. Its value-range lies between (-
2^63) to (2^63 -1).
• Its default value is 0.
• long a = 45677L;
Cont..
• float data type: The float data type is a 32-bit floating point.
• Its default value is 0.0F.
• Range 3.4e-038 to 3.4e+038.
• float f1 = 234.5f
• double data type: The double data type is a double-precision 64-bit
floating point.
• The double data type is generally used for decimal values just like float.
• Its default value is 0.0d.
• double d1 = 12.3 ;
• Range 1.7e-308 to 1.7e+308.
Arrays
• Array is an object which contains elements of a similar data type.
• It is a data structure where we store similar elements. We can store
only a fixed set of elements in a Java array.
1. int a[]=new int[5]; //declaration and instantiation
a[0]=10; //initialization
a[1]=20;
2. int a[]={33,3,4,5}; //declaration, instantiation and initialization
Cont..
• The elements of an array are stored in a contiguous memory location.
• Array in Java is index-based.
• The first element of the array is stored at the 0th index, 2nd element
is stored on 1st index and so on.
Types of Array
• There are two types of array.
• Single Dimensional Array : stores data in a single row
• Multidimensional Array: data is stored in row and column based index.
• Syntax to Declare Multidimensional Array :
dataType [][]arrayRefVar;
dataType arrayRefVar[][];
Example: int[][] arr=new int[3][3];
arr[0][0]=1;
arr[0][1]=2;
arr[0][2]=3;
Exceptions in Java(arrays)
• Exceptions in Arrays: ArrayIndexOutOfBoundsException
• The Java Virtual Machine (JVM) throws this exception if we are trying
to access array elements beyond its size.
• ArrayStoreException is a runtime exception in Java that occurs when
we try to store the incorrect type of element into an array.
Cont..
• Advantages
• Code Optimization: It makes the code optimized, we can retrieve or sort the
data efficiently.
• Random access: We can get any data located at an index position.
• Disadvantages
• Size Limit: We can store only the fixed size of elements in the array. It doesn't
grow its size at runtime. To solve this problem, collection framework is used in
Java which grows automatically.
Final Variable
• When the final keyword is used with a variable of different data types
such as int, float, the value of the variable cannot be changed.
final int No_students = 100;
No_students = 130;
Comments In Java
• The Java comments are the statements in a program that are not
executed by the compiler and interpreter.
• Why Comments:
• Comments are used to make the program more readable by adding
the details of the code.
• It makes easy to maintain the code and to find the errors easily.
• The comments can be used to provide information or explanation
about the variable, method, class, or any statement.
• It can also be used in testing the alternative code.
Types of Comments
• Single Line Comment: Single-line comments start with two forward
slashes ( // ).
• //This is single line comment
• Multi Line Comment: The multi-line comment is used to comment
multiple lines of code.
• /* This is
multi line comment */
• Java Documentation Comment: Documentation comments are
usually used to write large programs for a project or software
application as it helps to create documentation API.
• Example: /** and */.
Access Modifiers
• The access modifiers in Java specifies the accessibility or scope of a
field, method, constructor, or class.
• We can change the access level of fields, constructors, methods, and
class by applying the access modifier on it.
• There are four types of Java access modifiers:
1. Public
2. Private
3. Protected
4. Default
Access Modifiers
• Private: The access level of a private modifier is only within the class.
It cannot be accessed from outside the class.
Example: private int data=40;
• Default: The access level of a default modifier is only within the
package. It cannot be accessed from outside the package.
• If you do not specify any access level, it will be the default.
• It is more restrictive than protected, and public.
Cont..
• Protected: The access level of a protected modifier is within the
package and outside the package through inheritance only.
• If there is no child class, it cannot be accessed from outside the
package.
• It provides more accessibility than the default modifier.
• Public: The access level of a public modifier is everywhere. It can be
accessed from within the class, outside the class, within the package
and outside the package.
Example: public class A{ ….}
Access Modifiers
Access Modifier within class within package outside package
by subclass only
outside package
Private Y N N N
Default Y Y N N
Protected Y Y Y N
Public Y Y Y Y
Class in Java
• Class is a template or blueprint from which objects are created.
• It is a logical entity.
• A class in Java can contain:
• Fields
• Methods
• Constructors
• Blocks
• Nested class and interface
Class
1. class <class_name>
{
fields;
methods;
}
2. class Rectangle{
int length;
int width;
void insert(int l,int w){
length=l;
width=w;
} }
Objects in Java
• An object is an instance of a class.
• A class is a template or blueprint from which objects are created. So,
an object is the instance(result) of a class.
• Object Definitions:
• An object is a real-world entity.
• An object is a runtime entity.
• The object is an entity which has state and behavior.
• The object is an instance of a class.
• An object has three characteristics:
• State: represents the data (value) of an object.
• Behavior: represents the behavior (functionality) of an object such as
deposit, withdraw, etc.
• Identity: An object identity is typically implemented via a unique ID.
The value of the ID is not visible to the external user. However, it is
used internally by the JVM to identify each object uniquely.
Create Object
1. Anonymous object:
new Rectangle();
2. Referential name object:
Rectangle r1=new Rectangle();

More Related Content

Similar to intro_java (1).pptx

Skillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Group
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itlokeshpappaka10
 
Java platform
Java platformJava platform
Java platformVisithan
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variablesteach4uin
 
COMPUTER PROGRAMMING LANGUAGE.pptx
COMPUTER PROGRAMMING LANGUAGE.pptxCOMPUTER PROGRAMMING LANGUAGE.pptx
COMPUTER PROGRAMMING LANGUAGE.pptxSofiaArquero2
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed OverviewBuddha Tree
 
Java (1).ppt seminar topics engineering
Java (1).ppt  seminar topics engineeringJava (1).ppt  seminar topics engineering
Java (1).ppt seminar topics engineering4MU21CS023
 
Enumerations in java.pptx
Enumerations in java.pptxEnumerations in java.pptx
Enumerations in java.pptxSrizan Pokrel
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentalsAnsgarMary
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptxVijalJain3
 
cs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxcs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxmshanajoel6
 

Similar to intro_java (1).pptx (20)

Java introduction
Java introductionJava introduction
Java introduction
 
Skillwise Elementary Java Programming
Skillwise Elementary Java ProgrammingSkillwise Elementary Java Programming
Skillwise Elementary Java Programming
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept it
 
Unit 1
Unit 1Unit 1
Unit 1
 
Java platform
Java platformJava platform
Java platform
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
COMPUTER PROGRAMMING LANGUAGE.pptx
COMPUTER PROGRAMMING LANGUAGE.pptxCOMPUTER PROGRAMMING LANGUAGE.pptx
COMPUTER PROGRAMMING LANGUAGE.pptx
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed Overview
 
Core java
Core javaCore java
Core java
 
Core java
Core javaCore java
Core java
 
Java (1).ppt seminar topics engineering
Java (1).ppt  seminar topics engineeringJava (1).ppt  seminar topics engineering
Java (1).ppt seminar topics engineering
 
Java
JavaJava
Java
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
 
Enumerations in java.pptx
Enumerations in java.pptxEnumerations in java.pptx
Enumerations in java.pptx
 
Cse java
Cse javaCse java
Cse java
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
 
Java ce241
Java ce241Java ce241
Java ce241
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
Java basic
Java basicJava basic
Java basic
 
cs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxcs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptx
 

Recently uploaded

VIP Kolkata Call Girl Rajarhat 👉 8250192130 Available With Room
VIP Kolkata Call Girl Rajarhat 👉 8250192130  Available With RoomVIP Kolkata Call Girl Rajarhat 👉 8250192130  Available With Room
VIP Kolkata Call Girl Rajarhat 👉 8250192130 Available With Roomdivyansh0kumar0
 
CALL ON ➥8923113531 🔝Call Girls Charbagh Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Charbagh Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Charbagh Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Charbagh Lucknow best sexual serviceanilsa9823
 
Pooja Mehta 9167673311, Trusted Call Girls In NAVI MUMBAI Cash On Payment , V...
Pooja Mehta 9167673311, Trusted Call Girls In NAVI MUMBAI Cash On Payment , V...Pooja Mehta 9167673311, Trusted Call Girls In NAVI MUMBAI Cash On Payment , V...
Pooja Mehta 9167673311, Trusted Call Girls In NAVI MUMBAI Cash On Payment , V...Pooja Nehwal
 
GENUINE Babe,Call Girls IN Baderpur Delhi | +91-8377087607
GENUINE Babe,Call Girls IN Baderpur  Delhi | +91-8377087607GENUINE Babe,Call Girls IN Baderpur  Delhi | +91-8377087607
GENUINE Babe,Call Girls IN Baderpur Delhi | +91-8377087607dollysharma2066
 
BDSM⚡Call Girls in Sector 99 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 99 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 99 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 99 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
{ 9892124323 }} Call Girls & Escorts in Hotel JW Marriott juhu, Mumbai
{ 9892124323 }} Call Girls & Escorts in Hotel JW Marriott juhu, Mumbai{ 9892124323 }} Call Girls & Escorts in Hotel JW Marriott juhu, Mumbai
{ 9892124323 }} Call Girls & Escorts in Hotel JW Marriott juhu, MumbaiPooja Nehwal
 
Day 0- Bootcamp Roadmap for PLC Bootcamp
Day 0- Bootcamp Roadmap for PLC BootcampDay 0- Bootcamp Roadmap for PLC Bootcamp
Day 0- Bootcamp Roadmap for PLC BootcampPLCLeadershipDevelop
 
Call now : 9892124323 Nalasopara Beautiful Call Girls Vasai virar Best Call G...
Call now : 9892124323 Nalasopara Beautiful Call Girls Vasai virar Best Call G...Call now : 9892124323 Nalasopara Beautiful Call Girls Vasai virar Best Call G...
Call now : 9892124323 Nalasopara Beautiful Call Girls Vasai virar Best Call G...Pooja Nehwal
 
internal analysis on strategic management
internal analysis on strategic managementinternal analysis on strategic management
internal analysis on strategic managementharfimakarim
 
Call Now Pooja Mehta : 7738631006 Door Step Call Girls Rate 100% Satisfactio...
Call Now Pooja Mehta :  7738631006 Door Step Call Girls Rate 100% Satisfactio...Call Now Pooja Mehta :  7738631006 Door Step Call Girls Rate 100% Satisfactio...
Call Now Pooja Mehta : 7738631006 Door Step Call Girls Rate 100% Satisfactio...Pooja Nehwal
 
Dealing with Poor Performance - get the full picture from 3C Performance Mana...
Dealing with Poor Performance - get the full picture from 3C Performance Mana...Dealing with Poor Performance - get the full picture from 3C Performance Mana...
Dealing with Poor Performance - get the full picture from 3C Performance Mana...Hedda Bird
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Kondapur high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls Kondapur high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls Kondapur high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls Kondapur high-profile Call Girladitipandeya
 
CEO of Google, Sunder Pichai's biography
CEO of Google, Sunder Pichai's biographyCEO of Google, Sunder Pichai's biography
CEO of Google, Sunder Pichai's biographyHafizMuhammadAbdulla5
 

Recently uploaded (20)

VIP Kolkata Call Girl Rajarhat 👉 8250192130 Available With Room
VIP Kolkata Call Girl Rajarhat 👉 8250192130  Available With RoomVIP Kolkata Call Girl Rajarhat 👉 8250192130  Available With Room
VIP Kolkata Call Girl Rajarhat 👉 8250192130 Available With Room
 
CALL ON ➥8923113531 🔝Call Girls Charbagh Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Charbagh Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Charbagh Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Charbagh Lucknow best sexual service
 
Empowering Local Government Frontline Services - Mo Baines.pdf
Empowering Local Government Frontline Services - Mo Baines.pdfEmpowering Local Government Frontline Services - Mo Baines.pdf
Empowering Local Government Frontline Services - Mo Baines.pdf
 
Pooja Mehta 9167673311, Trusted Call Girls In NAVI MUMBAI Cash On Payment , V...
Pooja Mehta 9167673311, Trusted Call Girls In NAVI MUMBAI Cash On Payment , V...Pooja Mehta 9167673311, Trusted Call Girls In NAVI MUMBAI Cash On Payment , V...
Pooja Mehta 9167673311, Trusted Call Girls In NAVI MUMBAI Cash On Payment , V...
 
Call Girls Service Tilak Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SERVICE
Call Girls Service Tilak Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SERVICECall Girls Service Tilak Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SERVICE
Call Girls Service Tilak Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SERVICE
 
GENUINE Babe,Call Girls IN Baderpur Delhi | +91-8377087607
GENUINE Babe,Call Girls IN Baderpur  Delhi | +91-8377087607GENUINE Babe,Call Girls IN Baderpur  Delhi | +91-8377087607
GENUINE Babe,Call Girls IN Baderpur Delhi | +91-8377087607
 
BDSM⚡Call Girls in Sector 99 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 99 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 99 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 99 Noida Escorts >༒8448380779 Escort Service
 
Leadership in Crisis - Helio Vogas, Risk & Leadership Keynote Speaker
Leadership in Crisis - Helio Vogas, Risk & Leadership Keynote SpeakerLeadership in Crisis - Helio Vogas, Risk & Leadership Keynote Speaker
Leadership in Crisis - Helio Vogas, Risk & Leadership Keynote Speaker
 
Imagine - Creating Healthy Workplaces - Anthony Montgomery.pdf
Imagine - Creating Healthy Workplaces - Anthony Montgomery.pdfImagine - Creating Healthy Workplaces - Anthony Montgomery.pdf
Imagine - Creating Healthy Workplaces - Anthony Montgomery.pdf
 
Rohini Sector 16 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 16 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 16 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 16 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
{ 9892124323 }} Call Girls & Escorts in Hotel JW Marriott juhu, Mumbai
{ 9892124323 }} Call Girls & Escorts in Hotel JW Marriott juhu, Mumbai{ 9892124323 }} Call Girls & Escorts in Hotel JW Marriott juhu, Mumbai
{ 9892124323 }} Call Girls & Escorts in Hotel JW Marriott juhu, Mumbai
 
Unlocking the Future - Dr Max Blumberg, Founder of Blumberg Partnership
Unlocking the Future - Dr Max Blumberg, Founder of Blumberg PartnershipUnlocking the Future - Dr Max Blumberg, Founder of Blumberg Partnership
Unlocking the Future - Dr Max Blumberg, Founder of Blumberg Partnership
 
Day 0- Bootcamp Roadmap for PLC Bootcamp
Day 0- Bootcamp Roadmap for PLC BootcampDay 0- Bootcamp Roadmap for PLC Bootcamp
Day 0- Bootcamp Roadmap for PLC Bootcamp
 
Disrupt or be Disrupted - Kirk Vallis.pdf
Disrupt or be Disrupted - Kirk Vallis.pdfDisrupt or be Disrupted - Kirk Vallis.pdf
Disrupt or be Disrupted - Kirk Vallis.pdf
 
Call now : 9892124323 Nalasopara Beautiful Call Girls Vasai virar Best Call G...
Call now : 9892124323 Nalasopara Beautiful Call Girls Vasai virar Best Call G...Call now : 9892124323 Nalasopara Beautiful Call Girls Vasai virar Best Call G...
Call now : 9892124323 Nalasopara Beautiful Call Girls Vasai virar Best Call G...
 
internal analysis on strategic management
internal analysis on strategic managementinternal analysis on strategic management
internal analysis on strategic management
 
Call Now Pooja Mehta : 7738631006 Door Step Call Girls Rate 100% Satisfactio...
Call Now Pooja Mehta :  7738631006 Door Step Call Girls Rate 100% Satisfactio...Call Now Pooja Mehta :  7738631006 Door Step Call Girls Rate 100% Satisfactio...
Call Now Pooja Mehta : 7738631006 Door Step Call Girls Rate 100% Satisfactio...
 
Dealing with Poor Performance - get the full picture from 3C Performance Mana...
Dealing with Poor Performance - get the full picture from 3C Performance Mana...Dealing with Poor Performance - get the full picture from 3C Performance Mana...
Dealing with Poor Performance - get the full picture from 3C Performance Mana...
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Kondapur high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls Kondapur high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls Kondapur high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls Kondapur high-profile Call Girl
 
CEO of Google, Sunder Pichai's biography
CEO of Google, Sunder Pichai's biographyCEO of Google, Sunder Pichai's biography
CEO of Google, Sunder Pichai's biography
 

intro_java (1).pptx

  • 2. JAVA • Java is a programming language and a platform. • Java is a high level, robust, object-oriented and secure programming language. • Java was developed by Sun Microsystems in the year 1995. • James Gosling is known as the father of Java. Before Java, its name was Oak. Later, James Gosling and his team changed the name from Oak to Java.
  • 3. Features of Java • The primary objective of Java programming language was to make it portable, simple and secure programming language. • Simple • Object-Oriented • Portable: Java is portable because it facilitates you to carry the Java bytecode to any platform. It doesn't require any implementation. • Platform independent: Java code is compiled by the compiler and converted into bytecode. This bytecode is a platform-independent code because it can be run on multiple platforms. • Secured: Java is best known for its security. With Java, we can develop virus-free systems. • Robust: : It uses strong memory management, exception handling and the type checking mechanism is there in Java • Interpreted: • Multithreaded: A thread is like a separate program, executing concurrently. We can write Java programs that deal with many tasks at once by defining multiple threads. • Dynamic: Java is a dynamic language. It supports the dynamic loading of classes. It means classes are loaded on demand.
  • 4. Applications of Java • Desktop Applications such as acrobat reader, media player, antivirus, etc. • Web Applications such as irctc.co.in, javatpoint.com, etc. • Enterprise Applications such as banking applications. • Mobile • Embedded System • Smart Card • Robotics • Games, etc.
  • 5. Java Program compilation and Execution • Java can be considered both a compiled and an interpreted language because its source code is first compiled into a binary byte-code. • This byte-code runs on the Java Virtual Machine (JVM), which is usually a software-based interpreter.
  • 6. JVM • JVM (Java Virtual Machine) is an abstract machine. It is called a virtual machine. It is a specification that provides a runtime environment in which Java bytecode can be executed. • The JVM performs the following main tasks: • Loads code : Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java program, it is loaded first by the classloader. • It Verifies code and Executes code • Provides runtime environment
  • 7. JRE • JRE: 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.
  • 8. JDK • The Java Development Kit (JDK) is a software development environment that offers a collection of tools and libraries necessary for developing Java-based software applications. • JDK contains: • Java Runtime Environment (JRE), • An interpreter/loader (Java), • A compiler (javac), • An archiver (jar).
  • 9. Data Types • Data types specify the different sizes and values that can be stored in the variable. • All variables must be declared before its use. • There are two types of data types in Java: • Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float and double. • Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays.
  • 10. Primitive Data Types • There are 8 types of primitive data types: • Boolean data type: The Boolean data type is used to store only two possible values: true and false. This data type is used for simple flags that track true/false conditions. Boolean one = false ; • byte data type: it is an 8-bit signed integer. Its value-range lies between -128 to 127. Its minimum value is -128 and maximum value is 127. • Its default value is 0. • byte a = 10; • char data type: The char data type is a single 16-bit character. • The char data type is used to store characters. • Char BCA=‘a’;
  • 11. Cont.. • short data type: The short data type is a 16-bit signed integer. • Its value-range lies between -32,768 to 32,767 . • Its minimum value is -32,768 and maximum value is 32,767. • Its default value is 0. • int data type: The int data type is a 32-bit integer. Its value-range lies between (-2^31) to (2^31 -1) . Its minimum value is - 2,147,483,648 and maximum value is 2,147,483,647. • Its default value is 0. • int a = 144; • long data type: The long data type is a 64-bit integer. Its value-range lies between (- 2^63) to (2^63 -1). • Its default value is 0. • long a = 45677L;
  • 12. Cont.. • float data type: The float data type is a 32-bit floating point. • Its default value is 0.0F. • Range 3.4e-038 to 3.4e+038. • float f1 = 234.5f • double data type: The double data type is a double-precision 64-bit floating point. • The double data type is generally used for decimal values just like float. • Its default value is 0.0d. • double d1 = 12.3 ; • Range 1.7e-308 to 1.7e+308.
  • 13. Arrays • Array is an object which contains elements of a similar data type. • It is a data structure where we store similar elements. We can store only a fixed set of elements in a Java array. 1. int a[]=new int[5]; //declaration and instantiation a[0]=10; //initialization a[1]=20; 2. int a[]={33,3,4,5}; //declaration, instantiation and initialization
  • 14. Cont.. • The elements of an array are stored in a contiguous memory location. • Array in Java is index-based. • The first element of the array is stored at the 0th index, 2nd element is stored on 1st index and so on.
  • 15. Types of Array • There are two types of array. • Single Dimensional Array : stores data in a single row • Multidimensional Array: data is stored in row and column based index. • Syntax to Declare Multidimensional Array : dataType [][]arrayRefVar; dataType arrayRefVar[][]; Example: int[][] arr=new int[3][3]; arr[0][0]=1; arr[0][1]=2; arr[0][2]=3;
  • 16. Exceptions in Java(arrays) • Exceptions in Arrays: ArrayIndexOutOfBoundsException • The Java Virtual Machine (JVM) throws this exception if we are trying to access array elements beyond its size. • ArrayStoreException is a runtime exception in Java that occurs when we try to store the incorrect type of element into an array.
  • 17. Cont.. • Advantages • Code Optimization: It makes the code optimized, we can retrieve or sort the data efficiently. • Random access: We can get any data located at an index position. • Disadvantages • Size Limit: We can store only the fixed size of elements in the array. It doesn't grow its size at runtime. To solve this problem, collection framework is used in Java which grows automatically.
  • 18. Final Variable • When the final keyword is used with a variable of different data types such as int, float, the value of the variable cannot be changed. final int No_students = 100; No_students = 130;
  • 19. Comments In Java • The Java comments are the statements in a program that are not executed by the compiler and interpreter. • Why Comments: • Comments are used to make the program more readable by adding the details of the code. • It makes easy to maintain the code and to find the errors easily. • The comments can be used to provide information or explanation about the variable, method, class, or any statement. • It can also be used in testing the alternative code.
  • 20. Types of Comments • Single Line Comment: Single-line comments start with two forward slashes ( // ). • //This is single line comment • Multi Line Comment: The multi-line comment is used to comment multiple lines of code. • /* This is multi line comment */ • Java Documentation Comment: Documentation comments are usually used to write large programs for a project or software application as it helps to create documentation API. • Example: /** and */.
  • 21. Access Modifiers • The access modifiers in Java specifies the accessibility or scope of a field, method, constructor, or class. • We can change the access level of fields, constructors, methods, and class by applying the access modifier on it. • There are four types of Java access modifiers: 1. Public 2. Private 3. Protected 4. Default
  • 22. Access Modifiers • Private: The access level of a private modifier is only within the class. It cannot be accessed from outside the class. Example: private int data=40; • Default: The access level of a default modifier is only within the package. It cannot be accessed from outside the package. • If you do not specify any access level, it will be the default. • It is more restrictive than protected, and public.
  • 23. Cont.. • Protected: The access level of a protected modifier is within the package and outside the package through inheritance only. • If there is no child class, it cannot be accessed from outside the package. • It provides more accessibility than the default modifier. • Public: The access level of a public modifier is everywhere. It can be accessed from within the class, outside the class, within the package and outside the package. Example: public class A{ ….}
  • 24. Access Modifiers Access Modifier within class within package outside package by subclass only outside package Private Y N N N Default Y Y N N Protected Y Y Y N Public Y Y Y Y
  • 25. Class in Java • Class is a template or blueprint from which objects are created. • It is a logical entity. • A class in Java can contain: • Fields • Methods • Constructors • Blocks • Nested class and interface
  • 26. Class 1. class <class_name> { fields; methods; } 2. class Rectangle{ int length; int width; void insert(int l,int w){ length=l; width=w; } }
  • 27. Objects in Java • An object is an instance of a class. • A class is a template or blueprint from which objects are created. So, an object is the instance(result) of a class. • Object Definitions: • An object is a real-world entity. • An object is a runtime entity. • The object is an entity which has state and behavior. • The object is an instance of a class.
  • 28. • An object has three characteristics: • State: represents the data (value) of an object. • Behavior: represents the behavior (functionality) of an object such as deposit, withdraw, etc. • Identity: An object identity is typically implemented via a unique ID. The value of the ID is not visible to the external user. However, it is used internally by the JVM to identify each object uniquely.
  • 29. Create Object 1. Anonymous object: new Rectangle(); 2. Referential name object: Rectangle r1=new Rectangle();