2. Introduction to Java

Lesson 1

Introduction to Java Programming Language

1. Use of Java Programming Language

Java programming language is used to write programs applicable to our day to day life. We can write Java programs that can be run on independent computers as well as on web browsers and software based electronic devices also.

Two Simple Java Programs

A program to intialize 5 and 3 to two variables a and b, find sum and print it. Its output also is given.

public class Sum
{
public static void main()
{
int a=5,b=3;
int s=a+b;
System.out.println(s);
}
}

Output:

8

Do Yourself

Write a program to intialize 8 and 6 to two variables x and y, find difference and print it. Write its output also.

2. Two Types of Java Programs

The two types of Java programs are Internet Applets and Stand Alone Applications.

Internet Applets

These are the programs embedded in web pages and used for internet applications.

Stand Alone Applications

These are the programs used in independent computers without the help of web pages.
(Note: We are learning now the stand alone applications only.)

3. Different Compilation Processes

Conversion of program source code to machine code is known as program compilation.

Source Code

The program written in High Level Languages such as Java, C, C++ etc. is known as source code.

Machine Code

The language of computer is machine language i.e., binary (0 and 1). The instructions in binary form are machine code. It is the Low Level Language. The binary code of A is 01000001 and B is 01000010.

Ordinary Compilation Process

The compiler of Windows converts the source program directly to machine code for Windows only. The compiler of System7.5 compiles to machine code for System7.5 only. The compiler of a particular system software converts for that system software only.

Java Compilation Process

The Java Compiler compiles the source code into Java Byte Code, then this byte code is interpreted by Java Interpreter into Machine Code for the platform used – if the operating system used is Windows then to the machine code for Windows, and if the operating system used is System7.5 then to the machine code for System7.5.

Java Bytecode

Java bytecode is a machine instruction - an intermediate code which is converted from source code by Java compiler. The Java bytecode is a machine-independent code.

Object Code / Machine Executable Code

The source code converted to machine code to a particular platform is machine executable code. For different platforms, different machine codes are produced. The resultant machine code is known as machine executable code or native executable code or object code.

Platform in General

The platform generally refers to combination of system software and hardware like Windows on Pentium IV or System7.5 on PowerMacs. Windows and System7.5 are system software, and Pentium IV and PowerMacs are hardware chips.

Java Virtual Machine (JVM)

The Java interpreter which is used to convert the Java bytecode into native machine executable code is known as Java Virtual Machine (JVM). The JVM can be implemented in hardware form or software form.

Java API (Java Application Programming Interface)

The Java API is a library of compiled code (small built-in program parts) that can be used in our program in order to reduce our program effort. The API includes library classes.

Java Platform

The Java Compiler and JVM combined with Java APIs (library classes) makes Java platform.

JDK (Java Development Kit)

The JDK is the Java Development Kit that contains Java compiler, Java Virtual Machine, Java API and other necessary supporting programs etc. to develop a professional Java program.

4. Importance of Java

Java is Platform Independent

The program written in Java can run on any platform that means it can be executed by any operating system and any processors; because this source code is compiled by Java Compiler to byte code which is suited to any platform and then interpreted by JVM to native executable code. So Java is platform independent.

Java is a Programming Language As Well As a Platform

Java can be used to develop various application programs like MS Word, PowerPoint, Excel etc. So Java is a programming language. Java includes some programs like compiler, interpreter - generally which are parts of a system software. So Java is a platform also.

5. Features of Java

1) Simple: By simple code we can create big programs.
2) Robust: Java programs are strong that means we can write even difficult and big programs..
3) Secured: Java offers many security features to make the programs safe and secure.
4) Object Oriented: Each problem is considered as separate class and each item is considered as an object.
5) Platform Independent: Java can be run on any platform.
6) Write Once Run Anywhere (WORA): Once written programs can be run on different platforms.
7) Supports Multimedia: Text, video, audio, animation and graphics can be integrated.
8) Built-in Graphics: Java offers many built-in graphics features.
9) Open Product: Freely available to all.

6. Short History of Java

1) In 1991 Java was developed by James Gosling. Initially its name was Oak.
2) In 1995 Java was formally announced by Sun Micro Systems.
3) In 1995 its name changed to Java and it is incorporated to the web browsers Netscape Navigator.

Note: Initially Oak is used with consumer electronic devices such as microwave oven, washing machine etc.

6. BlueJ An IDE