SlideShare a Scribd company logo
Data Types and
Variables
What are DataTypes?
 Data-types means containers.
 They specify what kind of data to hold
 In java, there are two types of data types
 Primitive data types
 Non-primitive data types
Primitive Data Types
Non Primitive Data Types
 Strings
 Arrays
 Class
Variables
 Variable is name of reserved area allocated in memory.
 There are three types of variables in java
 local variable
 A variable that is declared inside the method is called local variable.
 instance variable
 A variable that is declared inside the class but outside the method is
called instance variable . It is not declared as static.
 static variable
 A variable that is declared as static is called static variable. It cannot
be local.
Variables
Syntax:
Datatype variable_name = value ;
Example
int id = 34;
float mks=67.34;
int int =45; //invalid
Literals
 Literals are numbers, characters, and string representations used
in a program.
 Numeric Literals
int roll_no=45;
 Character literals
char letter = ‘b';
letter = ‘S';
 String literals
String message = "HellotWorldn";
Casting is required when there is a need to explicitly convert a
value from one type to another.
The general syntax for a cast is:
Examples
Casting
(result_type) value;
float price = 37.53;
int dollars = (int) price; // fractional portion lost
// dollars = 37
char response = 'A';
byte temp =(byte) response; // temp = 65 (ASCII value
// for 'a')
Type Casting
 Assigning a value of one type to a variable of another
type is known as Type Casting.
 In Java, type casting is classified into two types,
 Widening Casting(Implicit)
 Narrowing Casting(Explicitly done)
A widening conversion occurs when a value stored in a
smaller space is converted to a type of a larger space.
There will never be a loss of information
Widening conversions occur automatically when needed.
Widening Conversions
A narrowing conversion occurs when a value stored in a larger
space is converted to a type of a smaller space.
Information may be lost
Never occurs automatically. Must be explicitly requested by
the programmer using a cast.
Narrowing Conversions
Strings
 String is a sequence of characters. In the Java programming
language, strings are objects. There are two types of String
i.e
 1. Mutable
 2.Immutable
 In java, string objects are immutable.
 Immutable simply means unmodifiable or unchangeable. It
is immutable because object reference is created.
String Formatting
StringBuffer Class
 Java StringBuffer class is used to created mutable
(modifiable) string. The StringBuffer class in java is same as
String class except it is mutable i.e. it can be changed.
class StringDemo{
public static void main(String args[]){
StringBuffer sb=new StringBuffer("Hello ");
sb.append("Java");//now original string is changed
System.out.println(sb);//prints Hello Java
}
}
StringBuilder Class
 Java StringBuilder class is used to create mutable (modifiable) string.
 The Java StringBuilder class is same as StringBuffer class except that it
is non-synchronized.
class A{
public static void main(String args[]){
StringBuilder sb=new StringBuilder("Hello ");
sb.append("Java");//now original string is changed
System.out.println(sb);//prints Hello Java
}
}
Difference between String and
StringBuffer
String
 String class is immutable
 String is slow and
consumes more memory
 String class overrides the
equals() method of
Object class.
StringBuffer
 StringBuffer class is
mutable
 StringBuffer is fast and
consumes less memory
 StringBuffer class doesn't
override the equals()
method of Object class
Difference between String and
StringBuffer conti..
StringBuffer
 StringBuffer
is synchronized
 StringBuffer is less
efficient than
StringBuilder.
StringBuilder
 StringBuilder is non-
synchronized
 StringBuilder is more
efficient than
StringBuffer.
Arrays
 An array is an ordered list of values
0 1 2 3 4 5 6 7 8 9
79 87 94 82 67 98 87 81 74 91
An array of size N is indexed from zero to N-1
rollno
The entire array
has a single name
Each value has a numeric index
This array holds 10 values that are indexed from 0 to 9
Array - Syntax
 A particular value in an array is referenced using the array
name followed by the index in brackets.
 Datatype [ ] variable_name = new datatype[size];
 Ex: int [] scores = new int [10];
 In JAVA, int is of 4 bytes, total space=4*10=40 bytes.
 Space Allocation is based on the datatype used to declare
array.
Types of Array
 Single Dimensional Array (1 D Array)
 Two Dimensional Array (2 D Array)
 Multidimensional Array(Arrays of Arrays)
Dot Operator
 Dot operator is used to access methods and variables
within classes.
 It is represented as . (dot)
Example
class Test
{
public int a;
public display()
{
System.out.println(“Hello”);
}
}
public static void main(String args[])
{
Test t=new Test();
t.a=32; //accessing dot
t.display(); //accessing display
}
}

More Related Content

What's hot

Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
Lovely Professional University
 
Java program structure
Java program structureJava program structure
Java program structure
shalinikarunakaran1
 
Data types in java
Data types in javaData types in java
Data types in java
HarshitaAshwani
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
VINOTH R
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
Arzath Areeff
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Pavith Gunasekara
 
Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variables
sasi saseenthiran
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
SURIT DATTA
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
Hitesh Kumar
 
Method overloading
Method overloadingMethod overloading
Method overloading
Lovely Professional University
 
Methods in java
Methods in javaMethods in java
Methods in java
chauhankapil
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Java string handling
Java string handlingJava string handling
Java string handling
Salman Khan
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
Farooq Baloch
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
Dhrumil Panchal
 
Generics in java
Generics in javaGenerics in java
Generics in java
suraj pandey
 

What's hot (20)

Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Java program structure
Java program structureJava program structure
Java program structure
 
Data types in java
Data types in javaData types in java
Data types in java
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Features of java
Features of javaFeatures of java
Features of java
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variables
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Methods in java
Methods in javaMethods in java
Methods in java
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Generics in java
Generics in javaGenerics in java
Generics in java
 

Similar to Data Types & Variables in JAVA

javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string class
fedcoordinator
 
Java Basics
Java BasicsJava Basics
Java - Basic Datatypes.pptx
Java - Basic Datatypes.pptxJava - Basic Datatypes.pptx
Java - Basic Datatypes.pptx
Nagaraju Pamarthi
 
Fileoperations.pptx
Fileoperations.pptxFileoperations.pptx
Fileoperations.pptx
VeenaNaik23
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
 
Java String
Java String Java String
Java String
SATYAM SHRIVASTAV
 
In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...
Indu32
 
Array.ppt
Array.pptArray.ppt
Array.ppt
SbsOmit1
 
array.ppt
array.pptarray.ppt
array.ppt
rajput0302
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
Madishetty Prathibha
 
Java unit 2
Java unit 2Java unit 2
Java unit 2
Shipra Swati
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIs
İbrahim Kürce
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Viyaan Jhiingade
 
Module 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdfModule 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdf
MegMeg17
 
JVM and OOPS Introduction
JVM and OOPS IntroductionJVM and OOPS Introduction
JVM and OOPS Introduction
SATYAM SHRIVASTAV
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
simarsimmygrewal
 
Learning core java
Learning core javaLearning core java
Learning core java
Abhay Bharti
 
JAVA_1.pptx
JAVA_1.pptxJAVA_1.pptx
Java
JavaJava

Similar to Data Types & Variables in JAVA (20)

javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string class
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java - Basic Datatypes.pptx
Java - Basic Datatypes.pptxJava - Basic Datatypes.pptx
Java - Basic Datatypes.pptx
 
Fileoperations.pptx
Fileoperations.pptxFileoperations.pptx
Fileoperations.pptx
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Java String
Java String Java String
Java String
 
In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...
 
Array.ppt
Array.pptArray.ppt
Array.ppt
 
array.ppt
array.pptarray.ppt
array.ppt
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
 
Java unit 2
Java unit 2Java unit 2
Java unit 2
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIs
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Java
JavaJava
Java
 
Module 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdfModule 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdf
 
JVM and OOPS Introduction
JVM and OOPS IntroductionJVM and OOPS Introduction
JVM and OOPS Introduction
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Learning core java
Learning core javaLearning core java
Learning core java
 
JAVA_1.pptx
JAVA_1.pptxJAVA_1.pptx
JAVA_1.pptx
 
Java
JavaJava
Java
 

Recently uploaded

block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 

Recently uploaded (20)

block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 

Data Types & Variables in JAVA

  • 2. What are DataTypes?  Data-types means containers.  They specify what kind of data to hold  In java, there are two types of data types  Primitive data types  Non-primitive data types
  • 4. Non Primitive Data Types  Strings  Arrays  Class
  • 5. Variables  Variable is name of reserved area allocated in memory.  There are three types of variables in java  local variable  A variable that is declared inside the method is called local variable.  instance variable  A variable that is declared inside the class but outside the method is called instance variable . It is not declared as static.  static variable  A variable that is declared as static is called static variable. It cannot be local.
  • 6. Variables Syntax: Datatype variable_name = value ; Example int id = 34; float mks=67.34; int int =45; //invalid
  • 7. Literals  Literals are numbers, characters, and string representations used in a program.  Numeric Literals int roll_no=45;  Character literals char letter = ‘b'; letter = ‘S';  String literals String message = "HellotWorldn";
  • 8. Casting is required when there is a need to explicitly convert a value from one type to another. The general syntax for a cast is: Examples Casting (result_type) value; float price = 37.53; int dollars = (int) price; // fractional portion lost // dollars = 37 char response = 'A'; byte temp =(byte) response; // temp = 65 (ASCII value // for 'a')
  • 9. Type Casting  Assigning a value of one type to a variable of another type is known as Type Casting.  In Java, type casting is classified into two types,  Widening Casting(Implicit)  Narrowing Casting(Explicitly done)
  • 10. A widening conversion occurs when a value stored in a smaller space is converted to a type of a larger space. There will never be a loss of information Widening conversions occur automatically when needed. Widening Conversions
  • 11. A narrowing conversion occurs when a value stored in a larger space is converted to a type of a smaller space. Information may be lost Never occurs automatically. Must be explicitly requested by the programmer using a cast. Narrowing Conversions
  • 12. Strings  String is a sequence of characters. In the Java programming language, strings are objects. There are two types of String i.e  1. Mutable  2.Immutable  In java, string objects are immutable.  Immutable simply means unmodifiable or unchangeable. It is immutable because object reference is created.
  • 14. StringBuffer Class  Java StringBuffer class is used to created mutable (modifiable) string. The StringBuffer class in java is same as String class except it is mutable i.e. it can be changed. class StringDemo{ public static void main(String args[]){ StringBuffer sb=new StringBuffer("Hello "); sb.append("Java");//now original string is changed System.out.println(sb);//prints Hello Java } }
  • 15. StringBuilder Class  Java StringBuilder class is used to create mutable (modifiable) string.  The Java StringBuilder class is same as StringBuffer class except that it is non-synchronized. class A{ public static void main(String args[]){ StringBuilder sb=new StringBuilder("Hello "); sb.append("Java");//now original string is changed System.out.println(sb);//prints Hello Java } }
  • 16. Difference between String and StringBuffer String  String class is immutable  String is slow and consumes more memory  String class overrides the equals() method of Object class. StringBuffer  StringBuffer class is mutable  StringBuffer is fast and consumes less memory  StringBuffer class doesn't override the equals() method of Object class
  • 17. Difference between String and StringBuffer conti.. StringBuffer  StringBuffer is synchronized  StringBuffer is less efficient than StringBuilder. StringBuilder  StringBuilder is non- synchronized  StringBuilder is more efficient than StringBuffer.
  • 18. Arrays  An array is an ordered list of values 0 1 2 3 4 5 6 7 8 9 79 87 94 82 67 98 87 81 74 91 An array of size N is indexed from zero to N-1 rollno The entire array has a single name Each value has a numeric index This array holds 10 values that are indexed from 0 to 9
  • 19. Array - Syntax  A particular value in an array is referenced using the array name followed by the index in brackets.  Datatype [ ] variable_name = new datatype[size];  Ex: int [] scores = new int [10];  In JAVA, int is of 4 bytes, total space=4*10=40 bytes.  Space Allocation is based on the datatype used to declare array.
  • 20. Types of Array  Single Dimensional Array (1 D Array)  Two Dimensional Array (2 D Array)  Multidimensional Array(Arrays of Arrays)
  • 21. Dot Operator  Dot operator is used to access methods and variables within classes.  It is represented as . (dot) Example class Test { public int a; public display() { System.out.println(“Hello”); } } public static void main(String args[]) { Test t=new Test(); t.a=32; //accessing dot t.display(); //accessing display } }