SlideShare a Scribd company logo
A CASE STUDY ON “JAVA”
By – Ayush Gupta
Himanshu Tripathi
Neeraj Kr Sahu
Sub Topics:–
• Polymorphism
• Encapsulation
• Primitive types in Java
• Casting in Java
• Types of error in Java
POLYMORPHISM IN JAVA
• Polymorphism in Java is a concept by which we can perform a single action in different
ways. Polymorphism is derived from 2 Greek words: ‘poly’ and ‘morphs’.
• The word "poly" means many and "morphs" means forms. So polymorphism means
“many forms”.
• There are two types of polymorphism in Java: Compile-time polymorphism and
Runtime polymorphism.
• We can perform polymorphism in java by ‘method overloading’ and ‘method
overriding’.
• If you overload a static method in Java, it is the example of compile time
polymorphism.
• Here, we will focus on runtime polymorphism in java.
RUNTIME POLYMORPHISM IN JAVA
• Runtime polymorphism or Dynamic Method Dispatch is a process in
which a call to an overridden method is resolved at runtime rather than
compile-time.
• In this process, an overridden method is called through the reference
variable of a super class. The determination of the method to be called
is based on the object being referred to by the reference variable.
EXAMPLE OF JAVA RUNTIME POLYMORPHISM
• In this example, we are creating two classes Bike and Splendor.
• Splendor class extends Bike class and overrides its run ( ) method. We
are calling the run method by the reference variable of Parent class.
• Since it refers to the subclass object and subclass method overrides the
Parent class method, the subclass method is invoked at runtime.
EXAMPLE OF JAVA RUNTIME POLYMORPHISM
CONT.
class Bike
{
void run(){System.out.println("running");
}
}
class Splendor extends Bike
{
void run()
{
System.out.println("running safely with 60km");
}
public static void main(String args[])
{
Bike b = new Splendor();//upcasting
b.run();
}
}
Output:
running safely with 60km.
METHOD OVERRIDING
•If subclass (child class) has the same method as declared in the parent class, it is
known as method overriding in Java.
•In other words, If a subclass provides the specific implementation of the method
that has been declared by one of its parent class, it is known as method
overriding.
•Usage of Java Method Overriding
•Method overriding is used to provide the specific implementation of a method
which is already provided by its superclass.
•Method overriding is used for runtime polymorphism.
METHOD OVERRIDING
Class Super
{
int x=10;
void disp()
{
system.out.println(“Super class” + x);
}
}
Class Test
{
Public static void main(String ar[] )
{
Sub.obj= new Sub();
Obj.disp();
}
}
Class Sub extends Super
{
int y=20;
void disp()
{
System.out.println(“Super”+x);
System.out.println(“Sub”+y);
}
}
OUTPUT:-
Super 10
Sub 20
METHOD OVERLOADING
• If a class has multiple methods having same name but different in parameters, it is known as
Method Overloading.
• If we have to perform only one operation, having same name of the methods increases the
readability of the program.
• Suppose you have to perform addition of the given numbers but there can be any number of
arguments, if you write the method such as a(int , int) for two parameters, and b(int , int , int)
for three parameters then it may be difficult for you as well as other programmers to
understand the behavior of the method because its name differs.
• Method overloading increases the readability of the program.
class DisplayOverloading
{
public void disp(char c)
{
System.out.println(c);
}
public void disp(char c, int num)
{
System.out.println(c + " "+num);
}
}
class Sample
{
public static void main(String args[])
{
DisplayOverloading obj = new
DisplayOverloading();
obj disp('a');
obj disp('a',10);
}
}
Output:
a
a 10
ENCAPSULATION
• Encapsulation in Java is a process of wrapping code and data together
into a single unit, for example, a capsule which is mixed of several
medicines.
• We can create a fully encapsulated class in Java by making all the data
members of the class private. Now we can use setter and getter
methods to set and get the data in it. The Java Bean class is the
example of a fully encapsulated class.
ADVANTAGE OF ENCAPSULATION
These are benefits of Java Encapsulation:
Data Hiding – It can provide the programmer to hide the inner classes and the user
to give access only to the desired codes. It allows the programmer to not allow the
user to know how variables and data store.
Flexibility – With this, we can make the data as read-only or write-only as we
require it to be.
Reusability – It allows the user to a programmer to use the program again and
again.
Testing of the code – Ease of testing becomes easy.
PRIMITIVE TYPES
• int 4 bytes
• short 2 bytes
• long 8 bytes
• byte 1 byte
• float 4 bytes
• double 8 bytes
• char Unicode encoding (2 bytes)
• boolean {true,false}
Behaviors is
exactly as in
C++
JAVA PRIMITIVE DATA TYPES
Data Type Characteristics Range
byte 8 bit signed integer -128 to 127
short 16 bit signed integer -32768 to 32767
int 32 bit signed integer -2,147,483,648 to 2,147,483,647
long 64 bit signed integer -9,223,372,036,854,775,808 to- 9,223,372,036,854,775,807
float 32 bit floating point number + 1.4E-45 to
+ 3.4028235E+38
double 64 bit floating point number + 4.9E-324 to
+ 1.7976931348623157E+308
boolean true or false NA, note Java booleans cannot be converted to or from other
types
char 16 bit, Unicode Unicode character, u0000 to uFFFF Can mix with integer
types
Constants:-
• 37 integer
• 37.2 float
• 42F float
• 0754 integer (octal)
• 0xfe integer (hexadecimal)
Primitive types - cont.
CASTING
• Casting is the temporary conversion of a variable from its original
data type to some other data type.
• With primitive data types if a cast is necessary from a less inclusive
data type to a more inclusive data type it is done automatically.
int x = 5;
double a = 3.5;
double b = a * x + a / x;
double c = x / 2;
• if a cast is necessary from a more inclusive to a less inclusive data
type the class must be done explicitly by the programmer
failure to do so results in a compile error.
double a = 3.5, b = 2.7;
int y = (int) a / (int) b;
y = (int)( a / b );
y = (int) a / b; //syntax error
PRIMITIVE CASTING
double
float
long
int
short,
char
byte
Outer ring is most inclusive
data type.
Inner ring is least inclusive.
In expressions variables and
sub expressions of less
inclusive data types are
automatically cast to more
inclusive.
If trying to place expression
that is more inclusive into
variable that is less inclusive,
explicit cast must be
performed.
From MORE to LESS
SYNTAX ERRORS, RUNTIME ERRORS, AND LOGIC ERRORS
You learned that there are three categories of errors: syntax errors,
runtime errors, and logic errors.
• Syntax errors arise because the rules of the language have not
been followed. They are detected by the compiler.
• Runtime errors occur while the program is running if the
environment detects an operation that is impossible to carry out.
• Logic errors occur when a program doesn't perform the way it
was intended to.
A Case Study on Java. Java Presentation
A CASE STUDY ON “JAVA”
By – Ayush Gupta
Himanshu Tripathi
Neeraj Kr Sahu
Next Topic – Exception Handling
Ad

More Related Content

What's hot (20)

Java Arrays
Java ArraysJava Arrays
Java Arrays
Jussi Pohjolainen
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java
Janu Jahnavi
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
Elizabeth alexander
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its types
Suraj Bora
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37
myrajendra
 
virtual function
virtual functionvirtual function
virtual function
VENNILAV6
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
VINOTH R
 
Java threads
Java threadsJava threads
Java threads
Prabhakaran V M
 
Constructors
ConstructorsConstructors
Constructors
M Vishnuvardhan Reddy
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
Spotle.ai
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
Ankita Totala
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
Lovely Professional University
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
Dhrumil Panchal
 
Expression trees
Expression treesExpression trees
Expression trees
Salman Vadsarya
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
Hitesh Kumar
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
sureshraj43
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
Hitesh Kumar
 
Dynamic method dispatch
Dynamic method dispatchDynamic method dispatch
Dynamic method dispatch
yugandhar vadlamudi
 
Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
A-Tech and Software Development
 

Similar to A Case Study on Java. Java Presentation (20)

Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwords
Raja Sekhar
 
JAVA Class Presentation.pdf Vsjsjsnheheh
JAVA Class Presentation.pdf VsjsjsnhehehJAVA Class Presentation.pdf Vsjsjsnheheh
JAVA Class Presentation.pdf Vsjsjsnheheh
AnushreeP4
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
Sherihan Anver
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
KartikKapgate
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
Sherihan Anver
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
Rakesh Madugula
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
Ahmed Farag
 
OOP-JAVA-ONLYUNIT-2-PPT_removed (1).pptx
OOP-JAVA-ONLYUNIT-2-PPT_removed (1).pptxOOP-JAVA-ONLYUNIT-2-PPT_removed (1).pptx
OOP-JAVA-ONLYUNIT-2-PPT_removed (1).pptx
deepayaganti1
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
tuyambazejeanclaude
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
AnsgarMary
 
Java basics training 1
Java basics training 1Java basics training 1
Java basics training 1
Kushan Shalindra Amarasiri - Technical QE Specialist
 
Unit 4
Unit 4Unit 4
Unit 4
LOVELY PROFESSIONAL UNIVERSITY
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Concepts
mdfkhan625
 
JAVA Basics Presentation for introduction to JAVA programming languauge
JAVA Basics Presentation for introduction to JAVA programming languaugeJAVA Basics Presentation for introduction to JAVA programming languauge
JAVA Basics Presentation for introduction to JAVA programming languauge
lakshyajain0740
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
apoorvams
 
Super Keyword in Java.pptx
Super Keyword in Java.pptxSuper Keyword in Java.pptx
Super Keyword in Java.pptx
KrutikaWankhade1
 
PROGRAMMING IN JAVA
PROGRAMMING IN JAVAPROGRAMMING IN JAVA
PROGRAMMING IN JAVA
SivaSankari36
 
full defination of final opp.pptx
full defination of final opp.pptxfull defination of final opp.pptx
full defination of final opp.pptx
rayanbabur
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
Chikugehlot
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwords
Raja Sekhar
 
JAVA Class Presentation.pdf Vsjsjsnheheh
JAVA Class Presentation.pdf VsjsjsnhehehJAVA Class Presentation.pdf Vsjsjsnheheh
JAVA Class Presentation.pdf Vsjsjsnheheh
AnushreeP4
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
Sherihan Anver
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
KartikKapgate
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
Rakesh Madugula
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
Ahmed Farag
 
OOP-JAVA-ONLYUNIT-2-PPT_removed (1).pptx
OOP-JAVA-ONLYUNIT-2-PPT_removed (1).pptxOOP-JAVA-ONLYUNIT-2-PPT_removed (1).pptx
OOP-JAVA-ONLYUNIT-2-PPT_removed (1).pptx
deepayaganti1
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
AnsgarMary
 
Core Java Concepts
Core Java ConceptsCore Java Concepts
Core Java Concepts
mdfkhan625
 
JAVA Basics Presentation for introduction to JAVA programming languauge
JAVA Basics Presentation for introduction to JAVA programming languaugeJAVA Basics Presentation for introduction to JAVA programming languauge
JAVA Basics Presentation for introduction to JAVA programming languauge
lakshyajain0740
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
apoorvams
 
Super Keyword in Java.pptx
Super Keyword in Java.pptxSuper Keyword in Java.pptx
Super Keyword in Java.pptx
KrutikaWankhade1
 
full defination of final opp.pptx
full defination of final opp.pptxfull defination of final opp.pptx
full defination of final opp.pptx
rayanbabur
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
Chikugehlot
 
Ad

Recently uploaded (20)

Presentatation_SM_muscle_structpes_funtionre_ty.pptx
Presentatation_SM_muscle_structpes_funtionre_ty.pptxPresentatation_SM_muscle_structpes_funtionre_ty.pptx
Presentatation_SM_muscle_structpes_funtionre_ty.pptx
muralinath2
 
Direct Evidence for r-process Nucleosynthesis in Delayed MeV Emission from th...
Direct Evidence for r-process Nucleosynthesis in Delayed MeV Emission from th...Direct Evidence for r-process Nucleosynthesis in Delayed MeV Emission from th...
Direct Evidence for r-process Nucleosynthesis in Delayed MeV Emission from th...
Sérgio Sacani
 
SuperconductingMagneticEnergyStorage.pptx
SuperconductingMagneticEnergyStorage.pptxSuperconductingMagneticEnergyStorage.pptx
SuperconductingMagneticEnergyStorage.pptx
BurkanAlpKale
 
Application of Microbiology- Industrial, agricultural, medical
Application of Microbiology- Industrial, agricultural, medicalApplication of Microbiology- Industrial, agricultural, medical
Application of Microbiology- Industrial, agricultural, medical
Anoja Kurian
 
Gender Bias and Empathy in Robots: Insights into Robotic Service Failures
Gender Bias and Empathy in Robots:  Insights into Robotic Service FailuresGender Bias and Empathy in Robots:  Insights into Robotic Service Failures
Gender Bias and Empathy in Robots: Insights into Robotic Service Failures
Selcen Ozturkcan
 
Concise Notes on tree and graph data structure
Concise Notes on tree and graph data structureConcise Notes on tree and graph data structure
Concise Notes on tree and graph data structure
YekoyeTigabu2
 
Chromatography, types, techniques, ppt.pptx
Chromatography, types, techniques, ppt.pptxChromatography, types, techniques, ppt.pptx
Chromatography, types, techniques, ppt.pptx
Dr Showkat Ahmad Wani
 
Multydisciplinary Nature of Environmental Studies
Multydisciplinary Nature of Environmental StudiesMultydisciplinary Nature of Environmental Studies
Multydisciplinary Nature of Environmental Studies
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Nutritional Diseases in poultry.........
Nutritional Diseases in poultry.........Nutritional Diseases in poultry.........
Nutritional Diseases in poultry.........
Bangladesh Agricultural University,Mymemsingh
 
Preparation of Permanent mounts of Parasitic Protozoans.pptx
Preparation of Permanent mounts of Parasitic Protozoans.pptxPreparation of Permanent mounts of Parasitic Protozoans.pptx
Preparation of Permanent mounts of Parasitic Protozoans.pptx
Dr Showkat Ahmad Wani
 
Structure formation with primordial black holes: collisional dynamics, binari...
Structure formation with primordial black holes: collisional dynamics, binari...Structure formation with primordial black holes: collisional dynamics, binari...
Structure formation with primordial black holes: collisional dynamics, binari...
Sérgio Sacani
 
Influenza-Understanding-the-Deadly-Virus.pptx
Influenza-Understanding-the-Deadly-Virus.pptxInfluenza-Understanding-the-Deadly-Virus.pptx
Influenza-Understanding-the-Deadly-Virus.pptx
diyapadhiyar
 
2025 Insilicogen Company Korean Brochure
2025 Insilicogen Company Korean Brochure2025 Insilicogen Company Korean Brochure
2025 Insilicogen Company Korean Brochure
Insilico Gen
 
Skin_Glands_Structure_Secretion _Control
Skin_Glands_Structure_Secretion _ControlSkin_Glands_Structure_Secretion _Control
Skin_Glands_Structure_Secretion _Control
muralinath2
 
Zoonosis, Types, Causes. A comprehensive pptx
Zoonosis, Types, Causes. A comprehensive pptxZoonosis, Types, Causes. A comprehensive pptx
Zoonosis, Types, Causes. A comprehensive pptx
Dr Showkat Ahmad Wani
 
Keynote presentation at DeepTest Workshop 2025
Keynote presentation at DeepTest Workshop 2025Keynote presentation at DeepTest Workshop 2025
Keynote presentation at DeepTest Workshop 2025
Shiva Nejati
 
DNA Profiling and STR Typing in Forensics: From Molecular Techniques to Real-...
DNA Profiling and STR Typing in Forensics: From Molecular Techniques to Real-...DNA Profiling and STR Typing in Forensics: From Molecular Techniques to Real-...
DNA Profiling and STR Typing in Forensics: From Molecular Techniques to Real-...
home
 
Turkey Diseases and Disorders Volume 2 Infectious and Nutritional Diseases, D...
Turkey Diseases and Disorders Volume 2 Infectious and Nutritional Diseases, D...Turkey Diseases and Disorders Volume 2 Infectious and Nutritional Diseases, D...
Turkey Diseases and Disorders Volume 2 Infectious and Nutritional Diseases, D...
Ali Raei
 
Antonie van Leeuwenhoek- Father of Microbiology
Antonie van Leeuwenhoek- Father of MicrobiologyAntonie van Leeuwenhoek- Father of Microbiology
Antonie van Leeuwenhoek- Father of Microbiology
Anoja Kurian
 
whole ANATOMY OF EYE with eye ball .pptx
whole ANATOMY OF EYE with eye ball .pptxwhole ANATOMY OF EYE with eye ball .pptx
whole ANATOMY OF EYE with eye ball .pptx
simranjangra13
 
Presentatation_SM_muscle_structpes_funtionre_ty.pptx
Presentatation_SM_muscle_structpes_funtionre_ty.pptxPresentatation_SM_muscle_structpes_funtionre_ty.pptx
Presentatation_SM_muscle_structpes_funtionre_ty.pptx
muralinath2
 
Direct Evidence for r-process Nucleosynthesis in Delayed MeV Emission from th...
Direct Evidence for r-process Nucleosynthesis in Delayed MeV Emission from th...Direct Evidence for r-process Nucleosynthesis in Delayed MeV Emission from th...
Direct Evidence for r-process Nucleosynthesis in Delayed MeV Emission from th...
Sérgio Sacani
 
SuperconductingMagneticEnergyStorage.pptx
SuperconductingMagneticEnergyStorage.pptxSuperconductingMagneticEnergyStorage.pptx
SuperconductingMagneticEnergyStorage.pptx
BurkanAlpKale
 
Application of Microbiology- Industrial, agricultural, medical
Application of Microbiology- Industrial, agricultural, medicalApplication of Microbiology- Industrial, agricultural, medical
Application of Microbiology- Industrial, agricultural, medical
Anoja Kurian
 
Gender Bias and Empathy in Robots: Insights into Robotic Service Failures
Gender Bias and Empathy in Robots:  Insights into Robotic Service FailuresGender Bias and Empathy in Robots:  Insights into Robotic Service Failures
Gender Bias and Empathy in Robots: Insights into Robotic Service Failures
Selcen Ozturkcan
 
Concise Notes on tree and graph data structure
Concise Notes on tree and graph data structureConcise Notes on tree and graph data structure
Concise Notes on tree and graph data structure
YekoyeTigabu2
 
Chromatography, types, techniques, ppt.pptx
Chromatography, types, techniques, ppt.pptxChromatography, types, techniques, ppt.pptx
Chromatography, types, techniques, ppt.pptx
Dr Showkat Ahmad Wani
 
Preparation of Permanent mounts of Parasitic Protozoans.pptx
Preparation of Permanent mounts of Parasitic Protozoans.pptxPreparation of Permanent mounts of Parasitic Protozoans.pptx
Preparation of Permanent mounts of Parasitic Protozoans.pptx
Dr Showkat Ahmad Wani
 
Structure formation with primordial black holes: collisional dynamics, binari...
Structure formation with primordial black holes: collisional dynamics, binari...Structure formation with primordial black holes: collisional dynamics, binari...
Structure formation with primordial black holes: collisional dynamics, binari...
Sérgio Sacani
 
Influenza-Understanding-the-Deadly-Virus.pptx
Influenza-Understanding-the-Deadly-Virus.pptxInfluenza-Understanding-the-Deadly-Virus.pptx
Influenza-Understanding-the-Deadly-Virus.pptx
diyapadhiyar
 
2025 Insilicogen Company Korean Brochure
2025 Insilicogen Company Korean Brochure2025 Insilicogen Company Korean Brochure
2025 Insilicogen Company Korean Brochure
Insilico Gen
 
Skin_Glands_Structure_Secretion _Control
Skin_Glands_Structure_Secretion _ControlSkin_Glands_Structure_Secretion _Control
Skin_Glands_Structure_Secretion _Control
muralinath2
 
Zoonosis, Types, Causes. A comprehensive pptx
Zoonosis, Types, Causes. A comprehensive pptxZoonosis, Types, Causes. A comprehensive pptx
Zoonosis, Types, Causes. A comprehensive pptx
Dr Showkat Ahmad Wani
 
Keynote presentation at DeepTest Workshop 2025
Keynote presentation at DeepTest Workshop 2025Keynote presentation at DeepTest Workshop 2025
Keynote presentation at DeepTest Workshop 2025
Shiva Nejati
 
DNA Profiling and STR Typing in Forensics: From Molecular Techniques to Real-...
DNA Profiling and STR Typing in Forensics: From Molecular Techniques to Real-...DNA Profiling and STR Typing in Forensics: From Molecular Techniques to Real-...
DNA Profiling and STR Typing in Forensics: From Molecular Techniques to Real-...
home
 
Turkey Diseases and Disorders Volume 2 Infectious and Nutritional Diseases, D...
Turkey Diseases and Disorders Volume 2 Infectious and Nutritional Diseases, D...Turkey Diseases and Disorders Volume 2 Infectious and Nutritional Diseases, D...
Turkey Diseases and Disorders Volume 2 Infectious and Nutritional Diseases, D...
Ali Raei
 
Antonie van Leeuwenhoek- Father of Microbiology
Antonie van Leeuwenhoek- Father of MicrobiologyAntonie van Leeuwenhoek- Father of Microbiology
Antonie van Leeuwenhoek- Father of Microbiology
Anoja Kurian
 
whole ANATOMY OF EYE with eye ball .pptx
whole ANATOMY OF EYE with eye ball .pptxwhole ANATOMY OF EYE with eye ball .pptx
whole ANATOMY OF EYE with eye ball .pptx
simranjangra13
 
Ad

A Case Study on Java. Java Presentation

  • 1. A CASE STUDY ON “JAVA” By – Ayush Gupta Himanshu Tripathi Neeraj Kr Sahu Sub Topics:– • Polymorphism • Encapsulation • Primitive types in Java • Casting in Java • Types of error in Java
  • 2. POLYMORPHISM IN JAVA • Polymorphism in Java is a concept by which we can perform a single action in different ways. Polymorphism is derived from 2 Greek words: ‘poly’ and ‘morphs’. • The word "poly" means many and "morphs" means forms. So polymorphism means “many forms”. • There are two types of polymorphism in Java: Compile-time polymorphism and Runtime polymorphism. • We can perform polymorphism in java by ‘method overloading’ and ‘method overriding’. • If you overload a static method in Java, it is the example of compile time polymorphism. • Here, we will focus on runtime polymorphism in java.
  • 3. RUNTIME POLYMORPHISM IN JAVA • Runtime polymorphism or Dynamic Method Dispatch is a process in which a call to an overridden method is resolved at runtime rather than compile-time. • In this process, an overridden method is called through the reference variable of a super class. The determination of the method to be called is based on the object being referred to by the reference variable.
  • 4. EXAMPLE OF JAVA RUNTIME POLYMORPHISM • In this example, we are creating two classes Bike and Splendor. • Splendor class extends Bike class and overrides its run ( ) method. We are calling the run method by the reference variable of Parent class. • Since it refers to the subclass object and subclass method overrides the Parent class method, the subclass method is invoked at runtime.
  • 5. EXAMPLE OF JAVA RUNTIME POLYMORPHISM CONT. class Bike { void run(){System.out.println("running"); } } class Splendor extends Bike { void run() { System.out.println("running safely with 60km"); } public static void main(String args[]) { Bike b = new Splendor();//upcasting b.run(); } } Output: running safely with 60km.
  • 6. METHOD OVERRIDING •If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in Java. •In other words, If a subclass provides the specific implementation of the method that has been declared by one of its parent class, it is known as method overriding. •Usage of Java Method Overriding •Method overriding is used to provide the specific implementation of a method which is already provided by its superclass. •Method overriding is used for runtime polymorphism.
  • 7. METHOD OVERRIDING Class Super { int x=10; void disp() { system.out.println(“Super class” + x); } } Class Test { Public static void main(String ar[] ) { Sub.obj= new Sub(); Obj.disp(); } } Class Sub extends Super { int y=20; void disp() { System.out.println(“Super”+x); System.out.println(“Sub”+y); } } OUTPUT:- Super 10 Sub 20
  • 8. METHOD OVERLOADING • If a class has multiple methods having same name but different in parameters, it is known as Method Overloading. • If we have to perform only one operation, having same name of the methods increases the readability of the program. • Suppose you have to perform addition of the given numbers but there can be any number of arguments, if you write the method such as a(int , int) for two parameters, and b(int , int , int) for three parameters then it may be difficult for you as well as other programmers to understand the behavior of the method because its name differs. • Method overloading increases the readability of the program.
  • 9. class DisplayOverloading { public void disp(char c) { System.out.println(c); } public void disp(char c, int num) { System.out.println(c + " "+num); } } class Sample { public static void main(String args[]) { DisplayOverloading obj = new DisplayOverloading(); obj disp('a'); obj disp('a',10); } } Output: a a 10
  • 10. ENCAPSULATION • Encapsulation in Java is a process of wrapping code and data together into a single unit, for example, a capsule which is mixed of several medicines. • We can create a fully encapsulated class in Java by making all the data members of the class private. Now we can use setter and getter methods to set and get the data in it. The Java Bean class is the example of a fully encapsulated class.
  • 11. ADVANTAGE OF ENCAPSULATION These are benefits of Java Encapsulation: Data Hiding – It can provide the programmer to hide the inner classes and the user to give access only to the desired codes. It allows the programmer to not allow the user to know how variables and data store. Flexibility – With this, we can make the data as read-only or write-only as we require it to be. Reusability – It allows the user to a programmer to use the program again and again. Testing of the code – Ease of testing becomes easy.
  • 12. PRIMITIVE TYPES • int 4 bytes • short 2 bytes • long 8 bytes • byte 1 byte • float 4 bytes • double 8 bytes • char Unicode encoding (2 bytes) • boolean {true,false} Behaviors is exactly as in C++
  • 13. JAVA PRIMITIVE DATA TYPES Data Type Characteristics Range byte 8 bit signed integer -128 to 127 short 16 bit signed integer -32768 to 32767 int 32 bit signed integer -2,147,483,648 to 2,147,483,647 long 64 bit signed integer -9,223,372,036,854,775,808 to- 9,223,372,036,854,775,807 float 32 bit floating point number + 1.4E-45 to + 3.4028235E+38 double 64 bit floating point number + 4.9E-324 to + 1.7976931348623157E+308 boolean true or false NA, note Java booleans cannot be converted to or from other types char 16 bit, Unicode Unicode character, u0000 to uFFFF Can mix with integer types
  • 14. Constants:- • 37 integer • 37.2 float • 42F float • 0754 integer (octal) • 0xfe integer (hexadecimal) Primitive types - cont.
  • 15. CASTING • Casting is the temporary conversion of a variable from its original data type to some other data type. • With primitive data types if a cast is necessary from a less inclusive data type to a more inclusive data type it is done automatically. int x = 5; double a = 3.5; double b = a * x + a / x; double c = x / 2; • if a cast is necessary from a more inclusive to a less inclusive data type the class must be done explicitly by the programmer failure to do so results in a compile error. double a = 3.5, b = 2.7; int y = (int) a / (int) b; y = (int)( a / b ); y = (int) a / b; //syntax error
  • 16. PRIMITIVE CASTING double float long int short, char byte Outer ring is most inclusive data type. Inner ring is least inclusive. In expressions variables and sub expressions of less inclusive data types are automatically cast to more inclusive. If trying to place expression that is more inclusive into variable that is less inclusive, explicit cast must be performed. From MORE to LESS
  • 17. SYNTAX ERRORS, RUNTIME ERRORS, AND LOGIC ERRORS You learned that there are three categories of errors: syntax errors, runtime errors, and logic errors. • Syntax errors arise because the rules of the language have not been followed. They are detected by the compiler. • Runtime errors occur while the program is running if the environment detects an operation that is impossible to carry out. • Logic errors occur when a program doesn't perform the way it was intended to.
  • 19. A CASE STUDY ON “JAVA” By – Ayush Gupta Himanshu Tripathi Neeraj Kr Sahu Next Topic – Exception Handling