SlideShare a Scribd company logo
1 of 11
Java Variables & Class
Kadarkarai Selvam
❖ Container to hold value. Assigned with data type
❖ Reserved Area allocated in memory
Int x = 10;
RAM
Java Variable
Reserved place for
variable X to store
value
Java Example
public class SumofNumbers
{
public static void main(String args[])
{
int i = 20, j = 15, sum;
sum = i + j;
System.out.println("The sum of numbers is: "+sum);
}
}
I, J, sum are variables
which can hold value
and of type Integer
Java Primitive Data type
❖ Specifies the container size and characteristics to store the values
❖ Primitive Data type - Basic entity to store the data
❖ Primitive Data type includes
➢ Boolean
➢ Char
➢ Byte, Short, Int, Long
➢ Float & Double
Java Primitive Data type
Data Type Default value Default Size Example
boolean false 1 bit boolean a = false;
char 'u0000' 2 byte
'u0000' (or 0) to 'uffff' (or 65,535)
char c = 'c';
byte 0 1 byte (-128 to 127) byte num1=127;
short 0 2 byte (-32,768 to 32,767) short s = 10000;
int 0 4 byte (2,147,483,648 (-2^31) to
2,147,483,647 (2^31 -1))
int i = 100000;
long 0L 8 byte (-9,223,372,036,854,775,808(-
2^63) to 9,223,372,036,854,775,807(2^63 -
1))
long l = 100000L;
float 0.0f 4 byte (unlimited) float f1 = 234.5f;
double 0.0d 8 byte (unlimited) double d1 = 12.3
Java Non Primitive Data type
❖ Used to store a group of values
❖ These Data types are not Pre defined in JAVA
❖ Few Examples are
➢ Class
➢ Array
➢ String
➢ Interface
Object
❖ Object have
➢ State : data of an object
➢ Behaviour : functionally of an object
➢ Identity : unique id used by JVM
❖ Object is an instance of a class
❖ E.g., Xiaomi Redmi 10 is an Object which have
➢ Size : 6.5 Inches (state)
➢ Ram memory : 4GB and 6GB (state)
➢ Warp Charging (behaviour)
➢ Dual standby (behaviour)
Class
❖ Group of Object which have common properties
❖ Boilerplate or Template or Blueprint for objects to get created
State and Behaviour Xiaomi Redmi 10 ABC mobile model
Ram 6GB and 4GB 2GB
Size 6.5 inches 5 inches
Standby Dual standby Single Standby
GPU Mali-G52 MC2 -
Class Components
❖ Variable : Reserved Memory location to hold values
❖ Constructor
➢ Special method and Used to initialize an object.
➢ If Constructor is not declared, then Java compiler will create default constructor
❖ Methods
➢ Block of code where parameters can be passed.
➢ Only runs when it is called. These are called Functions
➢ It represents the Behavior of an object and it supports code reusability and Optimization
public class Phones {
int Ram;
float size;
String Name, GPU;
static String type = "Android";
Phones(String N, int R, float S, String G) {
Ram = R;
size = S;
Name = N;
GPU = G;
}
void knowmyphone() {
String sim = "Dual Sim";
System.out.println("Phone Name :"+Name);
System.out.println("Operating System :"+type);
System.out.println("Sim card slot :"+sim);
System.out.println("Size in inches : "+size);
System.out.println("Ram memory : "+Ram);
System.out.println("GPU value : "+GPU);
}
public static void main(String args[]) {
Phones p1 = new Phones("Redmi Note 10",6,6.5f,"");
p1.knowmyphone();
Phones p2 = new Phones("OnePlus 9
pro",12,6.7f,"Adreno 660");
p2.knowmyphone();
}
//Instance Variable
//Static Variable
//local Variable
Variable Type
❖ Local Variable : Only within a Method. Other methods or outside the
method doesn’t know about the variable
❖ Instance Variable : Inside the class but outside the method. It is instance
specific i.e., Different Objects have Different values if it is not declared
❖ Static Variable : Single copy of variable. Memory is allocated when the
class is loaded. i.e, same value for all objects.

More Related Content

What's hot

An Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in JavaAn Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in JavaAbhishek Asthana
 
Debugging Your Production JVM
Debugging Your Production JVMDebugging Your Production JVM
Debugging Your Production JVMkensipe
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingLubomir Rintel
 
Introduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actorsIntroduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actorsShashank L
 
Java bytecode and classes
Java bytecode and classesJava bytecode and classes
Java bytecode and classesyoavwix
 
15 darwino script & command line
15   darwino script & command line15   darwino script & command line
15 darwino script & command linedarwinodb
 
Experiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the DatabaseExperiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the DatabaseMarcelo Ochoa
 
Type safe, versioned, and rewindable stream processing with Apache {Avro, K...
Type safe, versioned, and rewindable stream processing  with  Apache {Avro, K...Type safe, versioned, and rewindable stream processing  with  Apache {Avro, K...
Type safe, versioned, and rewindable stream processing with Apache {Avro, K...Hisham Mardam-Bey
 
Scala the-good-parts
Scala the-good-partsScala the-good-parts
Scala the-good-partsFuqiang Wang
 
An Intro to Scala for PHP Developers
An Intro to Scala for PHP DevelopersAn Intro to Scala for PHP Developers
An Intro to Scala for PHP DevelopersHuffPost Code
 
Javaforum looking into the memory
Javaforum   looking into the memoryJavaforum   looking into the memory
Javaforum looking into the memorySqueed
 
Continuations in scala (incomplete version)
Continuations in scala (incomplete version)Continuations in scala (incomplete version)
Continuations in scala (incomplete version)Fuqiang Wang
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machineLaxman Puri
 
Hp java heap dump analysis Workshop
Hp java heap dump analysis WorkshopHp java heap dump analysis Workshop
Hp java heap dump analysis WorkshopMadhavan Marimuthu
 

What's hot (20)

An Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in JavaAn Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in Java
 
JAVA CLASS1
JAVA CLASS1JAVA CLASS1
JAVA CLASS1
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Debugging Your Production JVM
Debugging Your Production JVMDebugging Your Production JVM
Debugging Your Production JVM
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profiling
 
JAVA BYTE CODE
JAVA BYTE CODEJAVA BYTE CODE
JAVA BYTE CODE
 
Dynamic Proxy by Java
Dynamic Proxy by JavaDynamic Proxy by Java
Dynamic Proxy by Java
 
Introduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actorsIntroduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actors
 
Java bytecode and classes
Java bytecode and classesJava bytecode and classes
Java bytecode and classes
 
15 darwino script & command line
15   darwino script & command line15   darwino script & command line
15 darwino script & command line
 
Experiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the DatabaseExperiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the Database
 
Type safe, versioned, and rewindable stream processing with Apache {Avro, K...
Type safe, versioned, and rewindable stream processing  with  Apache {Avro, K...Type safe, versioned, and rewindable stream processing  with  Apache {Avro, K...
Type safe, versioned, and rewindable stream processing with Apache {Avro, K...
 
JavaOne 2011 Recap
JavaOne 2011 RecapJavaOne 2011 Recap
JavaOne 2011 Recap
 
Java ce241
Java ce241Java ce241
Java ce241
 
Scala the-good-parts
Scala the-good-partsScala the-good-parts
Scala the-good-parts
 
An Intro to Scala for PHP Developers
An Intro to Scala for PHP DevelopersAn Intro to Scala for PHP Developers
An Intro to Scala for PHP Developers
 
Javaforum looking into the memory
Javaforum   looking into the memoryJavaforum   looking into the memory
Javaforum looking into the memory
 
Continuations in scala (incomplete version)
Continuations in scala (incomplete version)Continuations in scala (incomplete version)
Continuations in scala (incomplete version)
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machine
 
Hp java heap dump analysis Workshop
Hp java heap dump analysis WorkshopHp java heap dump analysis Workshop
Hp java heap dump analysis Workshop
 

Similar to Java variables and classes

Similar to Java variables and classes (20)

Computational Problem Solving 016 (1).pptx
Computational Problem Solving 016 (1).pptxComputational Problem Solving 016 (1).pptx
Computational Problem Solving 016 (1).pptx
 
Java Intro
Java IntroJava Intro
Java Intro
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topics
 
Java PSkills-session2.pptx
Java PSkills-session2.pptxJava PSkills-session2.pptx
Java PSkills-session2.pptx
 
C++ theory
C++ theoryC++ theory
C++ theory
 
C language basics
C language basicsC language basics
C language basics
 
Computational Problem Solving 004 (1).pptx (1).pdf
Computational Problem Solving 004 (1).pptx (1).pdfComputational Problem Solving 004 (1).pptx (1).pdf
Computational Problem Solving 004 (1).pptx (1).pdf
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptx
 
Unit 1
Unit 1Unit 1
Unit 1
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
 
02 data types in java
02 data types in java02 data types in java
02 data types in java
 
Class 8 - Java.pptx
Class 8 - Java.pptxClass 8 - Java.pptx
Class 8 - Java.pptx
 
RealmDB for Android
RealmDB for AndroidRealmDB for Android
RealmDB for Android
 
Java OOP Concepts 1st Slide
Java OOP Concepts 1st SlideJava OOP Concepts 1st Slide
Java OOP Concepts 1st Slide
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
 
Variables and Data Types
Variables and Data TypesVariables and Data Types
Variables and Data Types
 
Core java
Core javaCore java
Core java
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
 

More from KadarkaraiSelvam (11)

Selenium web driver useful commands
Selenium web driver useful commandsSelenium web driver useful commands
Selenium web driver useful commands
 
Java 2
Java 2Java 2
Java 2
 
Java 1
Java 1Java 1
Java 1
 
Java selenium web driver
Java selenium web driverJava selenium web driver
Java selenium web driver
 
Selenium inputs
Selenium inputsSelenium inputs
Selenium inputs
 
Selenium TestNG
Selenium TestNGSelenium TestNG
Selenium TestNG
 
Maven and versioning
Maven and versioningMaven and versioning
Maven and versioning
 
Java Inheritance and Polymorphism
Java Inheritance and PolymorphismJava Inheritance and Polymorphism
Java Inheritance and Polymorphism
 
Java Control Statements
Java Control StatementsJava Control Statements
Java Control Statements
 
Java JVM
Java JVMJava JVM
Java JVM
 
Selenium ide 1
Selenium ide 1Selenium ide 1
Selenium ide 1
 

Recently uploaded

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Recently uploaded (20)

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

Java variables and classes

  • 1. Java Variables & Class Kadarkarai Selvam
  • 2. ❖ Container to hold value. Assigned with data type ❖ Reserved Area allocated in memory Int x = 10; RAM Java Variable Reserved place for variable X to store value
  • 3. Java Example public class SumofNumbers { public static void main(String args[]) { int i = 20, j = 15, sum; sum = i + j; System.out.println("The sum of numbers is: "+sum); } } I, J, sum are variables which can hold value and of type Integer
  • 4. Java Primitive Data type ❖ Specifies the container size and characteristics to store the values ❖ Primitive Data type - Basic entity to store the data ❖ Primitive Data type includes ➢ Boolean ➢ Char ➢ Byte, Short, Int, Long ➢ Float & Double
  • 5. Java Primitive Data type Data Type Default value Default Size Example boolean false 1 bit boolean a = false; char 'u0000' 2 byte 'u0000' (or 0) to 'uffff' (or 65,535) char c = 'c'; byte 0 1 byte (-128 to 127) byte num1=127; short 0 2 byte (-32,768 to 32,767) short s = 10000; int 0 4 byte (2,147,483,648 (-2^31) to 2,147,483,647 (2^31 -1)) int i = 100000; long 0L 8 byte (-9,223,372,036,854,775,808(- 2^63) to 9,223,372,036,854,775,807(2^63 - 1)) long l = 100000L; float 0.0f 4 byte (unlimited) float f1 = 234.5f; double 0.0d 8 byte (unlimited) double d1 = 12.3
  • 6. Java Non Primitive Data type ❖ Used to store a group of values ❖ These Data types are not Pre defined in JAVA ❖ Few Examples are ➢ Class ➢ Array ➢ String ➢ Interface
  • 7. Object ❖ Object have ➢ State : data of an object ➢ Behaviour : functionally of an object ➢ Identity : unique id used by JVM ❖ Object is an instance of a class ❖ E.g., Xiaomi Redmi 10 is an Object which have ➢ Size : 6.5 Inches (state) ➢ Ram memory : 4GB and 6GB (state) ➢ Warp Charging (behaviour) ➢ Dual standby (behaviour)
  • 8. Class ❖ Group of Object which have common properties ❖ Boilerplate or Template or Blueprint for objects to get created State and Behaviour Xiaomi Redmi 10 ABC mobile model Ram 6GB and 4GB 2GB Size 6.5 inches 5 inches Standby Dual standby Single Standby GPU Mali-G52 MC2 -
  • 9. Class Components ❖ Variable : Reserved Memory location to hold values ❖ Constructor ➢ Special method and Used to initialize an object. ➢ If Constructor is not declared, then Java compiler will create default constructor ❖ Methods ➢ Block of code where parameters can be passed. ➢ Only runs when it is called. These are called Functions ➢ It represents the Behavior of an object and it supports code reusability and Optimization
  • 10. public class Phones { int Ram; float size; String Name, GPU; static String type = "Android"; Phones(String N, int R, float S, String G) { Ram = R; size = S; Name = N; GPU = G; } void knowmyphone() { String sim = "Dual Sim"; System.out.println("Phone Name :"+Name); System.out.println("Operating System :"+type); System.out.println("Sim card slot :"+sim); System.out.println("Size in inches : "+size); System.out.println("Ram memory : "+Ram); System.out.println("GPU value : "+GPU); } public static void main(String args[]) { Phones p1 = new Phones("Redmi Note 10",6,6.5f,""); p1.knowmyphone(); Phones p2 = new Phones("OnePlus 9 pro",12,6.7f,"Adreno 660"); p2.knowmyphone(); } //Instance Variable //Static Variable //local Variable
  • 11. Variable Type ❖ Local Variable : Only within a Method. Other methods or outside the method doesn’t know about the variable ❖ Instance Variable : Inside the class but outside the method. It is instance specific i.e., Different Objects have Different values if it is not declared ❖ Static Variable : Single copy of variable. Memory is allocated when the class is loaded. i.e, same value for all objects.

Editor's Notes

  1. Two data type - Primitive and Non Primitive.
  2. Byte - handle the stream of data from a network or file Short - to save memory as int is the default data type for numbers Float - If you want to save memory use float instead of double Float and double data types should never be used for precise values such as currency
  3. Classes and Objects are basic components of Object Oriented programming Object is the physical and logical entity whereas class is an logical entity only I.e, Object is a real world entity
  4. A constructor must be the same name of a Java class. It does not have a return type.