SlideShare a Scribd company logo
Java Data Types
Features
• There are total 9 Data Types
• Java is a Strongly Typed Language
• No conversion !!!
• This makes it more secure and robust
• Type Compatibility Checking
Strongly Typed
• Every variable has a type
• Every expression is a type
• All assignments are checked for type
• All parameters passing are checked for type
• No confusing conversions
• All type mismatches are error
• Types
boolean either true of false
char16 bit Unicode 1.1
byte8-bit integer (signed)
short 16-bit integer (signed)
int 32-bit integer (signed)
long64-bit integer (singed)
float32-bit floating point (IEEE 754-1985)
double 64-bit floating point (IEEE 754-1985)
String (class for manipulating strings)
Ctegories
Can be classified in four Categories:
• Integers
• Floating Point
• Characters
• Boolean
(They are simple data types not objects) !!!!
Integers
Integers : Width , Usage
• byte : 8 bit , used for stream of data from network and files
• short : 16 bit , rarely used , for 16 bit computers (oudated)
• int : 32 bit, generally used
• long : 64 bit, when integer is not sufficient
In java size does not vary on platform. Though the actual size
taken in memory depends on JVM.
All are signed integers; there are no unsigned integers in java.
Width represents the behaviour , not the amount of space in
memory
Floating Point
Floating Point :
• float : 32 bit
• double : 64 bit
Float
• Single Precision
• Uses 32 bits
• Sometimes faster
• Used when not much accuracy required
Double
• Double Precision
• Uses 64 bits
• Faster on modern processors
• Used in all mathematical calculations
• More Accurate
Characters
Characters:
• char : 16 bit
• Unicode : Contains all characters of all human languages
• No negative characters
• Range 0 to 65,536
• ASCII code is from 0 to 127 which is same for Unicode
till 127.
• ++ /--/+/- operators possible
Boolean
• boolean either true or false
• Not 0 or 1
• Output of all relational and logical operators
Data Type Default Value (for fields)
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
char 'u0000'
String (or any object) null
boolean false
Type Conversion
Automatic Conversion will take place if:
• Two Types are compatible
• Destination is larger than source
• By Default Any Numeric Value is treated as Integer
• By default any Decimal Value is treated as Double
• Still when we assign numeric value to Byte or Short it is
OK, but if we use any value with them … Then byte and
short are converted to int.
• In Float for assignment also f is to be used
• For Long L/l is to be used
Compatible
• Numerals (byte, short, int , long, float, double) are self
compatible but not with char and boolean.
• Char and boolean are not compatible
Casting
Casting is the temporary conversion of a variable
from its original data type to some other data type.
• With primitive data types if a cast is necessary from
a less inclusive data type to a more inclusive data
type it is done automatically if they are compatible.
int x = 5;
double a = 3.5;
double b = a * x + a / x;
double c = x / 2;
• if a cast is necessary from a more inclusive to a less
inclusive data type the class must be done explicitly
by the programmer
double a = 3.5, b = 2.7;
int y = (int) a / (int) b;
y = (int)( a / b );
y = (int) a / b; //syntax error
Type Promotion
17
double
float
long
int
short,
char
byte
Outer ring is most
inclusive data type.
Inner ring is least
inclusive.
In expressions
variables and
sub expressions
of less inclusive
data types are
automatically cast
to more inclusive.
If trying to place
expression that is
more inclusive into
variable that is less
inclusive, explicit cast
must be performed.
From MORE to LESS
Double-……..int
• If either operand is double then other operands are
converted to double
• Otherwise if either operand is float other operands are
converted to float
• Otherwise if either operand is of type long other operands
are converted to long
• Otherwise both operands are converted to int
Problem
• Byte b=50;
b=b * 2;
???????
Casting …
Int a ;
Byte b;
Flaot f;
b=(byte) a;
a = (int) f;
How does it takes place:
1.Reduced Modulo
2. Truncation
Byte b;
Int i=257;
B=(byte ) i;
System.out.println( “Value of b is” + b);
Scope
• Scope is limited to a block
• Block is
{
}
3 Types of variables:
• instance variables : Variable declared inside the class;
Any method in the class definition can access these
variables
• parameter variables Only the method where the
parameter appears can access these variables. This is how
information is passed to the object.
• local variables : Declared inside the method
public class TwoSides
{
int side1, side2 ;
public boolean testRightTriangle( int hypoteneuse )
{
int side1Squared = side1 * side1 ;
int side2Squared = side2 * side2 ;
int hypSquared = hypoteneuse * hypoteneuse ;
}
}
A variable can be declared in/as:
• In a class body as class fields. Variables declared here are
referred to as class-level variables/instance variables.
• As parameters of a method or constructor.
• In a method's body or a constructor's body.
• Within a statement block, such as inside a while or for .
X : Local variable-Block
public class MainClass
{
public static void main(String[] args)
{
for (int x = 0; x < 5; x++)
{
System.out.println(x);
}
}
}
Inner block :Access Outer
Block
public class MainClass
{
public static void main(String[] args)
{
for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 3; y++)
{ // int x; gives an error x already declared in outer block ... Not such in
// C / C++
System.out.println(x);
System.out.println(y);
}
}
}
}
public class MainClass
{
public static void main(String[] args)
{
int outer = 1;
{ int inner = 2;
System.out.println("inner = " + inner);
System.out.println("outer = " + outer);
}
int inner = 3;
System.out.println("inner = " + inner);
System.out.println("outer = " + outer);
}
}
class S
{ int a=5; // instance variable
public void S1()
{ int a=7; // block variable
System.out.println(a); // prints ??
}
}
public class Scope
{ int a=2; // instance variable
public static void main(String args[])
{
S x=new S(); // object x created
x.S1();
int b=5;
System.out.println(b);
}
//System.out.println(a);
// gives an error as a is instance variable and static no object created
} o/p will be 7 7 5 , local variable is given preference over instance variable
Ad

More Related Content

What's hot (20)

11 constructors in derived classes
11 constructors in derived classes11 constructors in derived classes
11 constructors in derived classes
Docent Education
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
Lovely Professional University
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
 
Data types in C
Data types in CData types in C
Data types in C
Tarun Sharma
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
VINOTH R
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
Amritsinghmehra
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
Spotle.ai
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Hitesh Kumar
 
Constructors in C++
Constructors in C++Constructors in C++
Constructors in C++
RubaNagarajan
 
Unary operator overloading
Unary operator overloadingUnary operator overloading
Unary operator overloading
Md. Ashraful Islam
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
Haresh Jaiswal
 
Applets
AppletsApplets
Applets
Prabhakaran V M
 
Applets in java
Applets in javaApplets in java
Applets in java
Wani Zahoor
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
Prof. Dr. K. Adisesha
 
Java constructors
Java constructorsJava constructors
Java constructors
QUONTRASOLUTIONS
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
Farooq Baloch
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
satvirsandhu9
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
SudhanshuVijay3
 

Viewers also liked (20)

02 data types in java
02 data types in java02 data types in java
02 data types in java
রাকিন রাকিন
 
Java Class 2
Java Class 2Java Class 2
Java Class 2
Mayank Aggarwal
 
Java Class1
Java Class1Java Class1
Java Class1
Mayank Aggarwal
 
Datatype introduction- JAVA
Datatype introduction- JAVADatatype introduction- JAVA
Datatype introduction- JAVA
Hamna_sheikh
 
Java Classes
Java ClassesJava Classes
Java Classes
Mayank Aggarwal
 
Presentation
PresentationPresentation
Presentation
Fiaz Khokhar
 
Java
JavaJava
Java
kavirishi
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
teach4uin
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
Thooyavan Venkatachalam
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
Ahmad Idrees
 
Java notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esectionJava notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esection
Arc Keepers Solutions
 
Virtualization: Force driving cloud computing
Virtualization: Force driving cloud computingVirtualization: Force driving cloud computing
Virtualization: Force driving cloud computing
Mayank Aggarwal
 
Java - Operators
Java - OperatorsJava - Operators
Java - Operators
Preethi Nambiar
 
OCA JAVA - 3 Programming with Java Operators
 OCA JAVA - 3 Programming with Java Operators OCA JAVA - 3 Programming with Java Operators
OCA JAVA - 3 Programming with Java Operators
Fernando Gil
 
Aae oop xp_04
Aae oop xp_04Aae oop xp_04
Aae oop xp_04
Niit Care
 
Cs1123 6 loops
Cs1123 6 loopsCs1123 6 loops
Cs1123 6 loops
TAlha MAlik
 
Cloud Computing : Revised Presentation
Cloud Computing : Revised PresentationCloud Computing : Revised Presentation
Cloud Computing : Revised Presentation
Mayank Aggarwal
 
Java features
Java featuresJava features
Java features
myrajendra
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
Tareq Hasan
 
Cloudsim modified
Cloudsim modifiedCloudsim modified
Cloudsim modified
Mayank Aggarwal
 
Ad

Similar to Java Datatypes (20)

java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
Raja Sekhar
 
JavaVariablesTypes.pptx
JavaVariablesTypes.pptxJavaVariablesTypes.pptx
JavaVariablesTypes.pptx
charusharma165
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
raksharao
 
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptx
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptxOOP - Lecture04 - Variables, DataTypes and TypeConversion.pptx
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptx
AhmedMehmood35
 
C language ppt is a presentation of how to explain the introduction of a c la...
C language ppt is a presentation of how to explain the introduction of a c la...C language ppt is a presentation of how to explain the introduction of a c la...
C language ppt is a presentation of how to explain the introduction of a c la...
sdsharmila11
 
Chapter02.PPTArray.pptxArray.pptxArray.pptx
Chapter02.PPTArray.pptxArray.pptxArray.pptxChapter02.PPTArray.pptxArray.pptxArray.pptx
Chapter02.PPTArray.pptxArray.pptxArray.pptx
yatakumar84
 
Variables, identifiers, constants, declaration in c
Variables, identifiers, constants, declaration in cVariables, identifiers, constants, declaration in c
Variables, identifiers, constants, declaration in c
GayathriShiva4
 
introduction2_programming slides briefly exolained
introduction2_programming slides briefly exolainedintroduction2_programming slides briefly exolained
introduction2_programming slides briefly exolained
RumaSinha8
 
A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...
bhargavi804095
 
Chapter02.PPT
Chapter02.PPTChapter02.PPT
Chapter02.PPT
Chaitanya Jambotkar
 
Introduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingIntroduction to Problem Solving C Programming
Introduction to Problem Solving C Programming
RKarthickCSEKIOT
 
c programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTc programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPT
KauserJahan6
 
CHAPTER 3 STRUCTURED PROGRAMMING.pptx 2024
CHAPTER 3 STRUCTURED PROGRAMMING.pptx 2024CHAPTER 3 STRUCTURED PROGRAMMING.pptx 2024
CHAPTER 3 STRUCTURED PROGRAMMING.pptx 2024
ALPHONCEKIMUYU
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
Eric Chou
 
BASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their ownBASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their own
Nandini485510
 
Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4
FabMinds
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Ayshwarya Baburam
 
01 Java Language And OOP PART I
01 Java Language And OOP PART I01 Java Language And OOP PART I
01 Java Language And OOP PART I
Hari Christian
 
C language
C languageC language
C language
Robo India
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
rohassanie
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
Raja Sekhar
 
JavaVariablesTypes.pptx
JavaVariablesTypes.pptxJavaVariablesTypes.pptx
JavaVariablesTypes.pptx
charusharma165
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
raksharao
 
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptx
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptxOOP - Lecture04 - Variables, DataTypes and TypeConversion.pptx
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptx
AhmedMehmood35
 
C language ppt is a presentation of how to explain the introduction of a c la...
C language ppt is a presentation of how to explain the introduction of a c la...C language ppt is a presentation of how to explain the introduction of a c la...
C language ppt is a presentation of how to explain the introduction of a c la...
sdsharmila11
 
Chapter02.PPTArray.pptxArray.pptxArray.pptx
Chapter02.PPTArray.pptxArray.pptxArray.pptxChapter02.PPTArray.pptxArray.pptxArray.pptx
Chapter02.PPTArray.pptxArray.pptxArray.pptx
yatakumar84
 
Variables, identifiers, constants, declaration in c
Variables, identifiers, constants, declaration in cVariables, identifiers, constants, declaration in c
Variables, identifiers, constants, declaration in c
GayathriShiva4
 
introduction2_programming slides briefly exolained
introduction2_programming slides briefly exolainedintroduction2_programming slides briefly exolained
introduction2_programming slides briefly exolained
RumaSinha8
 
A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...A File is a collection of data stored in the secondary memory. So far data wa...
A File is a collection of data stored in the secondary memory. So far data wa...
bhargavi804095
 
Introduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingIntroduction to Problem Solving C Programming
Introduction to Problem Solving C Programming
RKarthickCSEKIOT
 
c programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTc programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPT
KauserJahan6
 
CHAPTER 3 STRUCTURED PROGRAMMING.pptx 2024
CHAPTER 3 STRUCTURED PROGRAMMING.pptx 2024CHAPTER 3 STRUCTURED PROGRAMMING.pptx 2024
CHAPTER 3 STRUCTURED PROGRAMMING.pptx 2024
ALPHONCEKIMUYU
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
Eric Chou
 
BASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their ownBASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their own
Nandini485510
 
Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4
FabMinds
 
01 Java Language And OOP PART I
01 Java Language And OOP PART I01 Java Language And OOP PART I
01 Java Language And OOP PART I
Hari Christian
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
rohassanie
 
Ad

Recently uploaded (20)

An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient CareAn Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
Cyntexa
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient CareAn Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
Cyntexa
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 

Java Datatypes

  • 2. Features • There are total 9 Data Types • Java is a Strongly Typed Language • No conversion !!! • This makes it more secure and robust • Type Compatibility Checking
  • 3. Strongly Typed • Every variable has a type • Every expression is a type • All assignments are checked for type • All parameters passing are checked for type • No confusing conversions • All type mismatches are error
  • 4. • Types boolean either true of false char16 bit Unicode 1.1 byte8-bit integer (signed) short 16-bit integer (signed) int 32-bit integer (signed) long64-bit integer (singed) float32-bit floating point (IEEE 754-1985) double 64-bit floating point (IEEE 754-1985) String (class for manipulating strings)
  • 5. Ctegories Can be classified in four Categories: • Integers • Floating Point • Characters • Boolean (They are simple data types not objects) !!!!
  • 6. Integers Integers : Width , Usage • byte : 8 bit , used for stream of data from network and files • short : 16 bit , rarely used , for 16 bit computers (oudated) • int : 32 bit, generally used • long : 64 bit, when integer is not sufficient In java size does not vary on platform. Though the actual size taken in memory depends on JVM. All are signed integers; there are no unsigned integers in java. Width represents the behaviour , not the amount of space in memory
  • 7. Floating Point Floating Point : • float : 32 bit • double : 64 bit
  • 8. Float • Single Precision • Uses 32 bits • Sometimes faster • Used when not much accuracy required
  • 9. Double • Double Precision • Uses 64 bits • Faster on modern processors • Used in all mathematical calculations • More Accurate
  • 10. Characters Characters: • char : 16 bit • Unicode : Contains all characters of all human languages • No negative characters • Range 0 to 65,536 • ASCII code is from 0 to 127 which is same for Unicode till 127. • ++ /--/+/- operators possible
  • 11. Boolean • boolean either true or false • Not 0 or 1 • Output of all relational and logical operators
  • 12. Data Type Default Value (for fields) byte 0 short 0 int 0 long 0L float 0.0f double 0.0d char 'u0000' String (or any object) null boolean false
  • 13. Type Conversion Automatic Conversion will take place if: • Two Types are compatible • Destination is larger than source
  • 14. • By Default Any Numeric Value is treated as Integer • By default any Decimal Value is treated as Double • Still when we assign numeric value to Byte or Short it is OK, but if we use any value with them … Then byte and short are converted to int. • In Float for assignment also f is to be used • For Long L/l is to be used
  • 15. Compatible • Numerals (byte, short, int , long, float, double) are self compatible but not with char and boolean. • Char and boolean are not compatible
  • 16. Casting Casting is the temporary conversion of a variable from its original data type to some other data type. • With primitive data types if a cast is necessary from a less inclusive data type to a more inclusive data type it is done automatically if they are compatible. int x = 5; double a = 3.5; double b = a * x + a / x; double c = x / 2; • if a cast is necessary from a more inclusive to a less inclusive data type the class must be done explicitly by the programmer double a = 3.5, b = 2.7; int y = (int) a / (int) b; y = (int)( a / b ); y = (int) a / b; //syntax error
  • 17. Type Promotion 17 double float long int short, char byte Outer ring is most inclusive data type. Inner ring is least inclusive. In expressions variables and sub expressions of less inclusive data types are automatically cast to more inclusive. If trying to place expression that is more inclusive into variable that is less inclusive, explicit cast must be performed. From MORE to LESS
  • 18. Double-……..int • If either operand is double then other operands are converted to double • Otherwise if either operand is float other operands are converted to float • Otherwise if either operand is of type long other operands are converted to long • Otherwise both operands are converted to int
  • 20. Casting … Int a ; Byte b; Flaot f; b=(byte) a; a = (int) f; How does it takes place: 1.Reduced Modulo 2. Truncation
  • 21. Byte b; Int i=257; B=(byte ) i; System.out.println( “Value of b is” + b);
  • 22. Scope • Scope is limited to a block • Block is { }
  • 23. 3 Types of variables: • instance variables : Variable declared inside the class; Any method in the class definition can access these variables • parameter variables Only the method where the parameter appears can access these variables. This is how information is passed to the object. • local variables : Declared inside the method
  • 24. public class TwoSides { int side1, side2 ; public boolean testRightTriangle( int hypoteneuse ) { int side1Squared = side1 * side1 ; int side2Squared = side2 * side2 ; int hypSquared = hypoteneuse * hypoteneuse ; } }
  • 25. A variable can be declared in/as: • In a class body as class fields. Variables declared here are referred to as class-level variables/instance variables. • As parameters of a method or constructor. • In a method's body or a constructor's body. • Within a statement block, such as inside a while or for .
  • 26. X : Local variable-Block public class MainClass { public static void main(String[] args) { for (int x = 0; x < 5; x++) { System.out.println(x); } } }
  • 27. Inner block :Access Outer Block public class MainClass { public static void main(String[] args) { for (int x = 0; x < 5; x++) { for (int y = 0; y < 3; y++) { // int x; gives an error x already declared in outer block ... Not such in // C / C++ System.out.println(x); System.out.println(y); } } } }
  • 28. public class MainClass { public static void main(String[] args) { int outer = 1; { int inner = 2; System.out.println("inner = " + inner); System.out.println("outer = " + outer); } int inner = 3; System.out.println("inner = " + inner); System.out.println("outer = " + outer); } }
  • 29. class S { int a=5; // instance variable public void S1() { int a=7; // block variable System.out.println(a); // prints ?? } } public class Scope { int a=2; // instance variable public static void main(String args[]) { S x=new S(); // object x created x.S1(); int b=5; System.out.println(b); } //System.out.println(a); // gives an error as a is instance variable and static no object created } o/p will be 7 7 5 , local variable is given preference over instance variable
  翻译: