SlideShare a Scribd company logo
Course code: CSE208 - JAVA PROGRAMMING
1
What is java?
• Java is a general purpose, Object oriented programming Language
• Java is platform independent: the same program can run on any
correctly implemented Java system
• Java is object-oriented:
• Structured in terms of classes, which group data with
operations on that data
• Can construct new classes by extending existing ones
• Java designed as
• A core language plus
• A rich collection of commonly available packages
• Java can be embedded in Web pages
2
Reasons for using java
• Built-in support for multi-threading, socket communication, and
memory management (automatic garbage collection).
• Object Oriented (OO).
• Better portability than other languages across operating systems.
• Supports Web based applications (Applet, Servlet, and JSP),
distributed applications (sockets, RMI, EJB etc) and network
protocols (HTTP, JRMP etc) with the help of extensive standardized
APIs (Application Programming Interfaces).
3
Java and its Evolution
4
 Programming languages such as Cobol, Fortran do not have
structural principles. They use the Goto statement to control the
flow of the program.
 Therefore, ’C’ was invented in 1970, to replace the assembly
language and to create a structured, effective and high-level
language
 C++ came with object-oriented programming features. C++ is the
extension of C language which has been used extensively. It is a
powerful modern language that includes the power and simplicity
of C and the characteristics of OOP.
Java History
• Java is a general purpose, Object oriented programming Language developed by
Sun Microsystems of USA in 1991. Originally called Oak by James Gosling.
• 1990 – Sun Microsystems decided to develop special software for consumer
electronic devices headed by James Gosling.
• 1991 – Using C++ the team announced a new language named Oak.
• 1992 – The Green project team by Sun, shown new language to control home
appliances using hand held device with tiny touch-sensitive screen.
• 1993 - The www appeared on the internet and transformed the text based
internet into graphical rich environment using Web Applets.
• 1994 – Team developed a web browser called “HotJava” for web Applets.
• 1995 – “Oak” was renamed “Java” due to some legal snags. Java is just a name.
Netscape and Microsoft supports to Java.
• 1996 – Java established itself as a leader for internet & general purpose
programming. Java founds its home.
5
JAVA SE VERSION RELEASE DATE
JDK 1.0 Jan-96
JDK 1.1 Feb-97
J2SE 1.2 Dec-98
J2SE 1.3 May-2000
J2SE 1.4 Feb-2002
J2SE 5.0 Sep-2004
Java SE 6 Dec-2006
Java SE 7 Jul-2011
Java SE 8 Mar-2014
Java SE 9 September, 21st 2017
Java SE 10 March, 20th 2018
Java SE 11 September, 25th 2018
Java SE 12 March, 19th 2019
Java SE 13 September, 17th 2019
Java SE 14 March, 17th 2020
Java SE 15 September, 15th 2020
Java SE 16 March, 16th 2021
Java SE 17 September, 14th 2021
Java SE 18 March, 22nd 2022
Java SE 19 September, 20th 2022
Java SE 20 March, 21st 2023 6
Java Versions
7
Procedural Oriented Programming Object-Oriented Programming
In procedural programming, the program is divided into
small parts called functions.
In object-oriented programming, the program is divided
into small parts called objects.
Procedural programming follows a top-down approach.
Object-oriented programming follows a bottom-up
approach.
There is no access specifier in procedural programming.
Object-oriented programming has access specifiers like
private, public, protected, etc.
Procedural programming does not have any proper way
of hiding data so it is less secure.
Object-oriented programming provides data hiding so it
is more secure.
In procedural programming, overloading is not possible.
Overloading is possible in object-oriented
programming.
In procedural programming, there is no concept of data
hiding and inheritance.
In object-oriented programming, the concept of data
hiding and inheritance is used.
In procedural programming, the function is more
important than the data.
In object-oriented programming, data is more important
than function.
Procedural programming uses the concept of procedure
abstraction.
Object-oriented programming uses the concept of data
abstraction.
Code reusability absent in procedural programming,
Code reusability present in object-oriented
Differences between
C++ and Java
8
Sl. no COMPARISON PARAMETER C++ JAVA
1 Developed / Founded by
C++ was developed by Bjarne Stroustrup at
Bell Labs in 1979. It was developed as an
extension of the C language.
Java was developed by James
Gosling at Sun Microsystems.
Now, it is owned by Oracle.
2 Programming model
It has support for both procedural
programming and object-oriented
programming.
Java has support only for
object-oriented programming
models.
3 Platform dependence
C++ is platform dependent. It is based on the
concept of Write Once Compile Anywhere.
Java is platform-independent.
It is based on the concept of
Write Once Run Anywhere.
4 Features supported
C++ supports features like operator
overloading, Goto statements, structures,
pointers, unions, etc.
Java does not support features
like operator overloading,
Goto statements, structures,
pointers, unions, etc.
5 Compilation and Interpretation
C ++ is only compiled and cannot be
interpreted.
Java can be both compiled and
interpreted.
6
Library and Code reusability
support
C++ has very limited libraries with low-level
functionalities. C++ allows direct calls to
native system libraries.
Java, on the other hand, has
more diverse libraries with a
lot of support for code
reusability. In Java, only calls
through the Java Native
Interface and recently Java
Native Access are allowed.
7 Memory Management In C++, memory management is manual.
In Java, memory management
is System controlled.
9 Global Scope
In C++, both global and namespace scopes
are supported.
Java has no support for global
scope.
Java Environment
• Java Environment includes large number of development tools.
• The development tools are part of the system known as Java Development Kit
( 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.
9
Java Runtime Environment ( JRE )
• The Java Runtime Environment ( JRE ) facilitates the execution of
programs developed in java. It comprises the following:
• Java Virtual Machine ( JVM ) :
• Java Virtual Machine (JVM) is an engine that provides a runtime
environment to drive the Java Code or applications. It converts
Java bytecode into machine language. This machine is called Java
Virtual Machine and it exists only inside the computer memory.
• Compiling source code into bytecode ( machine readable code )
using javac compiler.
• Executing the bytecode ( machine-readable code ) to human-
understandable code using a Java interpreter
10
Java’s Magic: The Byte Code
 Allows Java to solve both the security and the portability problems is that
the output of a Java compiler is not executable code but it is the Bytecode.
 Bytecode is a highly optimized set of instructions designed to be executed
by the Java run-time system, which is called the Java Virtual
Machine (JVM).
 JVM is an interpreter for bytecode. The fact that a Java program is executed
by JVM helps solve the major problems associated with downloading
programs over the Internet.
 Translating a Java program into bytecode helps makes it much easier to
run a program in a wide variety of environments. This is because only the
JVM needs to be implemented for each platform.
Java is Compiled and Interpreted
Text Editor Compiler Interpreter
Programmer
Source Code
.java file
Byte Code
.class file
Hardware and
Operating System
Notepad, emacs, javac java
appletviewer
Java is both compiled and an interpreted lang. First the java compiler translates source code into
the byte code instructions. In the next stage the java interpreter converts the byte code
instructions to Machine Code.
Java features/Java Buzzwords
• Simple
• Object-Oriented
• Portable
• Platform independent
• Secured
• Robust
• Architecture neutral
• Interpreted
• High Performance
• Multithreaded
• Distributed
• Dynamic
13
Simple
• Java is very easy to learn, and its syntax is simple, clean and easy
to understand.
• Java syntax is based on C++ (so easier for programmers to learn it
after C++).
• Java has removed many complicated and rarely-used features, for
example, explicit pointers, operator overloading, etc.
• There is no need to remove unreferenced objects because there is
an Automatic Garbage Collection in Java.
14
Secure
• Secure As compared to C/C++, Java is considered to be much more
secure language, as it does not allow a programmer to create
pointers. Thus in Java we cannot access any address directly and
this makes Java much more reliable and secure as compared to
C/C++.
• In Java, we can split a program into multiple parts and store these
parts on different computers.
15
Object-Oriented
• Java is an object-oriented programming language. Everything in Java is
an object.
• Object-oriented means we organize our software as a combination of
different types of objects that incorporate both data and behavior.
• Basic concepts of OOPs are:
Object
Class
Inheritance
Polymorphism
Abstraction
Encapsulation
16
Platform Independent/Architecture
Neutral
• Java is platform independent because it is different from other languages
like C, C++, etc.
• Being java independent means, Programme compiled n one machine that can be
executed in another machine without any change.
• The Java compiler never converts the source code to machine code like C/C++
compiler. Rather it converts the source code into an intermediate code called as
the byte code and this byte code is
further translated to machine dependent form by another
layer of software called as JVM(Java Virtual Machine).
17
Robust
• It uses strong memory management.
• Java provides automatic garbage collection which runs on the Java
Virtual Machine to get rid of objects which are not being used by a
Java application anymore.
• There are exception handling and the type checking mechanism in
Java. All these points make Java robust.
• Java is portable because it facilitates you to carry the Java
bytecode to any platform. It doesn't require any implementation.
18
Portable
Interpreted and High Performance
• Java enables the creation of cross-platform programs by compiling
into an intermediate representation called Java bytecode.
• This code can be executed on any system that implements the Java
Virtual Machine.
• Most previous attempts at cross-platform solutions have done so at
the expense of performance
19
Multithreaded
• Java supports multithreaded programming, which allows you to
write programs that do many things simultaneously.
Example:
• Railway ticket reservation system where multiple customers
accessing the server. Multiple account holders accessing their
accounts simultaneously on the server. When you insert a ATM
card.
20
Distributed
• Java is distributed because it facilitates users to create distributed
applications in Java.
• RMI is used for creating distributed applications.
• This feature of Java makes us able to access files by calling the
methods from any machine on the internet.
• Java supports dynamic compilation and automatic memory
management (garbage collection).
21
Dynamic
Simple program
class Simple
{
public static void main(String args[])
{
System.out.println("Java World");
}
}
22
Simple program
class Simple
{
public static void main(String args[])
{
System.out.println("Java World");
}
}
23
• Write a java program to convert centigrade into Fahrenheit.
• Write a java program to display student details of the following
name, Register no, date of birth age and Nationality.
• Write a java program to compute simple interest.
• Write a java program Fahrenheit to Celsius
• Write a java program Find Odd or Even:
• Write a java program to compute Fibonacci Series:
24
Questions
1. Java object oriented programming concepts is/are
Select one:
a. Inheritance
b. polymorphism
c. All of the above.
d. Encapsulation
2. Polymorphism types in Java is/are
Select one:
a. None
b. Compile time
c. Run time
d. Both
3. JVM is an interpreter for
Select one:
a. Java
b. javac
c. Bytecode
d. JRE
25
4.Java was known as
a. jdk
b. Apple
c. oak
d. Java only
5.Java does not support ? Select one:
a. compile time polymorphism
b. Multiple inheritance for classes
c. multiple inheritance of interfaces
d. Inheritance
6. Which component is used to compile, debug and execute java program? Select one:
a. JIT
b. JDK
c. JRE
d. JVM
7. What is use of interpreter? Select one:
a. They are intermediated between JIT and JVM
b. They read high level code and execute them
c. It is a synonym for JIT
d. They convert bytecode to machine language code
26
OOPs Concepts
• Object-Oriented Programming is a methodology to design a
program using classes and objects. It simplifies software
development and maintenance by providing some concepts.
• Object
• Class
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
27
Class
Class is a collection data members and Methods
A class can also be defined as a blueprint from which you can create an individual object.
Example:
class classname {
type instance variable 1;
type instance variable 2;
.
.
type instance variable n;
type methodname 1 (parameter list) {
// body of method
}
type methodname 2 (parameter list) {
// body of method
}
type methodnamen (parameter list) {
// body of method
}
}
28
objects
• Any entity that has state and behavior is known as an object
• Single Instance of class.
• Objects are always called instances of a class which are created from a
class in java.
Example
Public class Mybook {
int x=10;
Public static void main (String args []) {
Mybook Myobj= new Mybook ();
System.out.println(MyObj.x);
}
}
29
ABSTRACTION
• Abstraction is the process of taking only a set of essential
characteristics from something.
• Hiding internal details and showing functionality is known as
abstraction.
• We can say that the main purpose of abstraction is data hiding
Abstract class animal {
//abstract method
public abstract void sound ( ) ;
}
30
INHERITANCE
• Inheritance is the process in which derived class acquire all the
properties from the base class.
• It inherits the properties from the base class by using extends keyword
• It provides code reusability.
• It is used to achieve runtime polymorphism.
• Types
1.Single level
2.Multilevel
3.Hierarchical level
4.Hybrid inheritance
31
Singe Inheritance
• In this one class i.e., the derived class inherits properties from its
parental class.
• Class A is the base or parental class and class b is the derived
class.
Class a {
…
}
Class b extends class a {
…
}
32
Multilevel Inheritance
• This one class is derived from another class which is also derived from
another class i.e., this class has more than one parental class, hence it is
called multilevel inheritance
Class a {
….
}
Class b extends class a {
….
}
Class c extends class b {
…
}
33
Hierarchical level
• In this one parental class has two or more derived classes or we can say
that two or more child classes have one parental class.
Class a {
….
}
Class b extends class a {
….
}
Class c extends class a {
…
}
34
Hybrid Inheritance
• This is the combination of multiple and multilevel inheritances and
in java, multiple inheritances are not supported as it leads to
ambiguity and this type of inheritance can only be achieved
through interfaces.
35
POLYMORPHISM
• Polymorphism refers to many forms, or it is a process that
performs a single action in different ways.
TYPES
1.COMPILE TIME  Method Overloading
2. RUN TIME  Method Overriding
• One of the examples of Compile time polymorphism is that when
we overload a static method in java.
• Run time polymorphism also called a dynamic method dispatch is
a method in which a call to an overridden method is resolved at
run time rather than compile time
36
Method Overloading
A Class contain two or more methods may have the
same name but different parameter List is called Method
Overloading
void func()
{
Statement(s)
}
void func(int a)
{
Statement(s)
}
float func(double a)
{
Statement(s)
}
float func(int a, float b)
{
Statement(s)
}
37
DATA TYPES
• Data Types in Java
• Data types specify the different sizes and values that can
be stored in the variable. 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.
38
39
Data Type Size Description
byte 1 byte Stores whole numbers from -128 to 127
short 2 bytes Stores whole numbers from -32,768 to 32,767
int 4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647
long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal
digits
double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal digits
boolean 1 bit Stores true or false values
char 2 bytes Stores a single character/letter or ASCII values
40
41
Example
• int myNum = 5; // Integer (whole number)
• float myFloatNum = 5.99f; // Floating point number
• char myLetter = 'D'; // Character
• boolean myBool = true;
• String name=“Raja”;
42

More Related Content

Similar to Java ppt-class_basic data types methods definitions (20)

PPTX
Java Basics
Khan625
 
PPTX
Java in Mule
Shahid Shaik
 
PPTX
UNIT 1 Programming in java Bsc program.pptx
jijinamt
 
PPTX
Introduction to java
Phaniu
 
PPTX
Introduction to java
javeed_mhd
 
PPTX
Java Introduction
javeed_mhd
 
PPT
Java2020 programming basics and fundamentals
swecsaleem
 
PDF
OOPS JAVA.pdf
DeepanshuMidha5140
 
PDF
Introduction to Java Programming
Ravi Kant Sahu
 
PPTX
Introduction to java
sanjay joshi
 
PPT
Java-Unit-I.ppt
RameswarGprec
 
PPTX
introduction to object orinted programming through java
Parameshwar Maddela
 
PPTX
Unit1- OOPJ Chapter-1 Object Oriented Programming JAVA.pptx
Divya573916
 
PPTX
java tutorial for beginner - Free Download
TIB Academy
 
PPTX
Java Introduction
sunmitraeducation
 
PPT
00 intro to java
Deia Abdullah
 
PPTX
JAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptx
netaji10700
 
PPTX
Java
seenak
 
Java Basics
Khan625
 
Java in Mule
Shahid Shaik
 
UNIT 1 Programming in java Bsc program.pptx
jijinamt
 
Introduction to java
Phaniu
 
Introduction to java
javeed_mhd
 
Java Introduction
javeed_mhd
 
Java2020 programming basics and fundamentals
swecsaleem
 
OOPS JAVA.pdf
DeepanshuMidha5140
 
Introduction to Java Programming
Ravi Kant Sahu
 
Introduction to java
sanjay joshi
 
Java-Unit-I.ppt
RameswarGprec
 
introduction to object orinted programming through java
Parameshwar Maddela
 
Unit1- OOPJ Chapter-1 Object Oriented Programming JAVA.pptx
Divya573916
 
java tutorial for beginner - Free Download
TIB Academy
 
Java Introduction
sunmitraeducation
 
00 intro to java
Deia Abdullah
 
JAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptx
netaji10700
 
Java
seenak
 

More from ganeshkarthy (15)

PPT
Basic coding skills_python and its applications
ganeshkarthy
 
PPTX
Lecture-5-Linear Regression-Tutorials.PPTX
ganeshkarthy
 
PPTX
Lecture-5-Linear Regression-Tutorials.PPTX
ganeshkarthy
 
PPTX
Lecture-6-Linear Regression-Gradient Descent-Tutorials.PPTX
ganeshkarthy
 
PPTX
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
ganeshkarthy
 
PPT
C_Language_PS&PC_Notes.ppt
ganeshkarthy
 
PDF
CLOUD_COMPUTING_UNIT_2.pdf
ganeshkarthy
 
PDF
CLOUD_COMPUTING_UNIT_1.pdf
ganeshkarthy
 
PPTX
S16_Notes_CC.pptx
ganeshkarthy
 
PPTX
Asynchronous Frameworks.pptx
ganeshkarthy
 
PPT
Green computing PPT Notes.ppt
ganeshkarthy
 
PPT
OOPS(CS8392)_Unit-I_Notes.ppt
ganeshkarthy
 
PPT
Unit-II(STATIC UML DIAGRAMS).ppt
ganeshkarthy
 
DOCX
UNIT-I(Unified_Process_and_Use Case_Diagrams)_OOAD.docx
ganeshkarthy
 
PDF
Unit-1_Notes(OOAD).pdf
ganeshkarthy
 
Basic coding skills_python and its applications
ganeshkarthy
 
Lecture-5-Linear Regression-Tutorials.PPTX
ganeshkarthy
 
Lecture-5-Linear Regression-Tutorials.PPTX
ganeshkarthy
 
Lecture-6-Linear Regression-Gradient Descent-Tutorials.PPTX
ganeshkarthy
 
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
ganeshkarthy
 
C_Language_PS&PC_Notes.ppt
ganeshkarthy
 
CLOUD_COMPUTING_UNIT_2.pdf
ganeshkarthy
 
CLOUD_COMPUTING_UNIT_1.pdf
ganeshkarthy
 
S16_Notes_CC.pptx
ganeshkarthy
 
Asynchronous Frameworks.pptx
ganeshkarthy
 
Green computing PPT Notes.ppt
ganeshkarthy
 
OOPS(CS8392)_Unit-I_Notes.ppt
ganeshkarthy
 
Unit-II(STATIC UML DIAGRAMS).ppt
ganeshkarthy
 
UNIT-I(Unified_Process_and_Use Case_Diagrams)_OOAD.docx
ganeshkarthy
 
Unit-1_Notes(OOAD).pdf
ganeshkarthy
 
Ad

Recently uploaded (20)

PPTX
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
PDF
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
PDF
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
PPTX
Photo chemistry Power Point Presentation
mprpgcwa2024
 
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
PPT
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
PPTX
How to Add New Item in CogMenu in Odoo 18
Celine George
 
PPTX
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
PPTX
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
PDF
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
PDF
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
PPTX
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
PPTX
Elo the HeroTHIS IS A STORY ABOUT A BOY WHO SAVED A LITTLE GOAT .pptx
JoyIPanos
 
DOCX
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
PDF
VCE Literature Section A Exam Response Guide
jpinnuck
 
PDF
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
PPTX
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
PDF
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
PDF
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
PPTX
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
Photo chemistry Power Point Presentation
mprpgcwa2024
 
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
How to Add New Item in CogMenu in Odoo 18
Celine George
 
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
Elo the HeroTHIS IS A STORY ABOUT A BOY WHO SAVED A LITTLE GOAT .pptx
JoyIPanos
 
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
VCE Literature Section A Exam Response Guide
jpinnuck
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
 
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
 
Ad

Java ppt-class_basic data types methods definitions

  • 1. Course code: CSE208 - JAVA PROGRAMMING 1
  • 2. What is java? • Java is a general purpose, Object oriented programming Language • Java is platform independent: the same program can run on any correctly implemented Java system • Java is object-oriented: • Structured in terms of classes, which group data with operations on that data • Can construct new classes by extending existing ones • Java designed as • A core language plus • A rich collection of commonly available packages • Java can be embedded in Web pages 2
  • 3. Reasons for using java • Built-in support for multi-threading, socket communication, and memory management (automatic garbage collection). • Object Oriented (OO). • Better portability than other languages across operating systems. • Supports Web based applications (Applet, Servlet, and JSP), distributed applications (sockets, RMI, EJB etc) and network protocols (HTTP, JRMP etc) with the help of extensive standardized APIs (Application Programming Interfaces). 3
  • 4. Java and its Evolution 4  Programming languages such as Cobol, Fortran do not have structural principles. They use the Goto statement to control the flow of the program.  Therefore, ’C’ was invented in 1970, to replace the assembly language and to create a structured, effective and high-level language  C++ came with object-oriented programming features. C++ is the extension of C language which has been used extensively. It is a powerful modern language that includes the power and simplicity of C and the characteristics of OOP.
  • 5. Java History • Java is a general purpose, Object oriented programming Language developed by Sun Microsystems of USA in 1991. Originally called Oak by James Gosling. • 1990 – Sun Microsystems decided to develop special software for consumer electronic devices headed by James Gosling. • 1991 – Using C++ the team announced a new language named Oak. • 1992 – The Green project team by Sun, shown new language to control home appliances using hand held device with tiny touch-sensitive screen. • 1993 - The www appeared on the internet and transformed the text based internet into graphical rich environment using Web Applets. • 1994 – Team developed a web browser called “HotJava” for web Applets. • 1995 – “Oak” was renamed “Java” due to some legal snags. Java is just a name. Netscape and Microsoft supports to Java. • 1996 – Java established itself as a leader for internet & general purpose programming. Java founds its home. 5
  • 6. JAVA SE VERSION RELEASE DATE JDK 1.0 Jan-96 JDK 1.1 Feb-97 J2SE 1.2 Dec-98 J2SE 1.3 May-2000 J2SE 1.4 Feb-2002 J2SE 5.0 Sep-2004 Java SE 6 Dec-2006 Java SE 7 Jul-2011 Java SE 8 Mar-2014 Java SE 9 September, 21st 2017 Java SE 10 March, 20th 2018 Java SE 11 September, 25th 2018 Java SE 12 March, 19th 2019 Java SE 13 September, 17th 2019 Java SE 14 March, 17th 2020 Java SE 15 September, 15th 2020 Java SE 16 March, 16th 2021 Java SE 17 September, 14th 2021 Java SE 18 March, 22nd 2022 Java SE 19 September, 20th 2022 Java SE 20 March, 21st 2023 6 Java Versions
  • 7. 7 Procedural Oriented Programming Object-Oriented Programming In procedural programming, the program is divided into small parts called functions. In object-oriented programming, the program is divided into small parts called objects. Procedural programming follows a top-down approach. Object-oriented programming follows a bottom-up approach. There is no access specifier in procedural programming. Object-oriented programming has access specifiers like private, public, protected, etc. Procedural programming does not have any proper way of hiding data so it is less secure. Object-oriented programming provides data hiding so it is more secure. In procedural programming, overloading is not possible. Overloading is possible in object-oriented programming. In procedural programming, there is no concept of data hiding and inheritance. In object-oriented programming, the concept of data hiding and inheritance is used. In procedural programming, the function is more important than the data. In object-oriented programming, data is more important than function. Procedural programming uses the concept of procedure abstraction. Object-oriented programming uses the concept of data abstraction. Code reusability absent in procedural programming, Code reusability present in object-oriented
  • 8. Differences between C++ and Java 8 Sl. no COMPARISON PARAMETER C++ JAVA 1 Developed / Founded by C++ was developed by Bjarne Stroustrup at Bell Labs in 1979. It was developed as an extension of the C language. Java was developed by James Gosling at Sun Microsystems. Now, it is owned by Oracle. 2 Programming model It has support for both procedural programming and object-oriented programming. Java has support only for object-oriented programming models. 3 Platform dependence C++ is platform dependent. It is based on the concept of Write Once Compile Anywhere. Java is platform-independent. It is based on the concept of Write Once Run Anywhere. 4 Features supported C++ supports features like operator overloading, Goto statements, structures, pointers, unions, etc. Java does not support features like operator overloading, Goto statements, structures, pointers, unions, etc. 5 Compilation and Interpretation C ++ is only compiled and cannot be interpreted. Java can be both compiled and interpreted. 6 Library and Code reusability support C++ has very limited libraries with low-level functionalities. C++ allows direct calls to native system libraries. Java, on the other hand, has more diverse libraries with a lot of support for code reusability. In Java, only calls through the Java Native Interface and recently Java Native Access are allowed. 7 Memory Management In C++, memory management is manual. In Java, memory management is System controlled. 9 Global Scope In C++, both global and namespace scopes are supported. Java has no support for global scope.
  • 9. Java Environment • Java Environment includes large number of development tools. • The development tools are part of the system known as Java Development Kit ( 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. 9
  • 10. Java Runtime Environment ( JRE ) • The Java Runtime Environment ( JRE ) facilitates the execution of programs developed in java. It comprises the following: • Java Virtual Machine ( JVM ) : • Java Virtual Machine (JVM) is an engine that provides a runtime environment to drive the Java Code or applications. It converts Java bytecode into machine language. This machine is called Java Virtual Machine and it exists only inside the computer memory. • Compiling source code into bytecode ( machine readable code ) using javac compiler. • Executing the bytecode ( machine-readable code ) to human- understandable code using a Java interpreter 10
  • 11. Java’s Magic: The Byte Code  Allows Java to solve both the security and the portability problems is that the output of a Java compiler is not executable code but it is the Bytecode.  Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system, which is called the Java Virtual Machine (JVM).  JVM is an interpreter for bytecode. The fact that a Java program is executed by JVM helps solve the major problems associated with downloading programs over the Internet.  Translating a Java program into bytecode helps makes it much easier to run a program in a wide variety of environments. This is because only the JVM needs to be implemented for each platform.
  • 12. Java is Compiled and Interpreted Text Editor Compiler Interpreter Programmer Source Code .java file Byte Code .class file Hardware and Operating System Notepad, emacs, javac java appletviewer Java is both compiled and an interpreted lang. First the java compiler translates source code into the byte code instructions. In the next stage the java interpreter converts the byte code instructions to Machine Code.
  • 13. Java features/Java Buzzwords • Simple • Object-Oriented • Portable • Platform independent • Secured • Robust • Architecture neutral • Interpreted • High Performance • Multithreaded • Distributed • Dynamic 13
  • 14. Simple • Java is very easy to learn, and its syntax is simple, clean and easy to understand. • Java syntax is based on C++ (so easier for programmers to learn it after C++). • Java has removed many complicated and rarely-used features, for example, explicit pointers, operator overloading, etc. • There is no need to remove unreferenced objects because there is an Automatic Garbage Collection in Java. 14
  • 15. Secure • Secure As compared to C/C++, Java is considered to be much more secure language, as it does not allow a programmer to create pointers. Thus in Java we cannot access any address directly and this makes Java much more reliable and secure as compared to C/C++. • In Java, we can split a program into multiple parts and store these parts on different computers. 15
  • 16. Object-Oriented • Java is an object-oriented programming language. Everything in Java is an object. • Object-oriented means we organize our software as a combination of different types of objects that incorporate both data and behavior. • Basic concepts of OOPs are: Object Class Inheritance Polymorphism Abstraction Encapsulation 16
  • 17. Platform Independent/Architecture Neutral • Java is platform independent because it is different from other languages like C, C++, etc. • Being java independent means, Programme compiled n one machine that can be executed in another machine without any change. • The Java compiler never converts the source code to machine code like C/C++ compiler. Rather it converts the source code into an intermediate code called as the byte code and this byte code is further translated to machine dependent form by another layer of software called as JVM(Java Virtual Machine). 17
  • 18. Robust • It uses strong memory management. • Java provides automatic garbage collection which runs on the Java Virtual Machine to get rid of objects which are not being used by a Java application anymore. • There are exception handling and the type checking mechanism in Java. All these points make Java robust. • Java is portable because it facilitates you to carry the Java bytecode to any platform. It doesn't require any implementation. 18 Portable
  • 19. Interpreted and High Performance • Java enables the creation of cross-platform programs by compiling into an intermediate representation called Java bytecode. • This code can be executed on any system that implements the Java Virtual Machine. • Most previous attempts at cross-platform solutions have done so at the expense of performance 19
  • 20. Multithreaded • Java supports multithreaded programming, which allows you to write programs that do many things simultaneously. Example: • Railway ticket reservation system where multiple customers accessing the server. Multiple account holders accessing their accounts simultaneously on the server. When you insert a ATM card. 20
  • 21. Distributed • Java is distributed because it facilitates users to create distributed applications in Java. • RMI is used for creating distributed applications. • This feature of Java makes us able to access files by calling the methods from any machine on the internet. • Java supports dynamic compilation and automatic memory management (garbage collection). 21 Dynamic
  • 22. Simple program class Simple { public static void main(String args[]) { System.out.println("Java World"); } } 22
  • 23. Simple program class Simple { public static void main(String args[]) { System.out.println("Java World"); } } 23
  • 24. • Write a java program to convert centigrade into Fahrenheit. • Write a java program to display student details of the following name, Register no, date of birth age and Nationality. • Write a java program to compute simple interest. • Write a java program Fahrenheit to Celsius • Write a java program Find Odd or Even: • Write a java program to compute Fibonacci Series: 24
  • 25. Questions 1. Java object oriented programming concepts is/are Select one: a. Inheritance b. polymorphism c. All of the above. d. Encapsulation 2. Polymorphism types in Java is/are Select one: a. None b. Compile time c. Run time d. Both 3. JVM is an interpreter for Select one: a. Java b. javac c. Bytecode d. JRE 25
  • 26. 4.Java was known as a. jdk b. Apple c. oak d. Java only 5.Java does not support ? Select one: a. compile time polymorphism b. Multiple inheritance for classes c. multiple inheritance of interfaces d. Inheritance 6. Which component is used to compile, debug and execute java program? Select one: a. JIT b. JDK c. JRE d. JVM 7. What is use of interpreter? Select one: a. They are intermediated between JIT and JVM b. They read high level code and execute them c. It is a synonym for JIT d. They convert bytecode to machine language code 26
  • 27. OOPs Concepts • Object-Oriented Programming is a methodology to design a program using classes and objects. It simplifies software development and maintenance by providing some concepts. • Object • Class • Inheritance • Polymorphism • Abstraction • Encapsulation 27
  • 28. Class Class is a collection data members and Methods A class can also be defined as a blueprint from which you can create an individual object. Example: class classname { type instance variable 1; type instance variable 2; . . type instance variable n; type methodname 1 (parameter list) { // body of method } type methodname 2 (parameter list) { // body of method } type methodnamen (parameter list) { // body of method } } 28
  • 29. objects • Any entity that has state and behavior is known as an object • Single Instance of class. • Objects are always called instances of a class which are created from a class in java. Example Public class Mybook { int x=10; Public static void main (String args []) { Mybook Myobj= new Mybook (); System.out.println(MyObj.x); } } 29
  • 30. ABSTRACTION • Abstraction is the process of taking only a set of essential characteristics from something. • Hiding internal details and showing functionality is known as abstraction. • We can say that the main purpose of abstraction is data hiding Abstract class animal { //abstract method public abstract void sound ( ) ; } 30
  • 31. INHERITANCE • Inheritance is the process in which derived class acquire all the properties from the base class. • It inherits the properties from the base class by using extends keyword • It provides code reusability. • It is used to achieve runtime polymorphism. • Types 1.Single level 2.Multilevel 3.Hierarchical level 4.Hybrid inheritance 31
  • 32. Singe Inheritance • In this one class i.e., the derived class inherits properties from its parental class. • Class A is the base or parental class and class b is the derived class. Class a { … } Class b extends class a { … } 32
  • 33. Multilevel Inheritance • This one class is derived from another class which is also derived from another class i.e., this class has more than one parental class, hence it is called multilevel inheritance Class a { …. } Class b extends class a { …. } Class c extends class b { … } 33
  • 34. Hierarchical level • In this one parental class has two or more derived classes or we can say that two or more child classes have one parental class. Class a { …. } Class b extends class a { …. } Class c extends class a { … } 34
  • 35. Hybrid Inheritance • This is the combination of multiple and multilevel inheritances and in java, multiple inheritances are not supported as it leads to ambiguity and this type of inheritance can only be achieved through interfaces. 35
  • 36. POLYMORPHISM • Polymorphism refers to many forms, or it is a process that performs a single action in different ways. TYPES 1.COMPILE TIME  Method Overloading 2. RUN TIME  Method Overriding • One of the examples of Compile time polymorphism is that when we overload a static method in java. • Run time polymorphism also called a dynamic method dispatch is a method in which a call to an overridden method is resolved at run time rather than compile time 36
  • 37. Method Overloading A Class contain two or more methods may have the same name but different parameter List is called Method Overloading void func() { Statement(s) } void func(int a) { Statement(s) } float func(double a) { Statement(s) } float func(int a, float b) { Statement(s) } 37
  • 38. DATA TYPES • Data Types in Java • Data types specify the different sizes and values that can be stored in the variable. 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. 38
  • 39. 39
  • 40. Data Type Size Description byte 1 byte Stores whole numbers from -128 to 127 short 2 bytes Stores whole numbers from -32,768 to 32,767 int 4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647 long 8 bytes Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal digits boolean 1 bit Stores true or false values char 2 bytes Stores a single character/letter or ASCII values 40
  • 41. 41
  • 42. Example • int myNum = 5; // Integer (whole number) • float myFloatNum = 5.99f; // Floating point number • char myLetter = 'D'; // Character • boolean myBool = true; • String name=“Raja”; 42