Sie sind auf Seite 1von 19

Enterprise Computing

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 is platform independent Object oriented programming language similar to C++ in syntax

Structure of Java Programs

class class-name { public static void main(String args[]) { statement1; statement2;

Example Program class first {

public static void main(String args[]) { System.out.println(Hello World); }

Compiling & Running the Program

Compiling: is the process of translating source code written in a particular programming language into computer-readable machine code that can be executed. $ javac This command will produce a file First.class, which is used for running the program with the command java. Running: is the process of executing program on a computer. $ java First

About Printing on the Screen

1. System.out.println(Hello World); outputs the string Hello World followed by a new line on the screen. 2. System.out.print(Hello World); - outputs the string Hello World on the screen. This string is not followed by a new line.

3. Some Escape Sequence

\n stands for new line character \t stands for tab character

Some Tips About Programming

Some common errors in the initial phase of learning programming: - Mismatch of parentheses - Missing ; at the end of statement

- Case sensitivity
The best way to learn programming is writing a lot of programs on your own.

1. Write a program which prints the following information about at least 5 persons:





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

we print '\\' with System.out.println() statement?\"" );

Storing data
In Java, Data can be stored as
Numbers 2, 6.67, 0.009 Characters c, p, ?, 2 Strings data, Hindi language, $99,

// 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

Used to explain/describe what is done in the program Good practice

Types of numbers
Whole numbers like 0, 575, -345 etc.

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).

Needed only once in one program Generally, done initially Syntax

datatype name;

double total; // stores the total value int index; int a,b,c,sum,interest;

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


Storage area

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 ! );