"Working With Class Programming in Java": A Term Paper Report On
"Working With Class Programming in Java": A Term Paper Report On
PROFESSIONAL COLLEGE
LUCKNOW
Affiliated to
LUCKNOW UNIVERSITY
ROLLNO: 16065106008
ACKNOWLEDGEMENT
INTRODUCTION
Java is a true OO language and therefore the underlying structure of all
Java programs is classes.
Anything we wish to represent in Java must be encapsulated in a class that
defines the state and behaviour of the basic program components
known as objects.
Classes create objects and objects use methods to communicate between
them. They provide a convenient method for packaging a group of
logically related data items and functions that work on them.
A class essentially serves as a template for an object and behaves like a
basic data type int. It is therefore important to understand how the fields
and methods are defined in a class and how they are used to build a Java
program that incorporates the basic OO concepts such as encapsulation,
inheritance, and polymorphism.
A class is the template for an object and a way to encapsulate both data
(called fields in Java) and the functions (called methods) that operate on
that data. The Inheritance, enables a class, called the subclass, inheriting
the capabilities of a base class, called a superclass in Java. The
polymorphism enables you to create virtual methods that can be
implemented differently in derived classes. In this article, you'll apply
what you know about object-oriented programming towards creating Java
classes.
class MyClass
Believe it or not, the preceding lines are a complete Java class. If you save
the lines in a file called MyClass.java, you could even compile the class
into a .CLASS file, although the file won't actually do anything if you tried
to run it. As you can see, the class definition begins with the keyword class
followed by the name of the class. The body of the class is marked off by
curly braces just like any other program block. In this case, the class's
body is empty. Because its body is empty, this example class doesn't do
anything. You can, however, compile the class and even create an object
from it. To create an object from a class, you type the class's name
followed by the name of the object. For example, the line below creates an
object from the MyClass class:
Defining Classes
Classes as types
When a class is defined, the compiler regards the class as a new type.
When a variable is declared, its type can be a primitive type or "Class"
type.
Any variable whose type is a class is an object reference.
The variable is a reference to an instance of the specified class.
The variables holds the address (in memory) of the object.
int myField;
The above line declares a data field of type integer. However, looking at
the above line doesn't tell you much about how data fields are used with
classes. In fact, you can't tell from the above line whether myField is
actually part of an object or just a normal variable. To clear up this
ambiguity, you can plug the above line into the MyClass class definition,
as shown in Listing1.
class MyClass
{
int myField
Now you can see that myField is a data field of the MyClass class.
Moreover, this data field is by default accessible only by methods in the
same package. (For now, you can think of a package as a file.) You can
change the rules of this access by using the public, protected, and private
keywords. A public data field can be accessed by any part of a program,
inside or outside of the class in which it's defined. A protected data field
can only be accessed from within the class or from within a derived class
(a subclass). A private data field cannot even be accessed by a derived
class.
Defining a Constructor
You have now added a data field to MyClass. However, the class has no
methods and so can do nothing with its data field. The next step in
defining the class, then, is to create methods. One special type of method,
called a constructor, enables an object to initialize itself when it's created.
A constructor is a public method (a method that can be accessed anywhere
in a program) with the same name as the class. Listing2 shows the
MyClass class with its constructor in place.
class MyClass
{
int myField;
{
myField = value;
}
}
As you can see, the class's constructor starts with the public keyword. This
is important because you want to be able to create an object from the class
anywhere in your program, and when you create an object, you're actually
calling its constructor. After the public keyword comes the name of the
constructor followed by the constructor's arguments in parentheses. When
you create an object of the class, you must also provide the required
arguments.
If you want to create an object from MyClass, you must supply an integer
value that the class uses to initialize the myField data field. This integer is
the MyClass constructor's single argument. You'd create an object of the
class like this:
This line not only creates an object of the MyClass class, but also
initializes the myField data field to 1. The first word in the line tells Java
that myObject is going to be an object of the MyClass class. The next
word is the object's name. After the equals sign comes the keyword new
and the call to the class's constructor.
Creating Classes
Classes and the class diagram represent the static structure of the
system
How the system behaves is not represented by this model
Credit
Debit
Debit
Debit
null References
null means refers to no object"
Object references can be compared to null to see if an object is
present or not.
null is the default value of an object reference before it is initialized
e.g :-
Employee anEmployee;
[...]
if (anEmployee == null)
{
}
REFRENCE
1. https://www.slideshare.net/BhagawatAdhikari1/root-finding-
method?qid=a3e3c177-d5ec-48f9-a883-e59c08a49980&v=&b=&from_search=2
2. http://math.tutorvista.com/calculus/bisection-method.html
3. https://en.wikiversity.org/wiki/The_bisection_method
4. https://ece.uwaterloo.ca/~dwharder/class/programming/10RootFinding/bisection