Sei sulla pagina 1di 98

1

TCS Confidential
Introduction to Java
(Genesis & Basics)
Java Programming
2
TCS Confidential
Genesis of Java
What is Java?
Java Buzzwords
Java API and JVM
Data Types in Java
Conditional Statements and Constructs
3
TCS Confidential
What is Java?
Java is a programming language
developed by Sun Microsystems in 1991
Its the current hot language
Its almost entirely object-oriented
It has a vast library of predefined objects
and operations
It is platform (OS/Hardware) independent
4
TCS Confidential
Pre-requisite For Java Execution
JDK 1.3 or above (Java Development
Toolkit)
Download the JDK version compatible with
your operating system (Windows, Unix,
Linux etc) from http://java.sun.com
Execute Setup.exe File in your JDK kit for
installing Java Development/Execution
environment in your machine.
5
TCS Confidential
Writing a Java Program
public class Suryodaya{
public static void main(String args[])
{
System.out.println(Welcome to Suryodaya!);
}
}
Executing a Java program is a two step process
Compilation (javac)
Execution (java)
6
TCS Confidential
How to Compile the Java Program?
Type the program using Notepad or DOS
editor and save it as Suryodaya.java.
Java being case sensitive, Suryodaya is
different from suryodaya Now type -
c:\jdk1.3>bin> javacSuryodaya.java
Suryodaya.class file is created on
successful compilation.
7
TCS Confidential
How to Run the Java Program?
Once the class file is created, type the
following command at the prompt to run the
program:
c:\jdk1.3>bin>java Suryodaya
Setting the CLASSPATH
The output is:
c:\jdk1.3>bin>
Welcome to Suryodaya!
8
TCS Confidential
The Java Buzzwords
Simple
Object-oriented
Portable
Secure
Robust
Multithreaded (will be discussed in later sessions)
Interpreted (will be discussed in later sessions)
9
TCS Confidential
Simple
Javas syntax is similar to that of C++
Features that led to complexity and
ambiguity were removed (For Ex:)
Simple and easy to learn language
Java = C++ - Complexity & Ambiguity
+ Security & Portability
10
TCS Confidential
Object Oriented
OO Programming is a powerful paradigm -
complex programming problems can be
reduced to simple solutions (For Ex:)
Everything in Java (except the primitive
data types) is an object
11
TCS Confidential
Portable
Goal of Java: Write once, run anywhere,
anytime, forever! How?
Javas Magic: The Bytecode & JVM
Java Complier always converts a .java file
(High level language) into a Generic format
commonly know as bytecode, .class file
JVM ,specific to OS (Windows, Unix, Linux
etc) then interprets this .class file and
executes the bytecode
12
TCS Confidential
What is Java Virtual Machine (JVM)?
JVM is simply the interpreter and the
classes that are needed to run the Java
bytecode.
Byte codes are not compiled with the
knowledge of underlying hardware/OS, the
JVM is always machine specific and knows
how the underlying OS works.
13
TCS Confidential
Java Program Execution
Java
Source
Code
Java Bytecode
Compiler
Java
Bytecodes
Java
Bytecode
Moved
Bytecode Verifier
(Verifies that the byte
codes are from J ava
compiler or not)
Java Class
Library
Java Class
Library
Java Virtual Machine
Java Virtual Machine
Java Interpreter
Java Interpreter
Runtime System
(Executable Code)
Runtime System
(Executable Code)
Operating System
Operating System
Hardware
Hardware
Class Loader
Rejected
Exceptions handled
Rejected
2
1
3
4
5
6
7
8
9
Suryodaya.java
Suryodaya.class
14
TCS Confidential
Secure
Java was designed to be a safe language.
Its powerful security mechanism acts at
four different levels of system architecture:
Security by Complier
Security by Class Loaders
Java Virtual Machine
Using Java API
15
TCS Confidential
Robust
Strictly Typed Language (For Ex:)
Memory Management (For Ex:)
Exceptional handling (For Ex:)
16
TCS Confidential
Robust ...
Example of Exception Handling:
try{
float i = a / b; // if b=0
}
catch(Exception e) {
System.out.println(Dividing by Zero is not allowed+e);
}
finally{ }
17
TCS Confidential
Java API
Java API or Application Program Interface
contains class libraries needed or called by
the application programs at run-time.
Java APIs can be downloaded from
http://java.sun.com
Java API For:
J2SE (Standard Edition)
J2EE (Enterprise Edition)
J2ME (Micro Edition)
18
TCS Confidential
Java API
J2SE (Standard Edition): Core Java
J2EE (Enterprise Edition): Advance Java
(Servlets, EJBs, JSPs etc)
J2ME (Micro Edition): PDA / Mobile
Applications Libraries etc..
19
TCS Confidential
Diagrammatic Representation JAVA
Platform
Java API
Java Applications
Java Virtual Machine
Hardware
Java
Code
Native
Code
Foundation
Classes
Network and
I/O Classes
Abstract Window
Toolkit (AWT)
20
TCS Confidential
Understanding Java Programming
Fundamentals
public classSuryodaya {
public static void main(String args[])
{
if(args.length > 0)
{
System.out.print(Welcome ::);
for(int i=0; i<args.length; i++)
System.out.print(args(i));
}
}
}
21
TCS Confidential
Understanding Java Programming
Fundamentals
The name of the program can be anything,
but should begin with a letter and may
contain digits but no blanks.
The word publicmeans that the contents of
the block are accessible from all other
classes.
The word static means that the defined
method is applied to the class itself rather
than to the objects of the class.
22
TCS Confidential
Understanding Java Programming
Fundamentals
The word voidmeans that the method main
has no return value.
The word main is the name of the method
being defined.
String args[] is a parameter to the method.
It is an array of objects of Stringtype.
System.out.println tells the system to print
the message: Welcome::
23
TCS Confidential
Understanding Java Programming
Fundamentals
The word println is the name of the
method that tells the system to position
the cursor at the beginning of the next line
after the message is printed
24
TCS Confidential
Basics in Java (Self Reading)
Data Types, Variables, Literals
Simple Data Types
Type Conversion and Casting
Automatic Type Promotion
Arrays
Operators
Arithmetic, Bitwise, Relational, Boolean,
Assignment, ?
Operator Precedence and Associativity
Control Statements
Selection and Iteration
25
TCS Confidential
Data Types (Self Reading)
There are two data types in Java:
Primitive
Reference
Java defines eight primitive types of data:
byte, short, int, long, char, float, double,
boolean
Java defines 3 reference data types
arrays, classes, Interfaces
26
TCS Confidential
Primitive Data Types (Self Reading)
3.4e-38 to 3.4e+38 32 float
1.7e-38 to 1.7e+38 64 double
-128 to 127 8 Byte
+32,768 to -32,767 16 short
-2,147,483,648 to +2,147,483,647 32 int
+9,223,372,036,854,775,808 64 long
Range Width Name
27
TCS Confidential
Primitive Data Types (Self Reading)
true or false 32 boolean
0 to 65,535 16 char
Range Width Name
28
TCS Confidential
Variables (Self Reading)
Variables can be defined as memory units
into which data is stored. There are two
basic parameters used to define a variable:
Identifier or name
Type or category
Assigning a value to a variable at the time
of declaration is optional
Apart from this, variables have a scope
which defines their lifetime and visibility.
29
TCS Confidential
Literals (Self Reading)
A literal is a simple value where what you
type is what you get. Numbers,
characters and Strings are all examples of
literals.
Literals are constant data values.
Examples:
100 98.6 x This is a test ox98
30
TCS Confidential
The Scope and Lifetime of Variables
Two major scopes:
Scope by Class
Scope by Method
Scope by Block
Variables declared inside a scope are not
visible (that is, accessible) to the code that
is defined outside that scope
31
TCS Confidential
Example - Usual Scope and Lifetime
classScope{
public static void main(String args[]) {
int x; // known to all code within main
x = 10;
if (x ==10) { // start new scope
int y =20; // known only to this block
// x and y both known here
System.out.println(x and y: + x + + y);
x = y*2; }
y=100; // Error: y not known here
// x is still known here.
System.out.println(x is + x); } }
32
TCS Confidential
Type Conversion And Casting
Type conversion is converting one data
type to another.
Conversion may be:
Automatic (Implicit)
Casting (Explicit or Forced)
33
TCS Confidential
Automatic Type Conversion
An automatic type conversion will take
place if the following two conditions are
met:
The two types are compatible.
The destination type is larger than the source
type.
When these two conditions are met, a
widening conversion takes place (byte to
short, int, long).
34
TCS Confidential
Automatic Type Conversion
Examples of Automatic type conversions:
int a; byte b; a = b;
long l; int I; l = I;
double d; float f; d = f;
float f; int i; i = f;
35
TCS Confidential
Casting Incompatible Types
Explicit or forced type conversion.
General form: (target-type) value
target-type specifies the desired type to
convert the specified value to
Example:
int a; byte b; b = (byte) a;
Usually a narrowing conversion requires
type cast.
36
TCS Confidential
What are Arrays?
An array is defined as a group of like typed
variables referred to by a common name.
Like variables, it is essential to specify the
following for declaring an array:
Data values (int , float)
Identifier for the array
Elements of an array cannot be accessed
using pointer arithmetic
37
TCS Confidential
How to Declare Arrays?
Example
float basicSalary[ ]; // Array declaration
basicSalary = new float[10]; // Refers to a
float array
// Allocating space
new operator automatically allocates the
array and initializes its elements to zero.
38
TCS Confidential
Assigning Values
NULL is assigned for an array of objects.
Array elements cannot be accessed till their
values are inserted.
Example: double nums[ ] = { 10.1, 11.2, 12.3,
13.4, 14.5 };
Above syntax does 3 things at a time:
Declaration of array
Allocation of space
Initialization of array with 5 elements.
39
TCS Confidential
How to Declare Multi-dimensional
Arrays?
Multidimensional arrays are arrays of arrays.
Examples:
1.Assume that a two dimensional array of
two rows and three columns has to be
declared:
int multiTwo[ ] [ ] = newint[2][3];
2.Initializing a 2x3 integer array:
int [ ] [ ] a = { {77, 22, 44}, {11, 33, 88}};
40
TCS Confidential
Example - One-dimensional Array
classAverage {
public static void main(String args[ ]) {
doublenums[] ={10.1, 11.2, 12.3, 13.4, 14.5};
doubleresult = 0;
for (int j = 0; j < 5; j++)
result = result + nums[j];
System.out.println(average is +result / 5); }
}
41
TCS Confidential
Declaring Arrays
It is not essential in Java to allocate the same
number of elements in each dimension:
Example: int multiTwo[ ][ ] =newint [3][ ];
multiTwo[0] = newint[1];
multiTwo[1] = newint[2];
multiTwo[2] = newint[3];
[0][0]
[1][0] [1][1]
[2][0] [2][1] [2][2]
One element in row 0
Two elements in row 1
Three elements in row 2
42
TCS Confidential
Example - Two-dimensional Array
classShowArray{ int p;
public static void main(String args[]) {
int twoD[][] = new int[4][5];
for (int j = 0; j < 4 ; j++) {
for (int k = 0; k < 5; k++) {
twoD[j][k] = p++;
System.out.println(twoD[j][k] + );
}
}}
}
43
TCS Confidential
Understanding Strings
String: Stringis not a simple data type like
an array of characters but a complete
object on its own.
Arrays of Stringcan also be declared.
Example: class FirstString {
public static void main (String args[ ] ) {
String str = My first string in Java;
System.out.println(str); }}
44
TCS Confidential
Operators in Java (Self Reading)
Type
Description Symbol Usage
Arithmetic
Addition
subtraction
multiplication
division
modulus
increment
decrement
assignment
+
-
*
/
%
++
+= -= /=
*= %=
int no = 3 + 2
int no = 3 - 2
int no = 3 * 2
int no = 3 / 2
int no = 3 % 2
no++ or ++no
no += 4; same as
no = no + 4; etc.
-- no-- or --no
45
TCS Confidential
Operators in Java ... (Self Reading)
Type
Description Symbol Usage
bitwise
NOT
a = 2
Binary Rep: 10
~a = 01 // Decimal 1
AND
~
&
b = 3
Binary Rep: 11
a & b = 10 // Dec. 2
OR |
a | b = 11 // Dec. 3
Exclusive-OR
^
a ^ b = 01 // Dec. 1
Shift left / right << / >>
byte a = 64, b;
b= (byte)(a << 2); //0
int i = a << 2; // 256
int c = 35 >> 2; // 8
int d = -8 >> 1; //-4
46
TCS Confidential
Operators in Java ... (Self Reading)
Type Description Symbol
Relational
Equal to
Not equal to
Greater than
Less than
Greater than or equal to
Less than or equal to
==
!=
>
<
>=
<=
Bitwise
Assignments
~= &= |=
^= <<= >>=
int a=1, b=2, c=3; a |= 4;
b >>= 1; c <<= 1; a ^= c;
(answers: a =3 b=1 c=6)
Unsigned Right
Shift
>>>
Always shifts zero
into high order bits
47
TCS Confidential
Operators in Java ... (Self Reading)
The ? Operator
A special ternary operator that can replace
certain types of if-then-else statements:
ratio = denom == 0 ? 0 : num / denom;
Difference between & and &&, | and ||
& and | are the logical AND and OR.
&& and || are the Short-circuit AND and OR.
48
TCS Confidential
Precedence of the Java Operators (Self
Reading)
( ) [ ]
++ -- ~ !
* / %
+ -
>> >>> <<
> >= < <=
== !=
&
^
|
&&
||
?:
= op=
Highest
Lowest
49
TCS Confidential
Control Statements
A program does not always follow a simple
sequence. There are always chances of
having to choose from several alternatives
or to repeat a certain set of steps. That is
where the various programming constructs
that a programming language provides
come to aid.
50
TCS Confidential
If Statement
The if-elsestatements can be nested as shown below. It is
normally used when more than one condition needs to be
tested.
if (score >100) { // Nested-if
if (score >250)
System.out.println(Excellent score);
else system.out.println(Good score);
}else system.out.println(Bad score);
if (score >250) // if-else-if Ladder
System.out.println(Excellent Score);
else if (score >100)
System.out.println(Good Score);
else System.out.println(Bad Score);
51
TCS Confidential
Selection Constructs
Selection Statements:
if , if-else, andif-else-if
switch-case
if Statement
if (score >100 ) {
System.out.println(Good Score);}
else{
System.out.println(Bad Score);}
52
TCS Confidential
switch Statement
Switch statement are used to reduce the
complexity and compound conditions in if-
else statements
A switch statement can be nested into
another switch statement .
Switch statement defines its own blocks.
Hence no conflicts arise between
constants in the inner blocks and those in
the outer blocks.
53
TCS Confidential
switch Statement
switch (score) {
case 300:
System.out.println(Excellent Score);
break;
case 200:
System.out.println(Good Score); break;
default: System.out.println(Bad Score);
}
If there is no break statement after each
case then all cases are executed
54
TCS Confidential
Iteration Constructs
Javas iteration statements are while, do-while
and for.
whileStatement
i = 0; found = false;
while (found == false && i < length)
{
// where i is the array index
if (Array[i] == str) found = true;
i++;
}
55
TCS Confidential
Iteration Constructs ...
do-whileStatement
i=0; found = false;
do{
if (Array[i] == str) found = true;
i++;
} while (found == false && i < length);
for Statement
// Execution over a range of integer values
for(i = 0 ; i < length ; i++)
{if (Array[i] == str) break;} // breakto exit a loop
56
TCS Confidential
Summary
We discussed the following in this session:
Genesis of Java
Java Buzzwords
Java API and JVM
Basics in Java
Data Types, Variables, Literals, Arrays
Operators
57
TCS Confidential
Assignments (Mandatory to submit)
Exercise 1:
Write a Java program that initializes two arrays
with the following products and their prices, and a
method that will display the same.
Chips 10 Hangers 75
Apples 10 Pens 10
Mangoes 12 Corn Flakes 19
Towels 125 Oats 22
Room Freshner 150 Tooth Paste 50
58
TCS Confidential
Assignments (Mandatory to submit)
Exercise 2:
Write a program for the problem: An array of integers
indicating the marks of students is given, You have
to calculate the percentile of the students according
to the rule: The percentile of a student is the %of no
of students having marks less then him.
For example: Suppose Student A,B,C,D,E,F secure
12,60,80,71,30,45 respectively
Percentile of C = 5/5 *100 = 100 (out of 5 students 5 are having
marks less then him)
59
TCS Confidential
Object-Oriented Programming in Java
60
TCS Confidential
Object-Oriented Programming in Java
The Three OOP Principles
Classes, Objects
Methods with Parameters
Constructors
The Keywords: static, final
finalize( ) Method
Overloading and Overriding Methods
61
TCS Confidential
The Three OOP Principles
Encapsulation
Is the mechanism that binds together code and
data it manipulates, and keeps both safe from
the outside interference and misuse
Inheritance
Is the process by which one object acquires the
properties of another object
Polymorphism
Is a feature that allows one interface to be used
for a general class of actions
62
TCS Confidential
Bank Module
Definition: Create a Bank application
which supports all elementary functions
like deposit, withdraw, checking balance,
interest calculation, transaction details
etc
63
TCS Confidential
Bank Module
Bank
Customers
Accounts
Savings Account Current Account
64
TCS Confidential
Step_1 Identifying Physical Entities
Each Physical entity contains attributes
that defines its state at any point of time.
Identify the Physical Entities:
Bank
Customer
Account (Savings / Current)
65
TCS Confidential
Step_2 : Defining Attributes
Account Entity:
Account ID
Account Type
Account Balance
Customer Entity:
Customer ID
Customer Name
Customer Address
Bank Entity:
Bank ID
Bank Name
Branch Name
Address
66
TCS Confidential
Encapsulation
Data Encapsulation
Data Items
Methods
Car
67
TCS Confidential
What are Classes?
Classes are templates on which objects
model themselves. They contain data-items
and the methods that are needed to
manipulate the former.
Classes are blue-prints that define the
variables and the methods common to all
objects of a certain type.
Class variables define the attributes of a
class and are called fields.Instance
variables define the attributes of an object.
68
TCS Confidential
What are Objects?
Objects are instance of classes.
69
TCS Confidential
Step_3 of Building the Account Class
(Encapsulation)
public class Account
{
privateint accountId,balance,custId;
Account (int accountId,int custId,int balance)
{
this.accountId = accountId;
this.custId = custId;
this.balance = balance;
}
publicvoid printAccountDetails()
{ .} continue in next slide.
70
TCS Confidential
publicboolean isAccountActive()
{.}
publicint depositAmount (int depAmount)
{.}
publicint withdrawAmount (int debitAmount)
{.}
publicint getMinBalanceReq()
{}
}
Step_3 of Building the Account Class
(Encapsulation)
71
TCS Confidential
Inheritance
A class once defined can be used by other
classes whenever required. It does not need
to be redefined again and again.
The derived class automatically inherits the
members of the parent class and adds to
them new methods and data members thus
increasing the functionality of the parent
class.
SuperClass
SubClass
Inherits From Super
72
TCS Confidential
Step_4 of Building the SavingsAccount Class
(Inheritance)
class SavingsAccount extendsAccount
{
private String accType = SA;
SavingsAccount (int accountId, int custId, int balance)
{
super(accountId, custId, balance) ;
}
continue in next slide.
73
TCS Confidential
public int getMinBalanceReq()
{
return 2000;
}
}
Step_4 of Building the SavingsAccount Class
(Inheritance)
74
TCS Confidential
Step_5 of Building the SavingsAccount Class
(Polymorphism)
class SavingsAccount extends Account
{
private String accType = SA;
SavingsAccount (int accountId, int custId, int balance)
{
super(accountId, custId, balance) ;
}
continue in next slide.
75
TCS Confidential
public int getMinBalanceReq()
{..}
/*By default 30 days duration*/
public void getTransactionData()
{ .}
/*Duration will be passed in parameter*/
public void getTransactionData(int duration)
{ .}
}
Step_5 of Building the SavingsAccount Class
(Polymorphism)
76
TCS Confidential
Creating Objects
Memory needs to be allocated for the object so that
a reference can be returned to it and stored in the
variable sAcc in this case.
The newoperator is used to dynamically allocate
memory to the object
SavingsAccount sAcc;
sAcc = newSavingsAccount (1,1,2500);
An alternate way is :
SavingsAccount sAcc = newSavingsAccount (1,1,2500 );
77
TCS Confidential
Methods With Parameters
Methods are capable of accepting
parameters that can be passed in the
following ways:
By value: Normally all parameters (except
Objects) are passed by value only
By reference: When an object is passed
as a parameter, it is passed as a reference
to the method. In reality, the reference to
the object is passed by value.
78
TCS Confidential
public class TestArguments
{
class BalanceDetail {
int balance;
BalanceDetail(int bal) { ..}
void printData() { }
}
public void passByValue(int bal)
{..... }
public void PassByReference(BalanceDetail balObj )
{. } continue in next slide.
Example Of Pass By
Value and
Pass By Reference
79
TCS Confidential
public static void main(String[] args)
{
TestArguments Obj1 = new TestArguments();
BalanceDetail balObj = new BalanceDetail();
Obj1.passByValue(10);
Obj1.PassByValue(10);
Obj1.PassByReference(balObj);
}
}
80
TCS Confidential
Constructors
Constructors initializes the values of object
at the time of creation.
A constructors is a special public method
with no return type (not even void), with or
without parameters, and with the same
name as the class.
If a constructor is not explicitly defined in a
class, Java automatically defines a default
constructor
81
TCS Confidential
A Parameterized Constructor
class SavingsAccount extends Account
{
private String accType = SA;
SavingsAccount (int accountId, int custId,
Int Balance)
{
super(accountId, custId, balance) ;
}
continue in next slide..
82
TCS Confidential
public float interest(int time,int rateOfInt)
{
return balance*time*rateOfInt*0.01;
}
}
A Parameterized Constructor
83
TCS Confidential
static methods and variables
At times one wants to define a class member
that will be used independently of any object of
that class. A static method can be used by itself
with the following restrictions:
A static method can call only other static methods
They may access only static data
They cannot refer to the keywords thisor superin any way
Variables declared as static do not occupy
memory on a per-instance basis
84
TCS Confidential
final Keyword
A final variable is essentially a constant:
final intFile_Open = 2;
Value of a final variable cannot be modified
after its initialization
85
TCS Confidential
The finalize( ) Method
Sometimes an object will need to perform
some action when it is destroyed.
Using the finalize( ) method, specific
actions can be defined that can occur just
before an object is reclaimed by the
garbage collector.
protected void finalize( )
{// finalize code here
}
86
TCS Confidential
Overloading Methods
A set of methods, having the same name
but different set of parameters can be
defined in the same class.
To external methods and data members it
would serve as one interface.
This phenomenon is termed as method
overloading.
87
TCS Confidential
Demo of OverLoading.java
classOverLoading { // Overloading Methods
static voidadd( ){
System.out.println(No parameters passed");}
static voidadd( double pnum){
System.out.println(Parameter = + pnum);}
static voidadd(int pnum1, int pnum2){ int result;
result = pnum1 + pnum2;
System.out.println(Integer sum = + result);}
static voidadd(float pnum1, float pnum2) {
float result; result = pnum1 + pnum2;
System.out.println(Float sum = + result); }
88
TCS Confidential
OverLoading.java ...
public static void main(String args[ ]) {
add( ); // no parameter.
add(20, 45); // 2 integerparameters.
add(30.5f, 40.5f); // 2 floatparameters.
add(45); // integer parameter is
} // elevated to type double.
}
Output
No parameters passedInteger sum = 65
Float sum = 71.0 Parameter = 45.0
In essence, method overloading is compile-time
polymorphism.
89
TCS Confidential
Method Overriding
In a class hierarchy, when a method in a
subclass has the same name and
signature as a method in its superclass,
then the method in the subclass is said to
override the method in the superclass.
90
TCS Confidential
class SavingsAccount extends Account
{
private String accType = SA;
SavingsAccount (int accountId, int custId, int balance)
{
super(accountId, custId, balance) ;
}
public int getMinBalanceReq() { return 2000; }
continue in next slide..
Method Overriding ...
91
TCS Confidential
Method Overriding ...
public int withdrawAmount (int debitAmount)
//Method overridden by Child Class
//This method is already defined in parent class
{
if( (balance debitAmount) > getMinBalanceReq() )
balance = balance debitAmount;
else
System.out.println(Minimum Balance Of +
getMinBalanceReq() + is required);
} continue in next slide
92
TCS Confidential
Method Overriding ...
public void getTransactionData(int
duration) /*Duration will be passed in
parameter*/
{ .}
}
93
TCS Confidential
Assignments
Exercise 3:
[Aim: Using Command-line arguments & Input from
keyboard]
Write a JAVA program to generate n prime numbers
greater than a given value. Read n from the keyboard
and supply the threshold values as command-line
arguments.
94
TCS Confidential
Assignments
Exercise 4:
Define a class called Complex containing two class
variables real and imagof type double. Define
methods, readC() and displayC() for reading a
complex number from keyboard and displaying it on
screen.
Also define methods for arithmetic operations,
addC(), subC(), mulC(), and divC() (add, subtract,
multiply, divide). Write a program to read two
complex numbers. Display the result of each
arithmetic operation on the two numbers
95
TCS Confidential
Instructions For Assignments
The given assignments are mandatory to
submit
We request all college co-ordinators to ensure
that assignments from the college are
submitted in a single .zip file by Wednesday,
11/10/2006
96
TCS Confidential
Instructions For Assignments
Folder Structure in .zip file:
College Name - Branch Name -
Students Roll No. - Programs
Email your assignments at suryodaya@tcs.com
with subject line as:
Assignments: (Java) Session Date (dd/mm/yyyy).
97
TCS Confidential
Whats Next???
Object Oriented Programming II
Java Database Connectivity (JDBC)
98
TCS Confidential
Question & Answers

Potrebbero piacerti anche