Starting with simple Java program


Start with JAVA

         As already discussed in previous posts, In java programming language, everything is class and objects.Let us consider a simple template of java code. In Java everything should be inside class

class example {
}

-----------------------------------------------------------------------------------------------------------------
 How to store the data in the class?

          Data will be stored using variables in JAVA.

class example{
              int a =10; // used to store Numeric data (Integer). Here  "a" is the variable
}
----------------------------------------------------------------------------
If we need to do some functionality with the integer, we need some functions
In the below code , add() is the function/method.

class example{
                    int a=10;
                 // Here add() is method to achieve the functionality
                     void add(){
                                   int b=5+10;
                                   System.out.println("Result of the add() method is "+ b);
                     }
}







Previous
Next Post »