Wednesday, October 15, 2014

Day3 (Java Training)

Please continue from here-
http://selenium-makeiteasy.blogspot.in/2014/10/day2java-training.html

Program is a collection of 1) data(variables) 2) methods (operation).
  • What is the variable ?
    Ans- Variable is used to store data, such as a number, or a string of characters. Basically it is used to store some value(Data). Ex- int i = 5; So here i is a variable which store integer.
  • What is operation/method/function ?
    Ans- It's a kind of process which will do some operation on variables and will give some output/result. Ex- addition of two numbers.
  • Variable follow three step process-
    i) Declaration (reserve some memory), ex- int i;
    ii) Initialization (initialize the variable with some value), ex- i=0;
    iii) Utilization (use the variable)., ex- i+6;
  • Based on memory allocation java provide 8 types of data type-
    1. byte (1 byte storage),
    2. short (2 byte storage),
    3. int (4 byte storage),
    4. long (8 byte storage),
    5. float (4 byte storage),
    6. double (8 byte storage),
    7. char (2 byte storage),
    8. boolean (2 byte storage),
  • byte, short, int and long can store only integer variable. ex- 2
  • float and double used to store decimal number. ex- 3.0
  • char used to store a to z alphabet.
  • boolean can have true or false. It can't have 0 or 1.
  • A program has keyword, identifiers and literals.
    ex- int i = 3;

    int
    is a keyword.
    i is a identifiers.
    3 is a literals.
  • Keyword is a word which is predefined.
  • Identifiers are words which are user defined. It can be alphanumeric but can't be only numeric. 1st letter should always be alphabet.
  • Convention for identifiers- Always start 1st word with small letter but rest of the word should start with Caps letter.
    ex- javaSeleniumTraining
  • Convention for class name- all the word should start with caps letter.
    ex- JavaTraining
  • Note- If any local variable has not been initialized before using it then it will give compilation error.

  • Ex-
    public class JavaTraining{
        public static void main(String[] args){
            System.out.println("Start Here");
            int x;
            x=4;
            int y = 5;
            System.out.println("value of x: "+x);
            System.out.println("value of y: "+y);
        }
    }
  • + sign work as concatenation when using between String and integer or say to concatenate two values in java use + sign.
  • ; indicate the end of statement.
That's all for today :)

For your practice-
1) Try to write the code to print the sum of two numbers.
2) Try to write the code to print the area of square whose one arm is 5cm.

No comments:

Post a Comment