Académique Documents
Professionnel Documents
Culture Documents
Learning Objective
At
the end of this course you should be able to design and implement real life computer programs using Java.
Main Reading
Teach Yourself Java 2 platform by Laura Lemay, and Rogers Cadenhead, Techmedia India, 1999. ISBN 81-7635-243-8. Program Design, 4th edition by Peter Juliff, Prentice Hall India, 2000. ISBN-81-2031622-3. The Java Handbook by Patrick Naughton, Tata McGraw-Hill India, 2001. ISBN 0-07463290-6. Java 2 The Complete Reference Fifth Edition by Herbert Schildt
Web Reading
Thinking in Java (3rd Edition) Bruce Eckel (Downloadable) http://www.mindview.net/Books/TIJ/ Official Sun Java site (Downloadable) http://java.sun.com/docs/books/tutorial/in dex.html
Evaluation Criteria
Assignments - 10%
Project - 10%
Project
Introduction
The purpose of the system is to provide the facility for the bank to give the services to the customers. In general scenario the bank is facing so many problems while doing the transactions in manually. To overcome such problem you have to develop a system called banking system to facilitate the bank needs.
Introduction to Java
Java was developed by James Gosling at Sun Microsystems in 1991. The Java language was successfully used to develop a web browser called WebRunner and Java/Hotjava project was commenced. In December 1995, beta version2 of Java was released.(Experimental level)
Introduction to Java
On January 23, 1996 Java 1.0 was officially released and made available to download over the net. Latest version of Java 6 SDK and Documentation can be downloaded at Java.sun.com
Java Buzzwords
Simple Object-oriented Distributed Interpreted Robust Secure Architecture-neutral Portable High performance Multithreaded Dynamic
10
Introduction to Java Development Kit (JDK) JDK provides core set of tools that are necessary to develop professional Java applications JDK tools are also written in Java.
11
Java Tools
The Java Compiler (javac) The Java Interpreter (java) The Java Debugger (jdb) The Java Documentation Tool (javadoc) The Java Disassembler (javap) The Appletviewer (appletviewer) The RMI Stub Compiler (rmic) The RMI Remote Object Registry (rmiregistry) The Serial Version Command (serialver) The Native to Ascii Converter (native2ascii) The Java Archive Tool (jar) The Java Security Tool (javakey)
12
Java Terminology
Java Virtual Machine (JVM) set of computer software programs and data structures that use a virtual machine model for the execution of other computer programs and scripts. Java Runtime Environment (JRE) A runtime environment which implements Java Virtual Machine, and provides all class libraries and other facilities necessary to execute Java programs. This is the software on your computer that actually runs Java programs.
13
14
15
The Java platform has two components: The Java Virtual Machine The Java Application Programming Interface (API)
16
Java Platforms
There are three main platforms for Java: Java SE (short for Standard Edition) runs on desktops and laptops
Java ME (short for Micro Edition) runs on mobile devices such as cell phones
Java EE (short for Enterprise Edition) runs on servers
17
class ILikeJava { public static void main(String[] args) { System.out.println(I Like Java); } }
Java Compiler
Java Liibrary
01101001010101 10111101010111
Java Interpreter
18
Creating a Java Source File Any plain text editor or text editor capable of saving in ASCII format can be used to create a Source file(Notepad) Source File should be saved with a .java extension This is very important java source file must have the same name as the class they define (including the same upper- and lowercase letters) Save the file somewhere on your disk with the name Hello.java for the following program.
/* This program display I Like Java on the computer Screen */ class Hello{ public static void main(String[] args) { System.out.println(I Like Java); } }
19
20
C:\Practical>Javac Hello.java
Java Compiler will create a Java byte code file
Java Compiler
C:\Practical>Java Hello
Interpreter Execute the Java Byte code class file
Java Interpreter
Class Name
22
Comment- The contents of a comment are ignored by the compiler. Three type of comment in java. 1. //text // This comment extends to the end of the line. // This type of comment is called a "slash-slash" comment
23
/* text */ /* This comment, a "slash-star" comment, includes multiple lines.*/ 3. /** documentation */ /** The last type of comment is the Javadoc comment. This comment type has some guidelines that allows a Javadoc reader to display information about a Java method or class by using special tags: @param myNum - describe what the parameter myNum is used for @return - describe what this method returns 24 */
2.
keyword class to declare that a new class is being defined. Hello is an identifier that is the name of the class. The main( ) method is simply an entry point for an application.
25
Exercise: Write a simple Java program which displays following two lines on the screen. I like Java programming. So I do practical.
26
Progress Check
1. Where does a Java program begin execution? 2. What does System.out.println( ) do? 3. What is the name of the Java compiler? Of the Java interpreter?
27
Progress Check
Answers 1. main( ) 2. Outputs information to the console. 3. The standard Java compiler is javac.exe; the interpreter is java.exe.
28
Write a simple Java program which adds 12 and 13, and displays the result on the screen.
class Addition { public static void main(String[] args) { int a=12; int b=13; int c; c=a+b; System.out.println(a+b=+c); } }
29
Statements
Statements are used to accomplish simplest tasks in Java forms simplest Java operations. can be single line or Span to multiple lines. does not necessarily return a value.
System.out.println(a+b=+c);
30
Expressions
Expressions simplest form of Statements. returns a value when evaluated. can be assigned to a variable or can be tested in Java statements. most expressions are a combination of Operators & Operands
c=a+b;
31
Variables
What is a Variable ? Variables are locations in memory in which values can be stored. Each Variable has a Type, Name and a Value After Declaring, it can be used to store values of the appropriate Type
int a=12;
32
Variables
Variables can be of reference type or Primitive Type. There are Eight Primitive Data Types in Java. Integer Types (4) Character Floating Point types (2) Boolean Why does Java have different data types for integers and floating-point values? That is, why arent all numeric values just the same type?
33
Variables
Integer Types
Type Byte Bit Size 8
16 32 64
double
64
34
Variables
Primitive Data Types
Data Type Size Min Value
-128
-32768 -2147483648
Max Value
127
32767 2147483647
byte
short int
8 bits
16 bits 32 bits
long Float
double char
64 bits 32 bits
64 bits 16 bits
-9223372036854775808
1.40239846E-45 4.94065645841246544E-324 \u0000
9223372036854775807
3.40282347E+8 1.79769313486231570E+ 308 \uFFFF
boolean
n/a
True or False
35
Variables
Reference Data Type
36
Variable
class Variables { public static void main (String args[]) { boolean b = true; int low = 1; long middle = 74; float pi = 3.1415292; double e = 2.71828; char s = a; System.out.println() //print the values } }
37
Variables
Variable Naming Can only Start with a Letter, Underscore (_) , or Dollar Sign ($) After the first letter Name can include any letter or Number but cannot include Symbols such as %, @, * and so on. Names are Case Sensitive (Value,VALUE and value are different)
38
Variables
Use meaningful Names such as number, areaOfCircle, firstName Convention is to start a variable with a lower case If the name is made up of several words, then from the second word onwards the first letter of the word is capital.
Illegal Names 1More, #Two, @Two Legal Names timeOfDay, temp_val, $_
39
Variable
Write down whether the following variable names are legal? &name _postalCode *age %company Age #$date Address $_month 8year $lastName
40
Variable
Declaring variables
type identifier[= value] [,identifier [=value]]
Class Square{ Public static void main(String args[]) { Double a = 3.5, b = 4.8 ; Double c = a*b ; System.out.println(Value of c is +c); } }
41
class ExampleDiv { public static void main(String args[]) { int var; // this declares an int variable double x; // this declares a floating-point variable var = 10; // assign var the value 10 x = 10.0; // assign x the value 10.0 System.out.println("Original value of var: " + var); System.out.println("Original value of x: " + x); System.out.println(); // print a blank line var = var / 4; x = x / 4; System.out.println("var after division: " + var); System.out.println("x after division: " + x); } }
42
43
Type Conversions
Conversion between integer types and floating point types. this includes char No automatic conversion from or to the type boolean. You can force conversions with a cast . int i = (int) 1.345;
45
Type Conversions
class typeConversion { public static void main(String args[]) { int a = 65; char c = A; double b = 3.5; //a=b; //b=a; //a=c; //c=a; //b=c; //c=b; //a=(int)b; int i = (int) 1.345; System.out.println(i);
}
}
46
Summary
Today we learned History, Features Java statements, expressions and variables
Exercise: Write a simple Java program which divides 12 by 5 and displays the result on the screen. Write a simple Java program multiplies 12.4 and 45678932. You should display the result on the screen up to two decimal points Write a program which converts inches to centimeters (1m= 39 inches)
47
Questions
48
Thank You
49