Académique Documents
Professionnel Documents
Culture Documents
Introduction to Java
Enterprise Architectural overview - object oriented software development for enterprise - Component Based software development for enterprise. Java Enterprise System. Enterprise Data - Basis of JDBC - interfaces -drivers. Advanced JDBC features.
Java
Java is platform independent Object oriented programming language similar to C++ in syntax
Example Program
first.java class first {
- Case sensitivity
The best way to learn programming is writing a lot of programs on your own.
Assignment
1. Write a program which prints the following information about at least 5 persons:
NAME
Raja
MARK1
90
MARK2
95
MARK3
100
Each entry should be on a separate line. 2. Write a program that prints the following line on the screen along with quotes. Can we print \ with System.out.println() statement?
Assignment - Ans
? Print the details in tabular format - use tabs \t
System.out.println("\"Can
Storing data
In Java, Data can be stored as
Numbers 2, 6.67, 0.009 Characters c, p, ?, 2 Strings data, Hindi language, $99, www.rediff.com
Program
// this program will declare and print a number class int2 { public static void main(String[] arguments) { int weight = 52; System.out.println("your weight is " + weight+ " Kg"); } } //end of program
Comments(double slash)
Not executed For documentation Can be placed on any line Anything written after // is not executed E.g.
// this is a comment
Types of numbers
int
Whole numbers like 0, 575, -345 etc.
double
Numbers with decimal point like 12.453, 3.432, 0.0000002
Variable declaration
Before using any name, it must be declared
(with its type i.e int or double).
double total; // stores the total value int index; int a,b,c,sum,interest;
Assignment
int a; //declaration needed once a = 10 ; // assignment declared above
int a = 10; // assignment and declaration together 10 = a ; // not possible compilation error Left hand side is always a variable for assignment
10
Storage area
Assignment
int a , b ; a = 4; b = 7; a = b; b = a; a = 5; // a =? b = ? // a = 4 b = ? // a = 4 b = 7 // a = 7 b = 7 // a = 7 b = 7 // a = 5 b = 7
Character data
Characters a, A, c , ? , 3 ,
(last is the single space)
Enclosed in single quotes Character variable declaration char ch; Character assignment
ch = k;
String data
Strings are sequence of characters enclosed in double quotes Declaration String name; String address; String line; Assignment name = ram; line = this is a line with spaces; name = a; // single character can be stored name = ; // empty string The sequence of characters enclosed in double quotes, printed in println() are also strings. E.g. System.out.println( Welcome ! );