garbage Collection در جاوا

  • JVM does the garbage collection action

چند نکته در مورد Context و Static در جاوا

  • static is a keyword.
  • context will be created 1 time but object will be created many times.
  • context of the class is a memory location present inside RAM.
  • context is used to Load static members. the context of the class will be created only one per class.
  • JVM creates context of the class.
  • basically the members of the context are known as class variables because we can access them using the context name that is same as class name.
  • when you give .class file to jvm for execution, jvm loads all the static members and blocks to context of the class.
  • JVM first searches for the static block in the context of the class and once the block executions is finished, jvm searches for main method and executes the main method.
  • we can create many static block but it is not necessary.
  • we can call non static main method in static block. actually after that it is not main method and it can have any other name.
  • if we don't create static main method we can not have input parameter from command line
  • main method is necessary for C and C++ because they don't support static block but because of static block main method is not necessary in Java


تفاوت های Method و Constructor در جاوا

Differents between Method and Constructor are as follows:

ConstructorMethod
does not contain any return typehas a signature of return type, name and the arguments
should be same as class namemethod name can not be same as a class name
Constructor can be called only once per objectwe can call a method n number of times on a particular object

چند نکته در مورد Constructor در جاوا

  • Constructor is same as method without return type. It's job only an  initialization the instance variables with the default values.
  • Explicitly we can not call the constructor. JVM has to call the constructor.
  • Constructors name should be same as the class name.
  • The constructor can be created when the we create the object.
  • The constructor can be call only once per object.
  • Job of construction: set default value to class variables.
  • If we pass argument to constructor it is known as parameter constructor
  • We can create our java class without any constructor but a java class without constructor is not possible, because the java compiler adds the default constructor if a user has not mentioned any constructor
  • Note**: Java compiler adds default constructor nooooot JVM


data type در جاوا

  • Java support 8 different data typs. They are categorized in 4 Groups
  • in Logical group Java does not use 0 and 1, Java uses true and false

Integer:default is 0
Real:default is 0.0Character: default is spaceLogical: default is false
Byte (1 byte)
Float (4 byte)char (2 byte)boolean (1 bit)
Short (2 byte)
double (8 byte)

Int (4 byte)



long (8 byte)