2. INTRODUCTION
Java is a computer programming
language that is concurrent, class
based object-oriented , and specifically
designed to have as few implementation
dependencies as possible.
Java applications are typically compiled to
byte code that can run on any Java virtual
machine (JVM) regardless of computer
architecture.
3. Java is, as of 2014, one of the most popular
programming languages in use, particularly for
client-server web applications, with a reported 9
million developers.
Java was originally developed by James
Gosling at Sun Microsystems and released in
1995 as a core component of Sun
Microsystems' Java Platform.
The language derives much of
its syntax from C and C++, but it has fewer low-
level facilities than either of them.
4. HISTORY
On 23 May 1995, John Gage, the director of the Science
Office of the Sun Microsystems along with Marc Andreesen,
co-founder and executive vice president at Netscape
announced to an audience of Sun World that Java
technology wasn't a myth and that it was a reality and that it
was going to be incorporated into Netscape Navigator.
At the time the total number of people working on Java was
less than 30. This team would shape the future in the next
decade and no one had any idea as to what was in store.
From being the mind of an unmanned vehicle on Mars to the
operating environment on most of the consumer electronics,
e.g. cable set-top boxes, VCRs, toasters and also for
personal digital assistants (PDAs). Java has come a long
way from its inception. Let's see how it all began.
5. Before Java emerged as a programming
language, C++ was the dominant player in the
trade. The primary goals that the creators of
Java was to create a language that could tackle
most of the things that C++ offered while getting
rid of some of the more tedious tasks that came
with the earlier languages.
Behind closed doors, a project was initiated in
December of 1990, whose aim was to create a
programming tool that could render obsolete
the C and C++ programming languages.
Engineer Patrick Naughton had become
extremely frustrated with the state of Sun's C++
and C APIs (Application Programming
Interfaces) and tools.
6. OBJECTIIVES
There were five primary goals in the
creation of the Java language.
It should be "simple, object-oriented and
familiar"
It should be "robust and secure"
It should be "architecture-neutral and
portable"
It should execute with "high performance"
It should be "interpreted, threaded, and
7. PROPERTIES
Various features of java programming language are as given below-
1.Java is very simple programming language. Even though you have no
programming background you can learn this language comfortably.
2.Java is popular because it is an object oriented programming language like
C++.
3.Platform independence is the most exciting feature of java. That means
programs in java can be executed on variety of systems. This feature is based
on the goal
“write once, run anywhere and at anytime, forever”.
4.Java supports multithreaded programming which allows a programmer to
write
such a program that can be perform many tasks simultaneously.
5.Thus robustness is the essential criteria for the java programs.
6.Java is designed for distributed systems. Hence two different objects on
different
8. VARIABLES
There are four kinds of variables.
Instance variables: These are variables that are used to store the state of an object (for
example, id). Every object created from a class definition would have its own copy of the
variable. It is valid for and occupies storage for as long as the corresponding object is in
memory.
Class variables: These variables are explicitly defined within the class-level scope with
a static modifier (for example, is Class Used). No other variables can have a
static modifier attached to them. Because these variables are defined with
the static modifier, there would always be a single copy of these variables no matter how
many times the class has been instantiated. They live as long as the class is loaded in
memory.
Parameters or Arguments: These are variables passed into a method signature (for
example, parameter). Recall the usage of the args variable in the main method. They are
not attached to modifiers (i.e. public, private, protected or static) and they can be used
everywhere in the method. They are in memory during the execution of the method and
can't be used after the method returns.
Local variables: These variables are defined and used specifically within the method-level
scope (for example, current Value) but not in the method signature. They do not have any
modifiers attached to it. They no longer exist after the method has returned.
9. OPERATORS
Unary operators are those operators that
operate on a single variable, such as increment
and decrement (++), positive and negative signs
(+ –), the bit-wise NOT operator (~), the
logical NOT operator (!), parentheses, and the
new operator.
Arithmetic operators are those operators used
in mathematical operations. Here it is important
to note that this table is read from left to right,
therefore multiplication and division have
greater precedence than addition and
subtraction.
10. Assignment operators includes the familiar
assignment (=) operator as well as a set of
additional assignment operators referred to
generically as op= (operator equal). These new
operators are shortcut operators used when
performing an operation on a variable and
assigning the result back to that variable.
Ternary operator is rarely used, and is mainly
inherited from Java's initial syntactical base
from C/C++. It is a somewhat cryptic shortcut,
but is perfectly legal
11. DECISION MAKING
If – The Conditional
The if statement evaluates an expression and if that
evaluation is true then the specified action is taken
if ( x < 10 ) x = 10;
If the value of x is less than 10, make x equal to 10
It could have been written:
if ( x < 10 )
x = 10;
Or, alternatively:
if ( x < 10 ) { x = 10; }
12. If… else
The if … else statement evaluates an expression and performs one
action if that evaluation is true or a different action if it is false.
if (x != oldx) {
System.out.print(“x was changed”);
}
else {
System.out.print(“x is unchanged”);
}
Nested if … else
if ( myVal > 100 ) {
if ( remainderOn == true) {
myVal = mVal % 100;
}
else {
myVal = myVal / 100.0;
}
}
else
{
System.out.print(“myVal is in range”);
}
13. else if
Useful for choosing between alternatives:
if ( n == 1 ) {
// execute code block #1
}
else if ( j == 2 ) {
// execute code block #2
}
else {
// if all previous tests have failed, execute code
block #3
}
14. A Warning…
WRONG!
if( i == j )
if ( j == k )
System.out.print(
“i equals k”);
else
System.out.print(
“i is not equal to j”);
CORRECT!
if( i == j ) {
if ( j == k )
System.out.print(
“i equals k”);
}
else
System.out.print(“i is not equal to j”); //
Correct!
15. The switch Statement
switch ( n ) {
case 1:
// execute code block #1
break;
case 2:
// execute code block #2
break;
default:
// if all previous tests fail then
//execute code block #4
break;
}
16. The for loop
Loop n times
for ( i = 0; i < n; n++ ) {
// this code body will execute n times
// ifrom 0 to n-1
}
Nested for:
for ( j = 0; j < 10; j++ ) {
for ( i = 0; i < 20; i++ ){
// this code body will execute 200 times
}
while loops
while(response == 1) {
System.out.print( “ID =” + userID[n]);
n++;
response = readInt( “Enter “);
}
17. do {… } while loops
do {
System.out.print( “ID =” + userID[n] );
n++;
response = readInt( “Enter ” );
}while (response == 1);
A break statement causes an exit from the innermost
containing while, do, for or switch statement.
for ( int i = 0; i < maxID, i++ ) {
if ( userID[i] == targetID ) {
index = i;
break;
}
} // program jumps here after break
18. Continue
Can only be used with while, do or for.
The continue statement causes the innermost loop to start the
next iteration immediately
for ( int i = 0; i < maxID; i++ ) {
if ( userID[i] != -1 ) continue;
System.out.print( “UserID ” + i + “ :” +
userID);
}