• Monday, October 31, 2016

    Start Learning Java from Beginner to Expert


    Class is the collection of variables i.e. fields and methods. And a program is collection of classes.
    The basic code for declaring a class in Java is:


    class MyClass{

    //Your codes go here.

    }

    When declaring a class, the name of class should be start with capital letter and cannot contains space or special character. If you want to write "My first class" then you should have to write it in Camel Case like: "MyFirstClass".

    CamelCase is very good approach in programming because it is human readable.




    What is Variable?
    It is like a name that point to something in computer memory. In Java it is good to write a variable and method name starting with small character. It is beneficial to differentiate between a class name and variable/method name. It also can't contains any spaces and start with alphabet. Variable that is a  member of a class is called a field.

    Each variable has a datatype associated with it that define which type of information, variable contains i.e. String (group of character), number or decimal etc.
    The basic code for declaring a variable is:

    datatype myVariable;

    Variable can be also declare with its initial value like this:

    dataype myVariable = myvalue;

    It's mean You are declaring a vaiable myVariable with a initial value myvalue of type datatype. We will learn about data type in upcoming tutorial.

    Note:  =  is a assignment operator, which assign a right operand to left operand.


    What is Method?
    It is type of function which operates on the variables of a class. Method will execute when some one calls and returns a value to the caller. 
    Basic declaration of method:

    datatype methodName(){

    }

    Here dataype defines what value the method will written after complete its execution.
    This is basic syntax that show how to call a method:

    datatype myVariable = methodName();

    or

    methodName();

    Above myVariable will get a result from methodName() in first syntax. And in second syntax no value will written to any field(variable).

    Next: Installing Java

    Syed Masoom Rizvi

    Author & Editor

    Hi, This is Syed Masoom Rizvi, who is continue exploring the world of programming ,programming and programming... :)

    0 comments:

    Post a Comment