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

  1. byte - integer
  2. short - integer
  3. char - integer
  4. int - integer
  5. long - integer
  6. float - floating points
  7. double - floating points
  8. boolean - binary (true/false)





Integer Hierarchy 

  1. long
  2. int
  3. short
  4. char
  5. byte


Floating Point Hierarchy

  1. double 
  2. 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

  • 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. 










Comments

Popular posts from this blog

Upcasting and Downcasting (OOP - JAVA)

Method Overloading (OOP - JAVA)