Data types in Java
Sun, 17 Nov 2024
3
componentsA set of values
,operations
that can be applied,representation
, which determines how the values are stored,Predefined data types
,int
, double
, String
etc,atomic
, indivisible value
, can't extend
primitive data types,Sequence of characters
of unlimited length,letters
and digits
,Spaces
aren't allowed in an identifier,Case sensitive
, value
, VALUE
are different identifier,memory locations
,3
properties:memory location
for storing the value,type of the data
to store at the memory location, and name
(also called identifier) to refer to the memory location,int sum;
whereint
is allocated,data type
= int
, name
= sum
,a value
,int result;
,byte, short, int, long, char, float, double
, boolean
,reference to an object
,String s;
variable
not for object,String s = new String("Saeed");
, Space
is allocated separately for variable
and the object
it is referring,private static void printHumanData(Human human){
System.out.println(human.getName()+" -> "+human.getAge());
human.setAge(26); // will modify main object
}
Using like this:Human human = new Human("Saeed",21);
printHumanData(human); // Saeed -> 21
System.out.println(human.getAge()); // 26
Classes and Object
section,This is a comment 1.
This is a comment 2.