Thursday, September 26, 2013

OOP with Java - Part 1


         Welcome to Object Oriented                                               Programming

                          JDK(Java Development Kid)

      The "JDK" is the Java Development Kit. I.e., the JDK is bundle of software that you can use to develop Java based software. The "JRE" is the Java Runtime Environment. I.e., the JRE is an 
implementation of the Java Virtual Machine which actually executes Java programs.Java Development Kit contains tools needed to develop the Java programs, and JRE to run the programs. The tools include compiler (javac.exe), Java application launcher (java.exe), Appletviewer, etc...

    JRE = JVM + Java Packages Classes(like util, math, lang,                                                         awt,swing etc)+runtime libraries.

                             JRE (Java Runtime Environment)

            Java Runtime Environment contains JVM, class libraries, and other supporting files. It does not contain any development tools such as compiler, debugger, etc. Actually JVM runs the program, and it uses the class libraries, and other supporting files provided in JRE. If you want to run any java program, you need to have JRE installed in the system.  
         The Java Virtual Machine provides a platform-independent way of executing code; programmers can concentrate on writing software, without having to be concerned with how or where it will run. 

                         JVM(Java Virtual Machine)

          The JVM is called "virtual" because it provides a machine interface that does not depend on the underlying operating system and machine hardware architecture. This independence from 
hardware and operating system is a cornerstone of the write-once run-anywhere value of Java programs. JVM is platform dependent.

            Java compiler generates Java byte code. Byte code is easy (and fast) to interpret, like machine language, but it is also portable, like a high-level language. Thus, it is possible to compile a Java 
program on one machine, transfer the byte code to another machine over a network, and then interpret the byte code on the other machine. This ability is one of the advantages of Java over many other high-level languages.

          java is a high level programming language. Computer doesn't understand our languages. It can understand only 0 and 1.There are three steps to create a java program.

  1. Writing the code
  2. Compiling the code 
  3. Running the code

  • How to run a "Hello World" program.....?
      1. Writing the code  
          
        Usually,we use notepad for this task.

                                         class Test{
                                                public static void main(String arg[]){
                                                    System.out.println("Hello World");
                                               }
                                          }


        First we have to type above code in notepad and save it
     C:\java -----> Test.java

      2. Compiling the code

         Then type we have to give compile and run command in command prompt. So to before give command we have to navigate the place we saved the text file(source file).
        To compile ----->  javac Test.java  (then press Enter) 
After compile source file, we can call it as "Class file".

       3. Running the code

          We run the byte code -------> java Test (then press Enter)

           
                      Declarations & Access Control
       
   An identifier can only be started with a letter, _(underscore) or $(dollar sign).Classes,interfaces,variables and method names should be "camelCase". classes and  interfaces usually start with a capital letter.





Next Post