What is class

Object Oriented Programming Components

What is Class ?

1. Class is a blueprint or template of an Object.

2. Class is a group of objects which have same State and Behaviour.

3. Class is a container that contain following things:

i. Data Type

ii. Method

iii. Constructor

iv. Block

v. Inner Class

i. Data Type

In Data Type we cover all the following things:

  1. Data Type in Java
  2. Variable in Java
  3. Type Casting in Java
  4. Wrapper Class in Java
  5. Modifiers in Java

1. Data Type in Java

a. Data Type is most important thing of the class because it is used to store the values.

b. Data is a group of Information.

c. Each and every Information has own type. So java Provide different type of data type to hold different type of values.

d. There are two type of Data Type in Java :

i. Primitive Data Type

ii. Non-Primitive Data Type

i. Primitive Data Type

a. Primitive Data Types are Old Data type or Lagecy Data type.

b. Primitive Data Types are never create instance.

c. Primitive Data Types are also called variables.

d. There are following primitive data type:

Type Size Default Value Range
boolean 1 bit false true/false
byte 8 bit 0 -128 to 127
short 16 bit 0 -32768 to 32767
char 16 bit \u0000 \u0000 to \uFFFF
int 32 bit 0 -2147483648 to 2147483647
long 64 bit 0 -9223372036854775808 to 9223372036854775807
float 32 bit 0.0 1.4E-45 to 3.4028235E+38
double 64 bit 0.0 4.9E-324 to 1.7976931348623157E+308

ii. Non-Primitive Data Type

a. Non-Primitive Data Types are New Data type.

b. Non-Primitive Data Types instance can be created.

c. Non-Primitive Data Types are also called refrence variables.

d. There are following non-primitive data type:

1. Classes : Predefine (String,System,Scanner,Integer,Float,Thread,etc.)
    User define(Car,MyClass,Demo,Test etc.)

2. Array : int [],Integer[] etc.

3. Interface : It just like class.

4. enum : It is used to define constant.

5. All non-primitive default value is null.

2. Variables in Java

i. Variables are identifiers that is used to store the values.

ii. Identifiers means every variable declare in Standard Patterns as follows:

  • variable name never start from number like int 1a=10;
  • variable name never have predefine keywords like int float=10;
  • variable name never have a space like int roll number=10;
  • variable name never start from special symbols like @,#,!,%,^,&,* etc except of $ because $ represents a currency.
  • variable name can have underscore like int roll_number=10;
  • variable name should be in small letter.

iii. There are three types of variables in java:

  1. Static Variable
  2. Non-Static Variable
  3. Local Variable

1. Static Variable

  • Static variable or property are the shareable property.
  • Static variable or property declare inside a class and outside a method, constructor and block with the help of static keyword.
  • Static property takes memory when your class loaded on JVM(Java Virtual Machine).
  • Static property takes memory single time only.
  • Static property takes memory inside Method Area.
  • Static property always call by the help of class name.
  • It is also called per class variable.
  • It also has default value.

2. Non-Static Variable

  • non static variables are non shareable property.
  • non static variable declare inside a class and outside a method and constructor and block without static keyword.
  • it takes memory when you create an object or instance.
  • it takes memory depends on number of object created of same class.
  • non static property takes memory inside Heap Area.
  • non static property call by a reference variable.
  • when you create an object using new keyword you can get reference variable.
  • non-static variable is called per instance variable.
  • It also has default value.

3. Local Variable

  • It is also called Temporary variable.
  • Local variable declare inside method ,constructor and block.
  • Local variable takes memory when we call method , constructor or block where its declare.
  • Local variable can be access with in a method, constructor and block only.
  • Local variable takes memory inside stack.
  • Each Thread has own stack and by default main method is main Thread so you need to configure from main method.
  • Stack is group of FrameSet.
  • Each Frameset holds a single method information.
  • FrameSet is divided into three parts:
  • i) Local Variable Array -> Where store all the local variables.
    ii)Frame Data -> It provide default error or exception messages.
    iii)Operand Space -> It provide a workspace to perform some calculaton.
  • Local variable has no default value because java does not support garbage value.

No comments: