Java

JAVA Basic

JAVA Basic

In JAVA Basic programming we consider, it can be defined as a collection of objects that communicate with each other’s using some specific methods. Before starting the Java programming we should now some basic concepts of object, class, method, and instance variables.

Object:   Everything which exists in real life called an object. Each object has two things one is the state and the other is behavior. For example, a cat has states color, name, shape, and behavior is running, eating, and wagging, etc. An object is also an instance of the class. When we obtain the object of the class two steps required. First, we must declare a variable of the class type and second, we must acquire physical memory to that object. We can do using Java built-in keyword new operator. The new operator used to allocate physical memory at the time of compilation.

Example:

    zoetropefilmWeb myobj = new zoetropefilmWeb( );
    //You can also write this statement in other way.
    zoetropefilmWeb myobj; // declare reference to object
    myobj = new zoetropefilmWeb( ); // allocate a zoetropefilm object

Class:   A class is user define data type which describes how its object outside the class look called a class. A class describes the behavior or state of the object. A class declared using a class keyword.

Example:

Related Articles
     class zoetropefilmWeb
     {
        . . . . . . // class content 01
        . . . . . . // class content 02
        . . . . . . // class content 03
     }

Method/Function:   A method/function is a named block of code which performs some specific action called Method/Function. The statements written in a function body are executed when it is called by its name. In a class method is the behavior of the object. A single class can have many methods. Logics wrote in the method body. A single class can have many methods with the same name but a difference in their parameters. The method has four parts, one is return type, second is method name, third is parameters and fourth is method body.

Example:

     void run ( )
     {
        . . . . . . .
        . . . . . . .
        . . . . . . .
     }
/////////////////////////////////////
     int push (int x, int y)
     {
        . . . . . . .
        . . . . . . .
        . . . . . . .
     }

function parts

Instance Variables:   Instance variable locate anywhere in the class and outside the method called instance variable. Every object has its unique collection of instance variables. An object can have store its states in the instance variables.

Example:

     class zoetropefilmWeb
     {
         int x;   // x is instance variable
         char y;   // y is instance variable
         string z;   // z is instance variable
         void show ()
         {
             . . . . . . 
             . . . . . .
             . . . . . .
         }
     }

In this example variables x, y, and z are instance variables that declare inside the zoetropefilmWeb class and outside the method named show ( ).

 

Show More
यौगिक किसे कहते हैं? परिभाषा, प्रकार और विशेषताएं | Yogik Kise Kahate Hain Circuit Breaker Kya Hai Ohm ka Niyam Power Factor Kya hai Basic Electrical in Hindi Interview Questions In Hindi