SlideShare a Scribd company logo
1 of 29
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

More Related Content

What's hot

Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methodsShubham Dwivedi
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
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 KuteTushar B Kute
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introductionSohanur63
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handlingNahian Ahmed
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in JavaKurapati Vishwak
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#Adeel Rasheed
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NETRajkumarsoy
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in javaRaja Sekhar
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statementsKuppusamy P
 
Chapter 8 software testing
Chapter 8 software testingChapter 8 software testing
Chapter 8 software testingdespicable me
 

What's hot (20)

Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
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
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Data types in java
Data types in javaData types in java
Data types in java
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
 
Java Notes
Java Notes Java Notes
Java Notes
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in java
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
Chapter 8 software testing
Chapter 8 software testingChapter 8 software testing
Chapter 8 software testing
 
Packages in java
Packages in javaPackages in java
Packages in java
 

Viewers also liked

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
 
Java Class1
Java Class1Java Class1
Java Class1
 
Datatype introduction- JAVA
Datatype introduction- JAVADatatype introduction- JAVA
Datatype introduction- JAVA
 
Java Classes
Java ClassesJava Classes
Java Classes
 
Presentation
PresentationPresentation
Presentation
 
Java
JavaJava
Java
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
 
Java notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esectionJava notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esection
 
Virtualization: Force driving cloud computing
Virtualization: Force driving cloud computingVirtualization: Force driving cloud computing
Virtualization: Force driving cloud computing
 
Java - Operators
Java - OperatorsJava - Operators
Java - Operators
 
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
 
Aae oop xp_04
Aae oop xp_04Aae oop xp_04
Aae oop xp_04
 
Cs1123 6 loops
Cs1123 6 loopsCs1123 6 loops
Cs1123 6 loops
 
Cloud Computing : Revised Presentation
Cloud Computing : Revised PresentationCloud Computing : Revised Presentation
Cloud Computing : Revised Presentation
 
Java features
Java featuresJava features
Java features
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
Cloudsim modified
Cloudsim modifiedCloudsim modified
Cloudsim modified
 

Similar to Java Datatypes

java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming NeedsRaja Sekhar
 
JavaVariablesTypes.pptx
JavaVariablesTypes.pptxJavaVariablesTypes.pptx
JavaVariablesTypes.pptxcharusharma165
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operatorsraksharao
 
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.pptxAhmedMehmood35
 
c programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTc programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTKauserJahan6
 
Introduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingIntroduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingRKarthickCSEKIOT
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingEric Chou
 
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 4FabMinds
 
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 IHari Christian
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2rohassanie
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2ndConnex
 
Chap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxChap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxRonaldo Aditya
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptxssuserb1a18d
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programmingChetan Giridhar
 

Similar to Java Datatypes (20)

java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
 
JavaVariablesTypes.pptx
JavaVariablesTypes.pptxJavaVariablesTypes.pptx
JavaVariablesTypes.pptx
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
 
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
 
Chapter02.PPT
Chapter02.PPTChapter02.PPT
Chapter02.PPT
 
c programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTc programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPT
 
Introduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingIntroduction to Problem Solving C Programming
Introduction to Problem Solving C Programming
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 
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
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
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
 
C language
C languageC language
C language
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
 
Javascript
JavascriptJavascript
Javascript
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Chap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxChap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptx
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptx
 
P1
P1P1
P1
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 

Recently uploaded

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Fact vs. Fiction: Autodetecting Hallucinations in LLMs
Fact vs. Fiction: Autodetecting Hallucinations in LLMsFact vs. Fiction: Autodetecting Hallucinations in LLMs
Fact vs. Fiction: Autodetecting Hallucinations in LLMsZilliz
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 

Recently uploaded (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Fact vs. Fiction: Autodetecting Hallucinations in LLMs
Fact vs. Fiction: Autodetecting Hallucinations in LLMsFact vs. Fiction: Autodetecting Hallucinations in LLMs
Fact vs. Fiction: Autodetecting Hallucinations in LLMs
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 

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