JAVA by neharsh2009

VIEWS: 127 PAGES: 13

More Info
									JAVA Introduction
 General

purpose object oriented programming language. by Sun Microsystems of USA in 1991. To develop softwares for consumer electronics

 Developed

 Purpose:

JAVA’s OOPS Features
     

Classes and Objects Data abstraction and encapsulation Inheritance Polymorphism Dynamic Binding Message Passing

JAVA’s Additional Features
     

Compiled and Interpreted Platform Independent and Portable Robust and Secure Distributed Familiar, Simple and Small Multithreaded and Interactive

Difference: C Vs JAVA
   

Does not include C statements: goto, sizeof and typedef Does not include C data types: struct, union and enum. Does not have preprocessor. Adds labeled break and continue statements.


Difference: C++ Vs JAVA
       

Does not support operator overloading. Does not have template classes. Does not support multiple inheritance. Does not support global variables. Does not use pointers. Adds labeled break and continue statements. Replaced destructor function with finalize() method There are no header files in JAVA.

JAVA Environment
JAVA Environment

JAVA Development Kit (JDK)

Application Programming Interface

• javac (Java Complier) • Java (Java Interpreter) • appletviewer • javap (Java Disassembler) • jdb (Java Debugger)

• java.lang(Fundamental Objects) • java.util (Utilities) • (I/O Operations) • (Network Functionality) • java.applet • java.awt (GUI Controls)

JAVA Program: Structure
Documentation Section Suggested

Package Statement
Import Statement Interface Statements Class Definitions Main Method Class { Main Method Definition }

Optional Optional Optional



Compilation Process
Text Editor

JAVA Source Code (

Java Compiler (Javac)

Java Class File (filename.class)

Java Interpreter (Java)

Java Program Output

Simple JAVA Program
/* Documentation Part */ import*; import java.util.*; class Demo { public static void main(String args[ ] ) { System.out.println(“ First Assignment”); } }


Compiling & Running Program
Prerequisites:  Setting java compiler path Syntax: set path=“path for java compiler”; e. g. set path=“c:\jdk1.5\bin”;


How to compile: From Move to your program location & type javac e.g. c:\JAVA_Assignments\javac


How to run From Move to your program location & type java filename e.g. c:\JAVA_Assignments\ java Demo

Program With Multiple Classes
//File Name: class Rectangle { float length, breadth; void getData (float a, float b) { length = a; breadth = b; } float Area() { return (length*breadth); } }


Program With Multiple Classes Contd…
class RectArea { public static void main(String args []) { float area = 0.0f; Rectangle r1 = new Rectangle(); r1.getData(10,5); area = r1.Area(); System.out.println(“ Area = ”+area); } }

Reading values from keyboard
1. Reading Integer Value:
int value; DataInputStream in = new DataInputStream(; System.out.println(“Enter Integer Value”); value = Integer.parseInt(in.readLine());

2. Reading Float Value:
float value; DataInputStream in = new DataInputStream(; System.out.println(“Enter Integer Value”); value = Float.valueOf(in.readLine()).floatValue();

3. Reading Character Value:
char c; c = (char);

To top