2 Lesson (History and Development)
2 Lesson (History and Development)
And
Development
Of
Java
Creator of Java : James Gosling
(Father of Java).
High Level Language Compiler Low Level Language
High Level Language Interpreter Low Level Language
Java
byte
code
Java Java
Java
interpreter interpreter
interpreter
for Windows for Windows
for Windows
Vista XP
8
Java Virtual
• Java is a high level language.
Message Passing :-
When the objects need to interact with one
another, they pass / request information to
one another. This interaction is known as
message passing.
Types
Of
Java Programs
There are two types of java
programs:
♦ Stand alone applications: Any
software application developed
with Java for a stand-alone
machine. It is also referred as
an application program
Java Development Kit (JDK)
It is a pack of a large number of development
tools.
Plays a great role in the development and
execution of Java programs.
Predefined classes and methods grouped in
packages
Commonly used tools : javac, java, javadoc,
appletviewer, etc.
JAVA API’s
Java API (Application Program Interface) is a
collection of pre-compiled codes grouped into
various functional packages that can be used
while creating programs in Java.
Java.lang
Java.io
Java.applet
Java.math
Jawa.awt
Java.net
Java.text
Basic Structure
In
Java
Programming
// Simple Java Program
•List
caseof reserved words : -
switch
else
break
static etc…. (refer book)
Comment
Symbol
In
Java Programs
Comments /*….*/ and // …. are
non-executable statement.
It tells more or detailed
information about program.
It makes user easy to
understand.
The comments are ignored by
the compiler and not executed
at all even if you write a valid
Examples:
What is a BlueJ?
ÞIt is basically an IDE (Integrated Development Environment ). It includes following tools in it :
Þ an editor : which you can use to write your program.
Þ a debugger :- which helps you find your mistakes.
Þ a viewer: which lets you see parts of your program graphically.
Java Character set :
Character set is a set of valid characters that a language can recognize. A character
represents any letter, digit or any other sign. Java uses the Unicode character set.
Unicode is a two-byte character code set . We can use Unicode by using ‘ \u ’
followed by a four digit hexadecimal number.
For e.g.. \u00AE -- it used for symbol ‘ @ ‘
\u0394 --- it used for symbol delta ‘ ∆ ‘
Tokens:- The smallest individual unit in a program is known as a Token.
For e.g.. Keywords, identifiers, literals, punctuators, operators.
1) Keywords :- are the words that convey a special meaning to the language
compiler. These are reserved for special purpose . E.g. break, float, goto, char etc.
2) Identifiers:- are fundamental building blocks of a program and are used as the
general terminology for the names given to different parts of the program. E.g.
variable, objects, classes etc.
It follows some rules :
1) they can have alphabets, digits and underscore and doller sign character.
2) they must not be a keyword or null literal.
3) they must not begin with a digit.
4) they can be of any length.
5) Java is case sensitive i.e. upper and lower case alphabets are treated differently.
e.g. some valid identifiers : Date9_7_99 , _DS , $1_to_$10
e.g. some invalid identifiers : Date9-7-99, break, My.File
3) Literals(Constants):- are data items that are fixed data values. Types of literals:
i) Integer literal ii) floating literal iii) Boolean literal
iv) Character literal v) string literal vi) the null literal
ii) Integer literal :- are whole number without any fractional part . It must have at
least one digit and must not contain any decimal point. It may contain + or – sign.
3) Character Types :
Type Size Description examples
Char 16 bits (2 Bytes) Single Character Alphabets and numerals
4) Boolean Type :
Type Size Description Range
Boolean Java reserve 8 bits Logical or boolean True or false
but uses 1 bit values
Variables: is a named memory lacation, which holds a data value of a
particular data types.
e.g. int radius = 5;
Float x= 0.27;
Operators in Java:
An operator is a symbol which represents a mathematical or logical
operation that can be performed on a data value.
The data value on which an operation is performed using an operator is
called the operand.
now we are studying types of operators :
1) Arithmetic Operators: a) Unary Operators i) Unary + :- if a=5 then +a
means 5.
if a= -4 then +a means -4
ii) Unary - :- if a=5 then -a means - 5.
if a= -4 then -a means 4
b) Binary Operators i) Addition (+): 4+20 results
in 24
ii)Subtraction (-):- 14-3 evaluates
to11
iii) Multiplication(*):- 3*4
evaluates to 12
◙ Increment / Decrement Operators (++ , --) :
++ is a increment operator and – is a decrement operator. The operator ++
adds 1 to its operand, and – subtracts one.
i.e. a = a + 1; is same as ++a or a++
And a = a – 1; is same as –a or a—
◙ Relational Operators : it gives the results in terms of true and false.
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
◙ Logical Operator :
&& -> all conditions must be satisfied
|| -> any one condition of the given conditions must be
satisfied
! -> Logical NOT
◘ Conditional Operator : this operators is ternary operator i.e. it
requires three operands . The general form of conditional operator is as
follow :
expression ? expression2 : expression3
If expression 1 is true it takes the value of expression2 otherwise value of
expression3
e.g. result = marks >= 50 ? ‘P” : ‘F’
◘ The [ ] operator: it used to declare array, to create arrays, and to access
a particular element in an array.
e.g. marks of 20 students, sales of 30 salesmen etc.
It declare as float [ ] arrayoffloats = new floats [10]
◘ The . Operator : it access instance members of an
object or class members of a class
◘ the ( ) operator: the method’s arguments are listed
between ( ). You can specify it as empty.
◘The (type) operator: it converts a value to specified type.
◘ The new operator: it use to create a new object or a new array.
◘The instanceof operator : it checks whether its first operand is instance
Operator Precedence:
It determines the order in which expression are evaluated.
e.g. the expression y = 6 + 4 / 2 it determines the order for
evaluation.
But, increment & decrement are evaluated before arithmetic,
Arithmetic are evaluated before comparisons, and
Comparisons are evaluated before logical expression.
Assignment expression are evaluated last.
So here division is evaluated before addition and
Value of y will be 8.
Operator Associativity: it determines the grouping of
Operands and operators in an expression.
e.g. x = a + ( b – c ) here, addition &subtraction have same
precedence rating but parentheses evaluate first and
then value of answer is added in operand ‘a’ .
Selection Statements: Where condition is the expression that is
being evaluated. If this condition is true,
a) If statement ; statement is executed. If it is false,
Syntax:- if (expression) statement is ignored (not executed) and
the program continues right after this
statement ; conditional structure.
break statement:
It causes the termination of the statement
and it skip over part of the code.
The For Loop:
Syntax:
Example:
Boolean expressions : are expressions which are either true or false. The
different boolean operators are < (less than), > (greater than), = (equal to),
>= (greater or equal to), <= (less or equal), != (not equal to).
Example:
int double
float
double
double
2) Explicit type conversion:
It is a user defined that forces an expression to be of
specific type
(type) expression
Where type is a valid Java data type to which conversion
is to be done.
e.g. (float) (x + y / 2)