Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
9Activity
0 of .
Results for:
No results containing your search query
P. 1
Java Chap1: Foundation Concepts of Class & Objects (Prof. Ananda M Ghosh.)

Java Chap1: Foundation Concepts of Class & Objects (Prof. Ananda M Ghosh.)

Ratings:

4.0

(1)
|Views: 1,307 |Likes:
Published by Ananda Mohan Ghosh
Object Oriented Programming with Java -- An Introduction
Object Oriented Programming with Java -- An Introduction

More info:

Published by: Ananda Mohan Ghosh on Nov 27, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/29/2012

pdf

text

original

 
Chapter 1:Foundation Concepts of Class and Objects1.0 Introduction
In our everyday life we interact with so many real-life objects like books, friends, chairs, tables, computers, teachers, cars, etc. etc. Interactions with manysuch physical objects become necessary to get our daily work done. For example, you cantell your friend Pradip or Pritima to take out a computer book from a rack and place it onyour reading table so that you can go through that book. Your intention is converted into avoice message, which you pass on to a particular friend of yours. He /She then takesnecessary actions by pulling out the book from the rack and placing it on the specifiedtable. In this simple task, quite a few real objects are involved, such as -- Pradip or Pratima (a member of your 
friend
set), computer-book (a member of the set
book 
); table/rack (a member of the set
furniture
), etc.Pradip or Pratima , as an individual, has name, address, father’s name, schoolwhere he/she goes, class in which he/she reads, etc. Moreover he/she can read/write/speak English, can operate computer, can swim, can sing, etc. Therefore, you can describe anyone of your friends with a number of 
attributes
like name, age, address, ...., etc. and by agroup of activities he/she is capable of doing like writeEnglish(), operateComputer(),giveAddress, tellName, ....., etc.Following the
Object Oriented
 
concept
, we can say that Pratima or Pradip isan
object
 belonging to the
Class
Friend. As you can have many friends, all of them can be described by a common description blueprint (or template) called
Friend.
In the sameway a particular book can be described by a description blueprint called
Book 
whichshould have attributes like book_name, author_name, publisher, price, ..., etc.Thus the blueprint with the help of which many similar objects can be describedand manipulated in an
Object Oriented Program (OOP)
has been given the name
Class
.Like any OOP language, Java takes help of 
class
definitions to create required number of 
software objects
to solve problems by a computer. A class or the objects’ blueprint shouldhave a unique name by calling which a
collection of attributes and methods
(Fig-1.1)can be manipulated as a software unit. 
State
Fig:1.1 A
Class
blueprint 
Behaviour
 
Class Name
Attribute1Attribute2||attributeMMethod1Method2||MethodN
 
As shown in Fig 1.1, a
Class
can be regarded also as a
special data type
whichencapsulates a bundle of 
attributes
(which describes the
State
an Object) and a collectionof 
methods
(exhibiting all common
behaviour
of objects). In a Java program, manysimilar 
objects
can be created from a
Class
definition.
Java
 being an
Object Oriented Programming language
, a java programconsists of one or more Class definitions out of which Objects are created andmanipulated by allowing
messages
(Fig-1.2) to pass in between them.
Class-A Class-B
 
Obj-i.methodx
(p)Message
Fig-1.2 Message passing between two objects
As shown in Fig-1.2,
Obj-k 
intends to get a work done by calling the method
methodx(p)
which
obj-i
is capable of performing. A
message
is normally passed in theform of --
Obj-i.methodx(p)
 -- where
p
stands for the parameter(s) to be passed with the method whilecalling, if any. Method invocation without any parameter passing is quite possible andoften done.
1.1Java Programming and Interactions between Objects
Let us start by writing a very simple java program.
/** Example 1.1 Sum of Two Integers
* class FirstJava* @author (A.M.ghosh)* @version (3.05)*/
class FirstJava
{ public static void
main()
{int x, y;int result;x = 10;y = 20;result = x+y; System.out.
println
(" Value of x + y =" + result);
 
Obj-iObj-
 
}} 
Picture 1.1 Java Source Codes of Example 1.1
If you run this program, the value of (x + y) will be displayed. The classFirstJava has a method
main()
which starts program execution. To display the outputresult, a method --
println() (
available
 
within java library class
System.out)
has beenutilized. 
Picture 1.2 (Top) Executed by clicking void main() menu (bottom) Terminal Windowshowing the output result

Activity (9)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
ankit boxer liked this
bappachandra2011 liked this
Akshara Mehra liked this
Sandy Sinha liked this
GVNGK liked this
taufufa liked this
pan_arshad liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->