Vous êtes sur la page 1sur 19

Enterprise Computing

Introduction to Java

UNIT I ENTERPRISE FOUNDATIONS

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

Structure of Java Programs


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

Example Program
first.java 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 First.java 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.

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

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

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

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

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;

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

Vous aimerez peut-être aussi