Object Creation & Data Types

Object Creation & Data Types

Object Creation

Only a class can be converted to an object. So to generate an object, a class must exist. in Java. The advantage of object creation is that many objects can be generated in relation to one class, so the process can be done using only one class.

Figure 1: Object Creation

Figure 1 shows the code used for object creation. 

"Code" is the class that the object belongs to and "java" is the variable name of the new object which is created in that class. "new" is the object generate keyword and by using the parameter list, the variable assignment or storing the new object is done.

Primitive Data Types

Formats that are used to store data are called Data Types. There are 3 main Data Types.

  1. integer
  2. float (decimals)
  3. binary (1/0, true/false)

In Java, there are 8 main Primitive Data Types. They are,

  1. byte
  2. char
  3. short
  4. int
  5. long
  6. float
  7. double
  8. boolean

Out of these 8 primitive data types, byte, char, short, int and long are integers, float and double are floating points and boolean is binary. 

As class hierarchy, there are integer and floating point hierarchy. From upper to lower, integer hierarchy goes as long, int, short, char, byte and floating point hierarchy goes as double, float.

Figure 2: Primitive Data Types

Any arithmetic operation can be accessed if the corresponding primitive data types are of the same type. If the types are different, it cannot be accessed directly. But there are also another ways to access them.

From Figure 3, you can learn more details about primitive data types.

Figure 3: More on Primitive Data Types

String

String is a prebuild (immutable) class. It can be used as a data type but not a primitive data type. Any type of data can be assigned using String and double commas are used to delimit the String value.

Figure 4: String Example

Comments

Popular posts from this blog

Polymorphism

Java Standards, Class & Object

Super Keyword