Introduction

  • Java is a programming language (but not a script language) which developed by Sun Micro System.
  • Program written using Java is formed as object-oriented 100% which packed as class (*.class)
  • Java Programming Code is compiled as class file stored in byte code (not binary code as *.exe files).
  • To execute byte code to application, sun has developed the software named Java Virtual Machine (JVM) which used to interpret and run Java’s byte code as Machine Language.
  • Java Virtual Machine is founded in Web Browser, JDK package, etc.

java-vitual-machine

Advantages:

  • Application written by Java can run on any operating system.
  • Application written by java is a dynamic which can transfer fast on the Internet.
  • Java Code (Object) is easy to distribute.

Software Packages:

  • JVM: JDK1.4, JDK1.5, JDK1.6 (Recommended)
  • Download: sun.java.com
  • JCreator 3.5, JCreator 4.5 (Recommended)
  • MS Access (using as Database)
  • Notepad2, Notepad++

Java Application Form

There are many different forms of Java Programming:

  • Console Application: is a program which can run on Dos, GUI (AWT, SWING).
  • Applet: is a dynamic program which can transfer on Web Server, and run on client
  • Servlet (Server let): is used to process as Server Application which runs on Web Server and output the result on client by using Web Browser (DHTML).

Compile and Run Java

  • Edit Java Code: Using Notepad, Text Editor, etc.
  • Save Java Code:
  • Using any name with extension *.java
  • Example: Filename àjava
  • Java Code Form:

class classname {

                                        //write your code here

}

  • Compile Java Code:
    • On Command Prompt, select the directory that the saved java file is stored (*.java)
    • Type: javac classname.java
    • For example: javac Hello.java
    • Compiling Java Code (Byte Code) will create new file name as classname.class
    • To set path for JVM, type:

set path=c:\jdk1.6\bin;

  • Run Java Code:
    • Run on Command Prompt
    • Type: java classname
    • For Example: java Hello

Notes:

  • . : move backward one dir
  • cd\ : move to the main root
  • cd JavaCodes : go to JavaCodes folder
  • dir : display contents inside directory

Example 1:

class Text1{

                public static void main(String[] args){

                System.out.println(“Hello World!”);

                System.out.println(“Learning Java is quiet easy!”);

}

}

Example 2:

import javax.swing.*;

class Jwin extends JFrame{

                public Jwin(){

                setTitle(“My first Java Form”);

                setSize(400,300);

                setVisible(true);

}

public static void main(String[] args){

                new Jwin();

}

}