Sunday, October 12, 2014

Day2(Java Training).

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

Installation of JDK-
  • go to Google - download latest version of JDK and install it.
    http://www.oracle.com/technetwork/java/javase/downloads/index.html
  • After installation, go to -> my computer -> C drive -> program files(x86)/program files -> search for Java folder and open -> jdk -> bin -> copy the path of bin.
  • open the computer properties -> Advanced System settings -> Advanced -> Environment variable -> under system variable search for Path -> click on edit -> go to end of line -> insert ; -> then paste the path of bin which you copied in the above step -> 3 times click OK button.
  • JDK installed.
  • To verify whether JDK installed or not - go to cmd and type the commad -> Java -version and hit enter. This will give you the java version which you have installed.

Every program should have 3 things-

  • keyword (all keyword should be in lower case.)
  • identifiers
  • literals
 Important points-
  • *Every java module should start with 'class' keyword.
  • While saving the program, class name and file name should always be same.
  • Space is not allowed in class name.
  • If there are more than one class declared inside a program, then always save the file with class name which has access specifier as public. (This concept will clear in next topics so don't worry.)
  • Compiler recognize the java program with the extension .java
  • Ex-
    class HelloProgram
    {
               public static void main(String[] args){
                     System.out.println("Hello Java");
               }
         }
  • Save the above program as HelloProgram.java
  • Convention- give the 1st letter as caps in class name for all the words used in class name.
  • Explanation-
    public, static, void are keywords.
    main() is method
    String is a class
    args is the argument
  • output of this program is Hello Java
How to compile and run java program ?
  • go to cmd.
  • go to that folder where java file is kept.
  • To compile java program command is -
    javac filename.java
  • To run/execute the class file command is -
    java ClassName
Note- 
  •  All java program execution start from main method.
    Syntax for main method- public static void main(String[] args)
  • Every statement in java program should end with semicolon(;).
Points to remember for interview
  • Can you compile and run the java program without main method ?
    Ans- Java program can be compiled without main method,
             but can not be run/executed without main method.
  • What is the difference between println and print ?
    Ans-
    println is used to print in the next line while print is used to print in the same line. Basically println will move the cursor to next line while print will remain the cursor in the same line.
    ex- System.out.println("Java");
          System.out.print("And");
          System.out.println("Selenium");
    output- Java
                And Selenium
  • Byte code is called as class file.
  • Whether java is compiler based or interpreter based ?
    Ans- java required both compiler and interpreter.

No comments:

Post a Comment