P. 1
Session 1

Session 1

|Views: 0|Likes:
Published by Karishma Gupta

More info:

Published by: Karishma Gupta on Aug 08, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PPT, PDF, TXT or read online from Scribd
See more
See less

08/08/2011

pdf

text

original

Java

Overview

Accent e Technology pvt. Ltd.
http://www.accentonline.co.in

Programming Languages
‡ Programming Language. ‡ Reasons for development of a new programming language.
± To adapt to the changing environment and its uses. ± To implement refinement and improvement in the art of programming.

‡ Previous Programming Languages.

‡ Structured Programming Concept. For example. ‡ Top to Bottom Execution. the program exceeding 25.000 lines. .C ‡ C was developed by Dennis Ritchie in the year 1972 for Bell Laboratories.Modern Programming . ‡ Problems arise if the program is huge.

C with Classes ± C++ ‡ Developed by Bjarne Stroustrup in the year 1979 for Bell Laboratories. ‡ Bottom to Top Execution. ‡ Problems started with Platform Dependency. ‡ Enhancement of C with Object Oriented Programming Concepts. ‡ Later in 1983. . it was named as C++.

Chris Warth. Ed Frank. ‡ In 1995. .Java ‡ Idea conceived by James Gosling. ‡ First working version was released in 1992 as ³Oak´. ‡ Pure Object Oriented Programming Concepts. Mike Sheridan and Patrick Naughton in 1991. it was renamed as ³Java´ and released for public use. ‡ It was developed by Sun Microsystems.

Features of Java ‡ ‡ ‡ ‡ ‡ Simple Secure Portable Architecture .Neutral Interpreted ‡ ‡ ‡ ‡ ‡ Multithreaded Robust Distributed Dynamic Object-oriented ‡ High performance .

Java Compilation & Execution Command Line Interface Programmer Editor Source File(s) (.class) Virtual Machine (java) Program executes Parts of Sun Java SDK .java) Compiler (javac) Class File(s) (.

Object-Oriented Concepts ‡ The Essential Element ± Abstraction ‡ The Three OOP Principles Encapsulation Inheritance Polymorphism .

. you must declare it. reserves memory space. int age. ‡ Variable declaration ± Format: ± Example: dataType variableName.Variables ‡ A variable is a storage location and has an associated type. ‡ Every variable has a name. ‡ Before you use a variable. a type and a value. ‡ Declaring a variable.

Datatypes ‡ Every variable must have two things: a data type and a name (identifier). ‡ There are two kinds of types in the Java programming language: ± Primitive Type ± Reference Type . ‡ Data Types defines the kind of data the variable can hold.

char .Primitive Types ‡ A primitive type is predefined by the Java programming language and named by its reserved keyword.float .int .double .long .short .byte . .boolean .

Reference Types ‡ There are three kinds of reference types: ± class ± interface ± array ‡ These are user defined values. . They differ depending upon the user declarations.

Introduction to Arrays ‡ An array is an object used to store a collection of data. a[0]=1.int[ ] a = new int[3]. a[2]=3. a[1]=2. ‡ All the data stored in the array must be of the same type. . ‡ Declaration : .5.9}.3.6. .int[ ] a = {1.

Arithmetic Operators ‡ ‡ ‡ ‡ ‡ ‡ ‡ + * / % ++ -to indicate addition to indicate subtraction to indicate multiplication to indicate division to indicate remainder of a division (integers only) increment (prefix and postfix) decrement (prefix and postfix) .

Relational Operators ‡ ‡ ‡ ‡ ‡ ‡ == != < > <= >= equals not equals less than greater than less than or equal to greater than or equal to ± Note: Arithmetic comparisons result in a Boolean value of true or false .

Bitwise Logical Operators ‡ The bitwise logical operators are ± & ± | ± ^ ± ~ The Bitwise AND The Bitwise OR The Bitwise XOR The Bitwise NOT .

Short-Circuit Logical Operators ‡ Short-Circuit Logical Operators are Boolean operators. ‡ These are secondary versions of the Boolean AND and OR operators. not found in most other computer languages.  &&  || Short-circuit AND Short-circuit OR .

± If expression1 is true. otherwise. then expression2 is evaluated. ‡ Ternary Operator ± The ? has this general form: ‡ expression1 ? expression2 : expression3 ± expression1 can be any expression that evaluates to a boolean value.Assignment and Ternary Operators ‡ Assignment Operator ± Assignment operator has this general form: ‡ var = expression. expression3 is evaluated. .

.Control Statements ‡ There are three types of Control Statements in Java. else«if . ± Iteration Statements ‡ for . continue . while . do«while. switch. ± Selection Statements ‡ if . ± Branching Statements ‡ break . return.

. } If the body has only one statement... the braces are optional condition is any logical expression. . statementN. as in if The body of the loop while ( condition ) statement1.while loop while ( condition ) { statement1. statement2.

statement2.. Always use braces for readability (even if the body has only one statement) The code runs through the body of the loop at least once if condition is false. . statementN. the next iteration is not executed . } while ( condition )..do«while loop do { statement1.

condition..for loop Initialization for ( initialization.. statement2. change ) { statement1. } Testing Change . statementN. .

} ‡ If the Expression is true then execute Action ‡ Action is either a single statement or a group of statements (in block) within braces Expression true false Action .if statement ‡ Syntax if (Expression) { Action.

if«. } else { Action2 .else statement ‡ Syntax if (Expression) { Action1 . Expression true Action1 false Action2 . } ‡ If Expression is true then execute Action1 otherwise execute Action2.

} else if(Boolean_Expression_3) { Action_3 . else { Default_Action .Multibranch if«. } «. } else if(Boolean_Expression_2) { Action_2 . } .else statement ‡ Syntax: if(Boolean_Expression_1) { Action_1 .

} case Case_label_N: { Statement. } Default: { Statement.«. case Case_label_1: short are allowed { Statement. } } . « break. char . int . « break. Break.switch case statement ‡ Syntax: switch( Controlling_Expression ) { Only byte .

‡ The Continue-Statement . and the remainder of the loop body is not executed. the immediately enclosing loop (or Switch-statement) ends.The break Statement can be used in a switchstatement or in any kind of loop statement.Branching statements ‡ The Break-Statement . When the break-statement is executed. for or do/while structure. .The continue statement proceeds with the next iteration (repetition) of the immediately enclosing while.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->