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
1

 Developed

 Purpose:

JAVA’s OOPS Features
     

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

JAVA’s Additional Features
     

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

Difference: C Vs JAVA
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.

4

Difference: C++ Vs JAVA
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.
5

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) • java.io (I/O Operations) • java.net (Network Functionality) • java.applet • java.awt (GUI Controls)
6

JAVA Program: Structure
Documentation Section Suggested

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

Optional
Optional Optional Optional

Essential

7

Compilation Process
Text Editor

JAVA Source Code (Filename.java)

Java Compiler (Javac)

Java Class File (filename.class)

Java Interpreter (Java)

Java Program Output
8

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

9

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 Filename.java e.g. c:\JAVA_Assignments\javac Demo.java



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

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

11

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); } }
12

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

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

3. Reading Character Value:
char c; c = (char)System.in.read();
13


								
To top