Java
Java
www.proximo.com
Introduction
Present the syntax of Java
Introduce the Java API
Demonstrate how to build
stand-alone Java programs
Java applets, which run within browsers e.g. Netscape
Example programs
Why Java?
Its the current hot language
Its almost entirely object-oriented
It has a vast library of predefined objects and operations
Its more platform independent
this makes it great for Web programming
Its more secure
It isnt C++
HelloWorld (standalone)
Note that String is built in
println is a member function for the System.out class
sum+=i;
Control statements II
Java also introduces the try statement, about which more later
switch(n+1){
case0:m=n1;break;
case1:m=n+1;
case3:m=m*n;break;
default:m=n;break;
}
Java isn't C!
In C, almost everything is in functions
In Java, almost everything is in classes
There is often only one class per file
There must be only one public class per file
The file name must be the same as the name of that public
class, but with a .java extension
What is a class?
Early languages had only arrays
all elements had to be of the same type
Then languages introduced structures (called records, or structs)
allowed different data types to be grouped
Then Abstract Data Types (ADTs) became popular
grouped operations along with the data
Name conventions
Java is case-sensitive; maxval, maxVal, and MaxVal are three
different names
Class names begin with a capital letter
All other names begin with a lowercase letter
Subsequent words are capitalized: theBigOne
Underscores are not used in names
These are very strong conventions!
An example of a class
classPerson{
Stringname;
intage;
voidbirthday(){
age++;
System.out.println(name+'isnow'
+age);
}
}
An array is an object
Personmary=newPerson();
intmyArray[]=newint[5];
or:
intmyArray[]={1,4,9,16,25};
Stringlanguages[]={"Prolog","Java"};
CONTACT US
www.proximo.in
Address: No:3, II Floor, 100
ft
Road,
BTM
Layout,
II
Stage,
Bangalore, Karnataka (560
076) India
Tel: +91 (0)80 4900 1234
Mail: [email protected]
Thanks for
watching