You are on page 1of 10

16-06-2011

Java Programming

OO Concepts, Intro to Java and Java architecture

Course Objective

To introduce Java Architecture & appreciation of the basic syntax in Java Language To illustrate how to make use of standard Java Class Library and create reusable classes.

To introduce Exception Handling in Java


To introduce User Interface Concepts & Event Handling

16-06-2011

References

Patrick Naughton & Herbert Schildt

Java2: The Complete Reference 3rd Ed., Tata McGraw-ill Publishing Company Limited, New Delhi.

Eckel & Bruce

Thinking in Java, 3rd Ed., Addison-Wesley.

"The Java Tutorial"

http://java.sun.com/docs/books/tutorial/

OO Basics

Polymorphism Inheritance Message Encapsulation

Abstraction

16-06-2011

What are Objects ?

Objects
PC

are things

Monitor, Employee, Space Shuttle,

Complex Number, (X+Yi), Bank Account, Bicycle

Objects

may be simple or complex

Objects

may be real or imaginary

Object Oriented Program


Data Function Data Function

Data Function

Data Function

16-06-2011

Objects vs. Classes

Class

A class defines a real world or abstract entity. A class defines both the behavior and attributes

of a group of objects with similar characteristics

Object

An object is an instance or variable of a class. It is said to belong to the class. An object can be distinguished from other objects by its attributes.

Introduction to Java

A language developed at Sun Microsystems

A general-purpose language
High-level language Developed initially for consumer devices Helps in building a dynamic Web Supported today by most of the big

players like IBM, Oracle etc.

16-06-2011

Features of Java

Object-oriented Simple Robust Secure Architecture Neutral / Portable Multithreaded Distributed

Java - The Basics

Draws An

features from OO languages

like Smalltalk, C++, Ada


interpreted language a virtual machine called Java

Uses
A

Virtual Machine (JVM) very exhaustive OO library

16-06-2011

Platform independence...

Java is a language that is platform independent. A platform is the hardware or software

environment in which a program runs


Once compiled, code will run on any platform without recompiling or any kind of modification. This is made possible by making use of a Java Virtual Machine a.k.a. JVM

Java Virtual Machine (1 of 2)

JVM can be considered as a processor purely implemented with software. The .class file that is generated is the machine code of this processor.

The interface that the JVM has to the .class file remains the same irrespective of the underlying platform. This makes platform independence possible

16-06-2011

Java Virtual Machine (2 of 2)

The

JVM interprets the .class file

to the machine language of the underlying platform.

The

underlying platform processes

the commands given by the JVM and

returns the result back to JVM


which displays it for you.

Java Architecture
Source File (HelloWorld.java) Class Loader

Byte Code Verifier

Compiler (javac)

Interpreter

JIT Code Generator

Runtime

Machine Code or Byte code (HelloWorld.class)

Hardware

JVM

16-06-2011

Intro to Java Setting up Java

Before we begin, something on installation

Java Installation

Java 2 SDK (v1.4 or higher)


(http://java.sun.com) Make sure that the path environment variable is set after installation (eg : Path=%Path%;C:\jdk1.4\bin)

to test open a command window and type javac

Source File Layout - Hello World



We will have the source code first Type this into any text editor
public class HelloWorldApp {
public static void main(String[]args){ System.out.println(Hello World!); } }

Save this as HelloWorldApp.java Important :

take care!! cAsE of file name matters. Make sure that the file is NOT saved as HelloWorldApp.java.txt [Refer Notes]

16-06-2011

To Compile

Open a command prompt Go to the directory in which you have saved your program. Type javac HelloWorldApp.java

If it says bad command or file name then set the path If it does not say anything, and you get the prompt, then the compilation was successful.

To execute

Type

in the command prompt

The
result

java HelloWorldApp

16-06-2011

Compilation & Execution


Java Program (.java)

Java Complier (javac)

Byte Code (.class file)

Interpreter (java)

Interpreter (java)

Interpreter (java)

Win 32

Linux

Mac

Summary

OO Concepts Features of Java Architecture of Java

Structure Compiling Executing

of a Java Program
a Java Program a Java Program

10

You might also like