SlideShare a Scribd company logo
Introduction to Class

Object-Oriented Programming
Module Introduction

1.

Classes and Objects

2.

Instance variables

3.

Methods

FPT- APTECH

2/28
#1 – Classes and Objects



Class declaration



Constructors



Creating objects

FPT- APTECH

3/28
Creating Class



The template or blueprint from which
objects are actually made.



Syntax:
class ClassName{
//definition of class
}



All code that you write in Java is inside a
class.



Classes can be built by extending other
classes
FPT- APTECH

4/28
Constructor - how to instance an object?



Same name as the class.



A class can have more than one constructor.



A constructor can take zero, one, or more parameters.



Has no return value.



Always called with the new operator.



Use for initializing variables and invoking any methods that
may be for initialization.



If a class does not have an explicit constructor, a default
constructor (no-argument) is provided.
FPT- APTECH

5/28
Dissecting the Rectangle class
Name of class
1. Use Naming rules

Data member

2. Always captain first letter

• WhatConstructor
data does it need to
3. Use Noun for naming
know?
•

Define the way to
instance object

1. Same name as the
class name
Methods
2. Like function in C but
• Whathave no do? value
can it return
1. Like function in C
2. Use Verb for naming
3. Always lower first letter
FPT- APTECH

6/28
Creating objects (instance object)



An object must be created before using in a program.

1.

Declare a variable to store the object reference.
1.
Objects can only be manipulated via references

2.

Creating an object.
1.
Using the new operator in conjunction with a call to a constructor

FPT- APTECH

7/28
#2 – Data Member



Instance Variables



Class Variables

FPT- APTECH

8/28
Instance variables



The values of those variables
define the state of object.



All instances of a class have
the same instance variables
 May have different values
inside them.



Has an “access modifier”
associated with it.

FPT- APTECH

9/28
Example of Instance variables

recA
length = 3.0
width = 4.0

FPT- APTECH

recB
length = 6.4
width = 4.7

10/28
Class Variables (Static Variables)



Variable that is accessed
without using an object of a
class.



Declare using the static
keyword.



Only one copy of a static
variable is shared by all the
objects of the class.
 Change in the value of static
variable is reflected by all the
objects of the class.
FPT- APTECH

11/28
Example of Static Variables

FPT- APTECH

12/28
#3 - Methods



Definition



Instance Method



Calling method and Passing Arguments by Value.



Calling method and Passing Arguments by Reference.



Static Methods



Variable Argument Methods

FPT- APTECH

13/28
Method



A method is defined as the actual implementation of an operation
on an object.



Syntax:

access_specifier modifier datatype
method_name (parameter_list)
{
//body of the method
}


The method name should begin with
a lowercase verb and follow with
a proper noun.

FPT- APTECH

14/28
Instance Method



A function defined in a class



Invoked by an instance object
and can access instance
variables



Provide a mechanism for
accessing the private data
stored in an object

FPT- APTECH

15/28
Invoking Methods



Using the '.' operator



Syntax:
 <the object reference> ‘.’ <the method to be invoked>

FPT- APTECH

16/28
Calling method and Passing Arguments by Value.



Value from calling method is passed as an argument to the
called method.



Any change made to that passed value in the called method
will not modify the value in the calling method.



Variables of primitive types (int, float ..) are passed by value.

FPT- APTECH

17/28
Example of Calling method and Passing Arguments by
Value.

FPT- APTECH

18/28
Calling method and Passing Arguments by Reference.



Called method to change the value of the parameter passed
to if from the calling method.



When references are passed as parameters, the caller can
change the values stored but not the reference variables.

FPT- APTECH

19/28
Example of Calling method and Passing Arguments by
Reference

FPT- APTECH

20/28
Static Methods



Methods that do not operate on objects.
 Can be called without creating any objects of the class.



Call static method, supply the name of the class.



Declared using the static keyword.



Can directly refer only to static variables and other static
methods of the class.



Cannot refer to non-static methods and variables

FPT- APTECH

21/28
Example of Static Methods

FPT- APTECH

22/28
static methods usage



When a method doesn't need to access the object state



When a method only needs to access static fields of the
class.

FPT- APTECH

23/28
Variable Argument Methods



Allow calling a method with variable number of arguments.

FPT- APTECH

24/28
That’s about all for today!


Classes and Objects



Instance variables



Methods

Thank you all for your attention and patient !

More Related Content

What's hot

Lecture02 java
Lecture02 javaLecture02 java
Lecture02 java
jawidAhmadRohani
 
Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2
Jamshid Hashimi
 
Java interfaces
Java   interfacesJava   interfaces
Java interfaces
Elizabeth alexander
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
talha ijaz
 
Java Generics
Java GenericsJava Generics
Java Generics
DeeptiJava
 
Ppt chapter06
Ppt chapter06Ppt chapter06
Ppt chapter06
Richard Styner
 
Java Chapter 04 - Writing Classes: part 1
Java Chapter 04 - Writing Classes: part 1Java Chapter 04 - Writing Classes: part 1
Java Chapter 04 - Writing Classes: part 1
DanWooster1
 
Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Adi Bolboaca
 
Ppt chapter11
Ppt chapter11Ppt chapter11
Ppt chapter11
Richard Styner
 
9781439035665 ppt ch07
9781439035665 ppt ch079781439035665 ppt ch07
9781439035665 ppt ch07Terry Yoast
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
Finite state system or finite automata
Finite state system or finite automataFinite state system or finite automata
Finite state system or finite automata
Dr. ABHISHEK K PANDEY
 
Comparable vs comparator
Comparable vs comparatorComparable vs comparator
Comparable vs comparatorDigvijayKale9
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statements
İbrahim Kürce
 
Ppt chapter03
Ppt chapter03Ppt chapter03
Ppt chapter03
Richard Styner
 
Ppt chapter05
Ppt chapter05Ppt chapter05
Ppt chapter05
Richard Styner
 

What's hot (20)

Lecture02 java
Lecture02 javaLecture02 java
Lecture02 java
 
Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2
 
Java interfaces
Java   interfacesJava   interfaces
Java interfaces
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Ppt chapter06
Ppt chapter06Ppt chapter06
Ppt chapter06
 
Generics
GenericsGenerics
Generics
 
Java Chapter 04 - Writing Classes: part 1
Java Chapter 04 - Writing Classes: part 1Java Chapter 04 - Writing Classes: part 1
Java Chapter 04 - Writing Classes: part 1
 
Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16
 
Ppt chapter11
Ppt chapter11Ppt chapter11
Ppt chapter11
 
My c++
My c++My c++
My c++
 
14 interface
14  interface14  interface
14 interface
 
9781439035665 ppt ch07
9781439035665 ppt ch079781439035665 ppt ch07
9781439035665 ppt ch07
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Finite state system or finite automata
Finite state system or finite automataFinite state system or finite automata
Finite state system or finite automata
 
Comparable vs comparator
Comparable vs comparatorComparable vs comparator
Comparable vs comparator
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statements
 
Ppt chapter03
Ppt chapter03Ppt chapter03
Ppt chapter03
 
17515
1751517515
17515
 
Ppt chapter05
Ppt chapter05Ppt chapter05
Ppt chapter05
 

Viewers also liked

Git - Boost Your DEV Team Speed and Productivity
Git - Boost Your DEV Team Speed and ProductivityGit - Boost Your DEV Team Speed and Productivity
Git - Boost Your DEV Team Speed and Productivity
KMS Technology
 
Exadata - Smart Scan Testing
Exadata - Smart Scan TestingExadata - Smart Scan Testing
Exadata - Smart Scan TestingMonowar Mukul
 
Edtc6341 63 esther_sauceda_practice_test5
Edtc6341 63 esther_sauceda_practice_test5Edtc6341 63 esther_sauceda_practice_test5
Edtc6341 63 esther_sauceda_practice_test5esauceda12
 
Exadata Cell metrics
Exadata Cell metricsExadata Cell metrics
Exadata Cell metrics
Monowar Mukul
 
Upgrade database using cloud_control Provisioning
Upgrade database using cloud_control Provisioning Upgrade database using cloud_control Provisioning
Upgrade database using cloud_control Provisioning
Monowar Mukul
 
SOA Fusion Middleware installation
SOA Fusion Middleware installationSOA Fusion Middleware installation
SOA Fusion Middleware installation
Monowar Mukul
 
Moving 12c database from NON-ASM to ASM
Moving 12c database from NON-ASM to ASMMoving 12c database from NON-ASM to ASM
Moving 12c database from NON-ASM to ASM
Monowar Mukul
 
Exadata I/O Resource Manager (Exadata IORM)
Exadata I/O Resource Manager (Exadata IORM)Exadata I/O Resource Manager (Exadata IORM)
Exadata I/O Resource Manager (Exadata IORM)
Monowar Mukul
 
Oracle 12c far sync standby instance
Oracle 12c far sync standby instanceOracle 12c far sync standby instance
Oracle 12c far sync standby instanceMonowar Mukul
 
Oracle 12c RAC (Advanced installation - Flex ASM)
Oracle 12c RAC (Advanced installation - Flex ASM)Oracle 12c RAC (Advanced installation - Flex ASM)
Oracle 12c RAC (Advanced installation - Flex ASM)Monowar Mukul
 
12c database migration from ASM storage to NON-ASM storage
12c database migration from ASM storage to NON-ASM storage12c database migration from ASM storage to NON-ASM storage
12c database migration from ASM storage to NON-ASM storage
Monowar Mukul
 
TimesTen in memory database Creation
TimesTen in memory database Creation TimesTen in memory database Creation
TimesTen in memory database Creation
Monowar Mukul
 
12c Flex ASM: Moving to Flex ASM
12c Flex ASM: Moving to Flex ASM12c Flex ASM: Moving to Flex ASM
12c Flex ASM: Moving to Flex ASM
Monowar Mukul
 
12c: Testing audit features for Data Pump (Export & Import) and RMAN jobs
12c: Testing audit features for Data Pump (Export & Import) and RMAN jobs12c: Testing audit features for Data Pump (Export & Import) and RMAN jobs
12c: Testing audit features for Data Pump (Export & Import) and RMAN jobsMonowar Mukul
 
Advanced installation 12c rac
Advanced installation 12c racAdvanced installation 12c rac
Advanced installation 12c racMonowar Mukul
 
Copyright Crash Course 1st revised ppt 6340.64 Sonia Aldape
Copyright Crash Course 1st revised ppt 6340.64 Sonia AldapeCopyright Crash Course 1st revised ppt 6340.64 Sonia Aldape
Copyright Crash Course 1st revised ppt 6340.64 Sonia Aldapesoniaaldape
 
Exadata - BULK DATA LOAD Testing on Database Machine
Exadata - BULK DATA LOAD Testing on Database Machine Exadata - BULK DATA LOAD Testing on Database Machine
Exadata - BULK DATA LOAD Testing on Database Machine
Monowar Mukul
 
Migration Database from SQL SERVER 2012 to Oracle12c with Pluggable Database
Migration Database from SQL SERVER 2012 to Oracle12c with Pluggable Database  Migration Database from SQL SERVER 2012 to Oracle12c with Pluggable Database
Migration Database from SQL SERVER 2012 to Oracle12c with Pluggable Database
Monowar Mukul
 
Oracle EM12c Edit or Create Incident rules and Setup SMS alert
Oracle EM12c Edit or Create Incident rules and Setup SMS alertOracle EM12c Edit or Create Incident rules and Setup SMS alert
Oracle EM12c Edit or Create Incident rules and Setup SMS alert
Monowar Mukul
 

Viewers also liked (20)

Git - Boost Your DEV Team Speed and Productivity
Git - Boost Your DEV Team Speed and ProductivityGit - Boost Your DEV Team Speed and Productivity
Git - Boost Your DEV Team Speed and Productivity
 
1247g3hg1238 2011
1247g3hg1238 20111247g3hg1238 2011
1247g3hg1238 2011
 
Exadata - Smart Scan Testing
Exadata - Smart Scan TestingExadata - Smart Scan Testing
Exadata - Smart Scan Testing
 
Edtc6341 63 esther_sauceda_practice_test5
Edtc6341 63 esther_sauceda_practice_test5Edtc6341 63 esther_sauceda_practice_test5
Edtc6341 63 esther_sauceda_practice_test5
 
Exadata Cell metrics
Exadata Cell metricsExadata Cell metrics
Exadata Cell metrics
 
Upgrade database using cloud_control Provisioning
Upgrade database using cloud_control Provisioning Upgrade database using cloud_control Provisioning
Upgrade database using cloud_control Provisioning
 
SOA Fusion Middleware installation
SOA Fusion Middleware installationSOA Fusion Middleware installation
SOA Fusion Middleware installation
 
Moving 12c database from NON-ASM to ASM
Moving 12c database from NON-ASM to ASMMoving 12c database from NON-ASM to ASM
Moving 12c database from NON-ASM to ASM
 
Exadata I/O Resource Manager (Exadata IORM)
Exadata I/O Resource Manager (Exadata IORM)Exadata I/O Resource Manager (Exadata IORM)
Exadata I/O Resource Manager (Exadata IORM)
 
Oracle 12c far sync standby instance
Oracle 12c far sync standby instanceOracle 12c far sync standby instance
Oracle 12c far sync standby instance
 
Oracle 12c RAC (Advanced installation - Flex ASM)
Oracle 12c RAC (Advanced installation - Flex ASM)Oracle 12c RAC (Advanced installation - Flex ASM)
Oracle 12c RAC (Advanced installation - Flex ASM)
 
12c database migration from ASM storage to NON-ASM storage
12c database migration from ASM storage to NON-ASM storage12c database migration from ASM storage to NON-ASM storage
12c database migration from ASM storage to NON-ASM storage
 
TimesTen in memory database Creation
TimesTen in memory database Creation TimesTen in memory database Creation
TimesTen in memory database Creation
 
12c Flex ASM: Moving to Flex ASM
12c Flex ASM: Moving to Flex ASM12c Flex ASM: Moving to Flex ASM
12c Flex ASM: Moving to Flex ASM
 
12c: Testing audit features for Data Pump (Export & Import) and RMAN jobs
12c: Testing audit features for Data Pump (Export & Import) and RMAN jobs12c: Testing audit features for Data Pump (Export & Import) and RMAN jobs
12c: Testing audit features for Data Pump (Export & Import) and RMAN jobs
 
Advanced installation 12c rac
Advanced installation 12c racAdvanced installation 12c rac
Advanced installation 12c rac
 
Copyright Crash Course 1st revised ppt 6340.64 Sonia Aldape
Copyright Crash Course 1st revised ppt 6340.64 Sonia AldapeCopyright Crash Course 1st revised ppt 6340.64 Sonia Aldape
Copyright Crash Course 1st revised ppt 6340.64 Sonia Aldape
 
Exadata - BULK DATA LOAD Testing on Database Machine
Exadata - BULK DATA LOAD Testing on Database Machine Exadata - BULK DATA LOAD Testing on Database Machine
Exadata - BULK DATA LOAD Testing on Database Machine
 
Migration Database from SQL SERVER 2012 to Oracle12c with Pluggable Database
Migration Database from SQL SERVER 2012 to Oracle12c with Pluggable Database  Migration Database from SQL SERVER 2012 to Oracle12c with Pluggable Database
Migration Database from SQL SERVER 2012 to Oracle12c with Pluggable Database
 
Oracle EM12c Edit or Create Incident rules and Setup SMS alert
Oracle EM12c Edit or Create Incident rules and Setup SMS alertOracle EM12c Edit or Create Incident rules and Setup SMS alert
Oracle EM12c Edit or Create Incident rules and Setup SMS alert
 

Similar to 4. java intro class

Java defining classes
Java defining classes Java defining classes
Java defining classes
Mehdi Ali Soltani
 
Java Basics
Java BasicsJava Basics
Java Basics
Emprovise
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part II
Eduardo Bergavera
 
Java As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & AppletsJava As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & Applets
Helen SagayaRaj
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7Vince Vo
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
SakkaravarthiS1
 
9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08Terry Yoast
 
JAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptx
JAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptxJAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptx
JAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptx
JohnMarkDeJesus4
 
SOEN6441.genericsSOEN6441.genericsSOEN6441.generics
SOEN6441.genericsSOEN6441.genericsSOEN6441.genericsSOEN6441.genericsSOEN6441.genericsSOEN6441.generics
SOEN6441.genericsSOEN6441.genericsSOEN6441.generics
tahircs1
 
SOEN6441.generics.ppt
SOEN6441.generics.pptSOEN6441.generics.ppt
SOEN6441.generics.ppt
ElieMambou1
 
Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1
bharath yelugula
 
L5
L5L5
L5
lksoo
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
chap 6 : Objects and classes (scjp/ocjp)
chap 6 : Objects and classes (scjp/ocjp)chap 6 : Objects and classes (scjp/ocjp)
chap 6 : Objects and classes (scjp/ocjp)
It Academy
 
Effective Java - Design Method Signature Overload Varargs
Effective Java - Design Method Signature Overload VarargsEffective Java - Design Method Signature Overload Varargs
Effective Java - Design Method Signature Overload Varargs
Roshan Deniyage
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 

Similar to 4. java intro class (20)

Hemajava
HemajavaHemajava
Hemajava
 
Java defining classes
Java defining classes Java defining classes
Java defining classes
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part II
 
Java As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & AppletsJava As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & Applets
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
 
9781439035665 ppt ch08
9781439035665 ppt ch089781439035665 ppt ch08
9781439035665 ppt ch08
 
JAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptx
JAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptxJAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptx
JAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptx
 
SOEN6441.genericsSOEN6441.genericsSOEN6441.generics
SOEN6441.genericsSOEN6441.genericsSOEN6441.genericsSOEN6441.genericsSOEN6441.genericsSOEN6441.generics
SOEN6441.genericsSOEN6441.genericsSOEN6441.generics
 
SOEN6441.generics.ppt
SOEN6441.generics.pptSOEN6441.generics.ppt
SOEN6441.generics.ppt
 
Objects and Types C#
Objects and Types C#Objects and Types C#
Objects and Types C#
 
Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1Objectorientedprogrammingmodel1
Objectorientedprogrammingmodel1
 
L5
L5L5
L5
 
Classes2
Classes2Classes2
Classes2
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
chap 6 : Objects and classes (scjp/ocjp)
chap 6 : Objects and classes (scjp/ocjp)chap 6 : Objects and classes (scjp/ocjp)
chap 6 : Objects and classes (scjp/ocjp)
 
Effective Java - Design Method Signature Overload Varargs
Effective Java - Design Method Signature Overload VarargsEffective Java - Design Method Signature Overload Varargs
Effective Java - Design Method Signature Overload Varargs
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 

Recently uploaded

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 

4. java intro class

  • 2. Module Introduction 1. Classes and Objects 2. Instance variables 3. Methods FPT- APTECH 2/28
  • 3. #1 – Classes and Objects  Class declaration  Constructors  Creating objects FPT- APTECH 3/28
  • 4. Creating Class  The template or blueprint from which objects are actually made.  Syntax: class ClassName{ //definition of class }  All code that you write in Java is inside a class.  Classes can be built by extending other classes FPT- APTECH 4/28
  • 5. Constructor - how to instance an object?  Same name as the class.  A class can have more than one constructor.  A constructor can take zero, one, or more parameters.  Has no return value.  Always called with the new operator.  Use for initializing variables and invoking any methods that may be for initialization.  If a class does not have an explicit constructor, a default constructor (no-argument) is provided. FPT- APTECH 5/28
  • 6. Dissecting the Rectangle class Name of class 1. Use Naming rules Data member 2. Always captain first letter • WhatConstructor data does it need to 3. Use Noun for naming know? • Define the way to instance object 1. Same name as the class name Methods 2. Like function in C but • Whathave no do? value can it return 1. Like function in C 2. Use Verb for naming 3. Always lower first letter FPT- APTECH 6/28
  • 7. Creating objects (instance object)  An object must be created before using in a program. 1. Declare a variable to store the object reference. 1. Objects can only be manipulated via references 2. Creating an object. 1. Using the new operator in conjunction with a call to a constructor FPT- APTECH 7/28
  • 8. #2 – Data Member  Instance Variables  Class Variables FPT- APTECH 8/28
  • 9. Instance variables  The values of those variables define the state of object.  All instances of a class have the same instance variables  May have different values inside them.  Has an “access modifier” associated with it. FPT- APTECH 9/28
  • 10. Example of Instance variables recA length = 3.0 width = 4.0 FPT- APTECH recB length = 6.4 width = 4.7 10/28
  • 11. Class Variables (Static Variables)  Variable that is accessed without using an object of a class.  Declare using the static keyword.  Only one copy of a static variable is shared by all the objects of the class.  Change in the value of static variable is reflected by all the objects of the class. FPT- APTECH 11/28
  • 12. Example of Static Variables FPT- APTECH 12/28
  • 13. #3 - Methods  Definition  Instance Method  Calling method and Passing Arguments by Value.  Calling method and Passing Arguments by Reference.  Static Methods  Variable Argument Methods FPT- APTECH 13/28
  • 14. Method  A method is defined as the actual implementation of an operation on an object.  Syntax: access_specifier modifier datatype method_name (parameter_list) { //body of the method }  The method name should begin with a lowercase verb and follow with a proper noun. FPT- APTECH 14/28
  • 15. Instance Method  A function defined in a class  Invoked by an instance object and can access instance variables  Provide a mechanism for accessing the private data stored in an object FPT- APTECH 15/28
  • 16. Invoking Methods  Using the '.' operator  Syntax:  <the object reference> ‘.’ <the method to be invoked> FPT- APTECH 16/28
  • 17. Calling method and Passing Arguments by Value.  Value from calling method is passed as an argument to the called method.  Any change made to that passed value in the called method will not modify the value in the calling method.  Variables of primitive types (int, float ..) are passed by value. FPT- APTECH 17/28
  • 18. Example of Calling method and Passing Arguments by Value. FPT- APTECH 18/28
  • 19. Calling method and Passing Arguments by Reference.  Called method to change the value of the parameter passed to if from the calling method.  When references are passed as parameters, the caller can change the values stored but not the reference variables. FPT- APTECH 19/28
  • 20. Example of Calling method and Passing Arguments by Reference FPT- APTECH 20/28
  • 21. Static Methods  Methods that do not operate on objects.  Can be called without creating any objects of the class.  Call static method, supply the name of the class.  Declared using the static keyword.  Can directly refer only to static variables and other static methods of the class.  Cannot refer to non-static methods and variables FPT- APTECH 21/28
  • 22. Example of Static Methods FPT- APTECH 22/28
  • 23. static methods usage  When a method doesn't need to access the object state  When a method only needs to access static fields of the class. FPT- APTECH 23/28
  • 24. Variable Argument Methods  Allow calling a method with variable number of arguments. FPT- APTECH 24/28
  • 25. That’s about all for today!  Classes and Objects  Instance variables  Methods Thank you all for your attention and patient !