Basic Java

Primitive types:

Primitive types are the most basic data types available within the Java language. There are 8: boolean , byte , char , short , int , long , float and double . These types serve as the building blocks of data manipulation in Java.

Class & Object:

Object - Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class.

Class - A class can be defined as a template/blue print that describes the behaviors/states that object of its type support.

Class contains following variable types:

  1. Local variables:

    • Inside the method, constructors or block.
    • Be declared and initialized within the method and the variable will be destroyed when the method has completed.
  2. Instance variables:

    • Within a class but outside of any method.
    • Initialized when the class is instantiated.
    • Can be accessed from inside any method, constructors or blocks of that particular class.
  3. Class variables:

    • declared with in a class
    • outside any method
    • with the static keyword.

results matching ""

    No results matching ""