SlideShare a Scribd company logo
1 of 19
Introduction to Java II
P.1
ghadeer-al-hasan ghadeerof@gamil.com
Object & Classes:
Object:
An entity that has state and behavior,
• state: represent data of an object.
• behavior: represent functionality of an object such as deposit.
• identity: object identity is typically implemented via unique ID.
The value of the ID is not visible to the external user, But, it is used
internally by the JVM to identify each object uniquely.
Class:
• Is a group of objects that has common properties, it is a template or
blueprint from which objects are created.
• In java can contain: data member, method, constructor, block,
Class and interface.
P.2
Variable and DataType :
Variable :
Variable is name of reserved area allocated in memory(RAM).
Type of Variable:
There are three type of variable in java:
• Local variable
that is declared inside the method
• Instance variable
that declared inside the class but outside the method, isn’t declared as static
• Static variable
that is declared as static , it cannot be local, are stored in static memory,
created when the program starts and destroyed when the program stops
P.3
Variable and DataType :
Data Types:
• Primitive data types
• Non- primitive data types
P.4
Variable and DataType :
Data Type Default Value Default size
boolean false 1 bit
char ‘u0000’ 2 byte
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
float 0.0f 4 byte
double 0.0d 8 byte
P.5
P.S :
In Unicode, character holds 2 byte, so java also uses 2 byte for character.
Lowest value: u0000
Highest value: uFFFF
P.6
Constructor:
Is a special type of method that is used to initialize the object.
It is invoked at the time of object creation, constructor the values
There are basically two rules defined for the constructor:
1. Constructor name must be same as its class name
2. Constructor must have no explicit return type.
There are two types of constructor:
1. Default constructor (no- arg constructor)
2. Parameterized constructor
P.S:
If there is no constructor in a class, compiler automatically creates a default
Constructor, it is provides the default values the object
P.7
Example of default constructor:
P.8
Example of parameterized constructor :
It is used to provider different values to the distinct objects.
Student s3 = new Student();
it is false
Why???
P.9
Overloading Constructor:
The compiler differentiates
these constructors by taking into account
the number of parameters
in the list and their type
P.10
Difference between constructor and method:
Constructor Method
Is used to initialize the state of an object Is used to expose behavior of an object
Must not have return type Must have return type
Is invoked implicitly Is invoked explicitly
Compiler provides a default constructor if you
don’t have any constructor
Is not provided by compiler in any case
Name must be same as the class name Name may or may not be same as class name
P.11
Copier Constructor:
P.12
Access Modifier:
The access modifiers specifies accessibility of a data member, method, constructor or class.
There are 4 types of access modifiers :
1. private
is accessible only within class
2. default
when you don’t use any modifier, it is treated as default by default, is accessible only with package
3. protected
is accessible within package and outside the package but through inheritance only
it can’t be applied on the class
4. public
accessible everywhere , it has the widest scope among all other modifiers
P.13
Example of Private Access Modifier:
Student.java
Main.java
If you make any class constructor private,
you cannot create the instance of that
class from outside the class
A class cannot be private or
protected except nested class
P.14
Example of Default Access Modifier:
A.java
A class is not public,
so it cannot be accessed from
outside the package.
B.java
P.15
Example of Protected Access Modifier:
Student.java
P.16
Main.java
Example of Public Access Modifier :
Student.java
Main.java
P.17
Finally :
Access
Modifier
Within
class
Within
package
Outside
package by
subclass only
Outside
package
Private Yes No No No
Default Yes Yes No No
Protected Yes Yes Yes No
Public Yes Yes Yes Yes
P.18
The End
ghadeer-al-hasan ghadeerof@gamil.com

More Related Content

What's hot

Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationHoneyChintal
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented PrinciplesSujit Majety
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variablesPushpendra Tyagi
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasShahzad Younas
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentationtigerwarn
 
Object oriented programming interview questions
Object oriented programming interview questionsObject oriented programming interview questions
Object oriented programming interview questionsKeet Sugathadasa
 
Introduction to C++ Programming
Introduction to C++ ProgrammingIntroduction to C++ Programming
Introduction to C++ ProgrammingPreeti Kashyap
 
Learn Java language fundamentals with Unit nexus
Learn Java language fundamentals with Unit nexusLearn Java language fundamentals with Unit nexus
Learn Java language fundamentals with Unit nexusUnit Nexus Pvt. Ltd.
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteTushar B Kute
 
object oriented programming using c++
 object oriented programming using c++ object oriented programming using c++
object oriented programming using c++fasalsial1fasalsial1
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classesasadsardar
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in JavaKurapati Vishwak
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingJun Shimizu
 
6 class and methods
6    class and methods6    class and methods
6 class and methodsTuan Ngo
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingumairrajpoot6
 

What's hot (20)

Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
 
Oop
OopOop
Oop
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variables
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younas
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
Object oriented programming interview questions
Object oriented programming interview questionsObject oriented programming interview questions
Object oriented programming interview questions
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Introduction to C++ Programming
Introduction to C++ ProgrammingIntroduction to C++ Programming
Introduction to C++ Programming
 
Learn Java language fundamentals with Unit nexus
Learn Java language fundamentals with Unit nexusLearn Java language fundamentals with Unit nexus
Learn Java language fundamentals with Unit nexus
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
object oriented programming using c++
 object oriented programming using c++ object oriented programming using c++
object oriented programming using c++
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classes
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Friend Function
Friend FunctionFriend Function
Friend Function
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
6 class and methods
6    class and methods6    class and methods
6 class and methods
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 

Similar to 2- Introduction to java II

Qb it1301
Qb   it1301Qb   it1301
Qb it1301ArthyR3
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in javaElizabeth alexander
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfacesmadhavi patil
 
OOP in Java Presentation.pptx
OOP in Java Presentation.pptxOOP in Java Presentation.pptx
OOP in Java Presentation.pptxmrxyz19
 
+2 CS class and objects
+2 CS class and objects+2 CS class and objects
+2 CS class and objectskhaliledapal
 
[Java] #8 String and Inner Class
[Java] #8 String and Inner Class[Java] #8 String and Inner Class
[Java] #8 String and Inner ClassGhadeer AlHasan
 
Object oriented programming CLASSES-AND-OBJECTS.pptx
Object oriented programming CLASSES-AND-OBJECTS.pptxObject oriented programming CLASSES-AND-OBJECTS.pptx
Object oriented programming CLASSES-AND-OBJECTS.pptxDaveEstonilo
 
Classes-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfClasses-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfismartshanker1
 
JavaScript OOPS Implimentation
JavaScript OOPS ImplimentationJavaScript OOPS Implimentation
JavaScript OOPS ImplimentationUsman Mehmood
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxDrYogeshDeshmukh1
 
Constructors in Java (2).pdf
Constructors in Java (2).pdfConstructors in Java (2).pdf
Constructors in Java (2).pdfkumari36
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitishChaulagai
 

Similar to 2- Introduction to java II (20)

oopm 2.pdf
oopm 2.pdfoopm 2.pdf
oopm 2.pdf
 
Qb it1301
Qb   it1301Qb   it1301
Qb it1301
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 
Java Object Oriented Programming
Java Object Oriented Programming Java Object Oriented Programming
Java Object Oriented Programming
 
OOP in Java Presentation.pptx
OOP in Java Presentation.pptxOOP in Java Presentation.pptx
OOP in Java Presentation.pptx
 
+2 CS class and objects
+2 CS class and objects+2 CS class and objects
+2 CS class and objects
 
Java notes
Java notesJava notes
Java notes
 
[Java] #8 String and Inner Class
[Java] #8 String and Inner Class[Java] #8 String and Inner Class
[Java] #8 String and Inner Class
 
Object oriented programming CLASSES-AND-OBJECTS.pptx
Object oriented programming CLASSES-AND-OBJECTS.pptxObject oriented programming CLASSES-AND-OBJECTS.pptx
Object oriented programming CLASSES-AND-OBJECTS.pptx
 
Classes-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfClasses-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdf
 
CHAPTER 3 part1.pdf
CHAPTER 3 part1.pdfCHAPTER 3 part1.pdf
CHAPTER 3 part1.pdf
 
JavaScript OOPS Implimentation
JavaScript OOPS ImplimentationJavaScript OOPS Implimentation
JavaScript OOPS Implimentation
 
Class and object
Class and objectClass and object
Class and object
 
Computer Programming 2
Computer Programming 2 Computer Programming 2
Computer Programming 2
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptx
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Constructors in Java (2).pdf
Constructors in Java (2).pdfConstructors in Java (2).pdf
Constructors in Java (2).pdf
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 

More from Ghadeer AlHasan

More from Ghadeer AlHasan (20)

[C++ Tutorial ] #9 Classes
[C++ Tutorial ] #9 Classes[C++ Tutorial ] #9 Classes
[C++ Tutorial ] #9 Classes
 
[C++ Tutorial] #8 Files
[C++ Tutorial] #8 Files[C++ Tutorial] #8 Files
[C++ Tutorial] #8 Files
 
[C++ Tutorial] #7- Linked List
[C++ Tutorial] #7- Linked List[C++ Tutorial] #7- Linked List
[C++ Tutorial] #7- Linked List
 
[C++ Tutorial] #6- Pointers
[C++ Tutorial] #6- Pointers [C++ Tutorial] #6- Pointers
[C++ Tutorial] #6- Pointers
 
[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream
 
[C++] #5 - Structures
[C++] #5 - Structures[C++] #5 - Structures
[C++] #5 - Structures
 
3- Operators in Java
3- Operators in Java3- Operators in Java
3- Operators in Java
 
1- Introduction to java
1- Introduction to java1- Introduction to java
1- Introduction to java
 
0- Overview
0- Overview0- Overview
0- Overview
 
4- Arrays
4-  Arrays4-  Arrays
4- Arrays
 
3- Functions
3-  Functions3-  Functions
3- Functions
 
2- Control Structures
2-  Control Structures2-  Control Structures
2- Control Structures
 
1- Languages Basics
1- Languages Basics1- Languages Basics
1- Languages Basics
 
#8 (Java Message Service)
#8 (Java Message Service)#8 (Java Message Service)
#8 (Java Message Service)
 
#7 (Java Message Service)
#7 (Java Message Service)#7 (Java Message Service)
#7 (Java Message Service)
 
#6 (RESTtful Web Wervices)
#6 (RESTtful Web Wervices)#6 (RESTtful Web Wervices)
#6 (RESTtful Web Wervices)
 
#5 (Remote Method Invocation)
#5 (Remote Method Invocation)#5 (Remote Method Invocation)
#5 (Remote Method Invocation)
 
#4 (Remote Method Invocation)
#4 (Remote Method Invocation)#4 (Remote Method Invocation)
#4 (Remote Method Invocation)
 
#3 (Multi Threads With TCP)
#3 (Multi Threads With TCP)#3 (Multi Threads With TCP)
#3 (Multi Threads With TCP)
 
#2 (UDP)
#2 (UDP)#2 (UDP)
#2 (UDP)
 

Recently uploaded

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 

Recently uploaded (20)

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 

2- Introduction to java II

  • 1. Introduction to Java II P.1 ghadeer-al-hasan ghadeerof@gamil.com
  • 2. Object & Classes: Object: An entity that has state and behavior, • state: represent data of an object. • behavior: represent functionality of an object such as deposit. • identity: object identity is typically implemented via unique ID. The value of the ID is not visible to the external user, But, it is used internally by the JVM to identify each object uniquely. Class: • Is a group of objects that has common properties, it is a template or blueprint from which objects are created. • In java can contain: data member, method, constructor, block, Class and interface. P.2
  • 3. Variable and DataType : Variable : Variable is name of reserved area allocated in memory(RAM). Type of Variable: There are three type of variable in java: • Local variable that is declared inside the method • Instance variable that declared inside the class but outside the method, isn’t declared as static • Static variable that is declared as static , it cannot be local, are stored in static memory, created when the program starts and destroyed when the program stops P.3
  • 4. Variable and DataType : Data Types: • Primitive data types • Non- primitive data types P.4
  • 5. Variable and DataType : Data Type Default Value Default size boolean false 1 bit char ‘u0000’ 2 byte byte 0 1 byte short 0 2 byte int 0 4 byte long 0L 8 byte float 0.0f 4 byte double 0.0d 8 byte P.5
  • 6. P.S : In Unicode, character holds 2 byte, so java also uses 2 byte for character. Lowest value: u0000 Highest value: uFFFF P.6
  • 7. Constructor: Is a special type of method that is used to initialize the object. It is invoked at the time of object creation, constructor the values There are basically two rules defined for the constructor: 1. Constructor name must be same as its class name 2. Constructor must have no explicit return type. There are two types of constructor: 1. Default constructor (no- arg constructor) 2. Parameterized constructor P.S: If there is no constructor in a class, compiler automatically creates a default Constructor, it is provides the default values the object P.7
  • 8. Example of default constructor: P.8
  • 9. Example of parameterized constructor : It is used to provider different values to the distinct objects. Student s3 = new Student(); it is false Why??? P.9
  • 10. Overloading Constructor: The compiler differentiates these constructors by taking into account the number of parameters in the list and their type P.10
  • 11. Difference between constructor and method: Constructor Method Is used to initialize the state of an object Is used to expose behavior of an object Must not have return type Must have return type Is invoked implicitly Is invoked explicitly Compiler provides a default constructor if you don’t have any constructor Is not provided by compiler in any case Name must be same as the class name Name may or may not be same as class name P.11
  • 13. Access Modifier: The access modifiers specifies accessibility of a data member, method, constructor or class. There are 4 types of access modifiers : 1. private is accessible only within class 2. default when you don’t use any modifier, it is treated as default by default, is accessible only with package 3. protected is accessible within package and outside the package but through inheritance only it can’t be applied on the class 4. public accessible everywhere , it has the widest scope among all other modifiers P.13
  • 14. Example of Private Access Modifier: Student.java Main.java If you make any class constructor private, you cannot create the instance of that class from outside the class A class cannot be private or protected except nested class P.14
  • 15. Example of Default Access Modifier: A.java A class is not public, so it cannot be accessed from outside the package. B.java P.15
  • 16. Example of Protected Access Modifier: Student.java P.16 Main.java
  • 17. Example of Public Access Modifier : Student.java Main.java P.17
  • 18. Finally : Access Modifier Within class Within package Outside package by subclass only Outside package Private Yes No No No Default Yes Yes No No Protected Yes Yes Yes No Public Yes Yes Yes Yes P.18