Object Creation, Data Types (OOP - JAVA)
OBJECT CREATION
In java we can generate objects if only we have a class.
We can convert only a class into object
class Human{
}
creating objects - Human h1 = new Human();
Human h2 = new Human();
Human h3 = new Human();
eg: Human duneth = new Human();
class name of object - Human
variable name - duneth
object generate keyword - new
class name of object with parameters - Human()
semi colon - ;
if we consider a name with surname,
surname : Anderson
name : Michael
Stephanie
Jimmy
in that case class is surname and particular object is name. 😇
we can write as below,
1st way or 2nd way
Human duneth; Human duneth = new Human();
duneth = new Human();
PRIMITIVE DATA TYPES
Data types are the types/formats which are used for keeping data.
There are three major primitive data types.
- Integers
- Floats
- Binary
In java we can identify 8 primitive data types
- byte - integer
- short - integer
- char - integer
- int - integer
- long - integer
- float - floating points
- double - floating points
- boolean - binary (true/false)
Integer Hierarchy
- long
- int
- short
- char
- byte
Floating Point Hierarchy
- double
- float
We can perform any arithmetic expression by using data types which are inside same hierarchy.
eg: int a = 5; 😄 eg: float c = 7.8; 😄
int b = 7; float d = 9;
a+b; d-c;
We can not perform any arithmetic expression directly by using data types which are inside different hierarchy.
eg: long e = 12345; 😟
float f = 789.76;
e + f;
- String is a class
- A prebuild (unchangeable) class
- We can use as a data type
- It's not a primitive data type
- We can assign any data to string easily.
eg: String s1 = "12345678";
String s2 = "jgABcX";
String s3 = "!@^#$";
String s4 = "hAD@34!";
We must use quotation marks when assign a value.
.png)


Comments
Post a Comment