Professional Documents
Culture Documents
Session 1
Session 1
Overview
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.
Modern Programming - C
C was developed by Dennis Ritchie in the year 1972 for Bell Laboratories. Structured Programming Concept. Top to Bottom Execution. Problems arise if the program is huge. For example, the program exceeding 25,000 lines.
Java
Idea conceived by James Gosling, Ed Frank, Chris Warth, Mike Sheridan and Patrick Naughton in 1991. First working version was released in 1992 as Oak. In 1995, it was renamed as Java and released for public use. It was developed by Sun Microsystems. Pure Object Oriented Programming Concepts.
Features of Java
Simple Secure Portable Architecture - Neutral Interpreted Multithreaded Robust Distributed Dynamic Object-oriented
High performance
Programmer
Editor Source File(s) (.java) Compiler (javac) Class File(s) (.class) Virtual Machine (java) Program executes
Object-Oriented Concepts
The Essential Element
Abstraction
Variables
A variable is a storage location and has an associated type. Before you use a variable, you must declare it. Variable declaration
Format: Example: dataType variableName; int age;
Every variable has a name, a type and a value. Declaring a variable, reserves memory space.
Datatypes
Every variable must have two things: a data type and a name (identifier). Data Types defines the kind of data the variable can hold. There are two kinds of types in the Java programming language:
Primitive Type Reference Type
Primitive Types
A primitive type is predefined by the Java programming language and named by its reserved keyword.
- byte - short - int - long - float - double - char - 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. All the data stored in the array must be of the same type. Declaration :
- int[ ] a = new int[3]; a[0]=1, a[1]=2, a[2]=3; - int[ ] a = {1,3,5,6,9};
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
& | ^ ~
The Bitwise AND The Bitwise OR The Bitwise XOR The Bitwise NOT
Ternary Operator
The ? has this general form:
expression1 ? expression2 : expression3 expression1 can be any expression that evaluates to a boolean value. If expression1 is true, then expression2 is evaluated; otherwise, expression3 is evaluated.
Control Statements
There are three types of Control Statements in Java.
Iteration Statements
for , while , dowhile.
Selection Statements
if , elseif , switch.
Branching Statements
break , continue , return.
while loop
while ( condition ) { statement1; statement2; ... statementN; } If the body has only one statement, the braces are optional condition is any logical expression, as in if The body of the loop
dowhile loop
do { statement1; statement2; ... statementN; } while ( condition ); 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, the next iteration is not executed
for loop
Initialization for ( initialization; condition; change ) { statement1; statement2; ... statementN; } Testing Change
if statement
Syntax if (Expression) { Action; } 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.else statement
Syntax if (Expression) { Action1 ; } else { Action2 ; } If Expression is true then execute Action1 otherwise execute Action2.
Action2
Branching statements
The Break-Statement
- The break Statement can be used in a switchstatement or in any kind of loop statement. When the break-statement is executed, the immediately enclosing loop (or Switch-statement) ends, and the remainder of the loop body is not executed.
The Continue-Statement
- The continue statement proceeds with the next iteration (repetition) of the immediately enclosing while, for or do/while structure.