Professional Documents
Culture Documents
The java is constructed & based on the OOP ( Object Oriented Programming
) concepts. The java uses object oriented programming environment.
Programming languages:
There are two types:
Initial programming languages that uses machine language or binary language & called
LOW LEVEL PROGRAMMING LANGUAGES.
Languages that uses alphabets, numbers & special characters so its called HIGH LEVEL
PROGRAMMING LANGUAGE.
THIS HIGH LEVE PROGRAMMING LANGUAGE CANE BE:
STRUCTURED LANGUAGE:
this type has sets of rules & regulations such as java
..etc.
UNSTRUCTURED LANGUAGE: this type doesnt has sets of rules & regulations.
PAGE
1- Defining the objects that are to be manipulated by the program. Once the objects are
identified, the programmer will begin to
2- Identify the relationship between each object or Operations or calculations.
THIS PROCESS IS USUALLY REFERRED TO AS DATA MODELLING.
Essentially, the programmer is seeking to place the objects into a
classification, thus helping to define the data that is part of the inheritance brought to the task
by each object. In fact, the process of defining these classes and subclasses of data is normally
called inheritance.
OBJECT:
DEFINITION: Object is a tangible and visible thing or entity. An object
can be considered a "thing" that can perform a set of activities. Real-world objects share two
characteristics: they all have STATE & BEHAVIOR .Objects are key to understanding objectoriented technology.
Software objects are modelled after real-world objects in that they too
have state and behavior. A software object maintains its STATE in variables and
implements its behavior with METHODS.
These real-world objects share two characteristics: they all have state and they all
have behavior. For example, dogs have state (name, color, breed, hungry) and dogs have behavior
(barking, fetching, and slobbering on your newly cleaned slacks). Bicycles have state (current gear,
current pedal cadence, two wheels, number of gears) and behavior (braking, accelerating, slowing
down, changing gears).
PAGE
Classes in Java
A class is a blueprint from which individual objects are created. A class can have any number of
methods to access the value of various kinds of methods.
CLASS:
DEFINITION:
This class describes the data properties and behaviours alone. In
programming language, CLASS describes both the PROPERTIES (DATA) and BEHAVIOURS
(FUNCTIONS) of objects. Classes are not objects, but they are used to instantiate objects.
FEATURES OF CLASS: Classes contain data known as members and member
functions. As a unit, the collection of members and member functions is an object.
Therefore, this unit of objects make up a class.
Encapsulation:
In Java is a mechanism of wrapping the data (variables) and code acting on the data (methods)
together as a single unit. In encapsulation, the variables of a class will be hidden from other
classes, and can be accessed only through the methods of their current class. Therefore, it is also
known as data hiding. { }
Advantages of encapsulation:
1. It improves maintainability and flexibility.
2. The fields can be made read-only.
3. User code would not know what is going on behind the scene. Encapsulation is
also known as data Hiding.
Encapsulation:
DEFINITION: Encapsulation is the process of combining data and
functions into a single unit called class. Using the method of encapsulation, the
programmer cannot directly access the data. Data is only accessible through the functions present inside
the class. Data encapsulation led to the important concept of data hiding. Data hiding is the
implementation details of a class that are hidden from the user. The concept of restricted access led
programmers to write specialized functions or methods for performing the operations on hidden members
of the class. Attention must be paid to ensure that the class is designed properly.
PAGE
Modularity--The source code for an object can be written and maintained independently of the source
code for other objects. Also, an object can be easily passed around in the system. You can give your
bicycle to someone else and it will still work.
DEFINING OOP :
Object-Oriented Programming (OOP) is a type of programming that
This concept is very important when dealing with object-oriented programming languages such
as Java, this involves dividing the various codes that we have into separate classes & methods
that in order to maximize code separation in to other classes and methods and minimize coding to
be only in a single unit.
Constructors
Constructor in java is a special type of method that is used to initialize the object.
Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data
for the object that is why it is known as constructor.
PAGE
Example Programme:
class OPT
{
public static void main(String args[])
{
Box M1 = new Box();
Box M2 = new Box();
double ADD;
M1.width = 10;
M1.height = 20;
M1.depth = 15;
M2.width = 3;
M2.height = 6;
M2.depth = 9;
ADD = M1.volume();
System.out.println("Volume is " + ADD);
ADD = M2.volume();
System.out.println("Volume is " + ADD);
}
}
class Box
{
double width;
double height;
double depth;
double volume()
{
return width * height * depth;
}
}
PAGE
Functions
programmers to define their own functions. So Developers often need the ability to break
programs up into smaller chunks (parts) that are easier to develop & follow in the case of the
large programmes. Functions help us to classify our programmes to the necessary parts.
"Real world" programs can be many of thousands (or millions!) of lines long. Without this
ability to divide the program into parts, developing such large programs would quickly become
impossible.
Always programmers to divide their code up into chunks (parts) known as functions. A function
with a simple description and a well-defined interface to the outside world can be written and
debugged without worrying about the code that surrounds it.
Types of functions:
1. Void function (function that returns no value and sends no value).
2. Function that receives values from main function (also called Passing
arguments by reference).
3. Function that returns value to main function (function that passes a parameter).
Function:
is a another part of code written out side the main function thus creating a
subprogram, the main function will be the first to work then the functions will work next , the
functions has t be called by the main programme so then it can work.
Functions may depend on variables passed to them, called arguments or parameters, and may pass
results of a task on to the main function of the function; this is called the return value.
It is important to note that a function that exists in the global scope can also be called global function
and a function that is defined inside a class is called a member function. (The term method is
commonly used in other programming languages to refer to things like functions, but this can lead to
dealing with java which supports functions.)
PAGE
Calling function:
Calling function means starting the function or making the function start or work. Each function
call is responsible for its own function code that has the same name.
PAGE
Explanation:
1. If the function returns a value then the type of that value must be specified in functiontype. For the moment this could be int, float or char.
If the function does not return a value then the function-type must be void.
The function-name follows the same rules of composition as identifiers or variable.
The parameter-list lists the formal parameters of the function together with their types.
The local-definitions are definitions of variables that are used in the functionimplementation or function code. These variables have no meaning outside the function.
6. The function-implementation consists of executable statements that implement the
effect of the function.
2.
3.
4.
5.
PAGE
Programme Example:
import java.util.Scanner;
public class AC
{
public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
int C;
System.out.println("1- Addittion");
System.out.println("2-Multiplication");
System.out.println("3-Divition");
System.out.println("4-Subtraction");
System.out.println("Enter the Option : ");
C=input.nextInt();
switch(C)
{
case 1: ADD();
break;
case 2: MUL();
break;
case 3: DIV();
break;
case 4: SUB();
break;
default: System.out.println("Invalid Option select (1-4)");
}
}
PAGE
double X,Y,Z;
System.out.println("Enter number : ");
X=input.nextDouble();
System.out.println("Enter number : ");
Y=input.nextDouble();
Z=X/Y;
System.out.println("Division: " +Z);
}
public static void MUL()
{
Scanner input= new Scanner(System.in);
double X,Y,Z;
System.out.println("Enter number : ");
X=input.nextDouble();
System.out.println("Enter number : ");
Y=input.nextDouble();
Z=X*Y;
System.out.println("Multiplication: " +Z);
}
public static void ADD()
{
Scanner input= new Scanner(System.in);
double X,Y,Z;
System.out.println("Enter number : ");
X=input.nextDouble();
System.out.println("Enter number : ");
Y=input.nextDouble();
Z=X+Y;
System.out.println("Addittion: " +Z);
}
PAGE
10
Arrays
An array is a group of like-typed variables that are referred to by a common name.
Arrays of any type can be created and may have one or more dimensions. A specific element in an
array is accessed by its index. Arrays offer a convenient means of grouping related information.
One-Dimensional Arrays
A one-dimensional array is, essentially, a list of like-typed variables. To create an array, you first
must create an array variable of the desired type. The general form of a one-dimensional
array declaration is
Multidimensional Arrays
In Java, multidimensional arrays are actually arrays of arrays. These, as you might expect, look and act like regular
multidimensional arrays.
PAGE
11
Garbage Collection:
The garbage collector is a program which runs on the Java Virtual Machine which
gets rid of objects which are not being used by a Java application anymore. It is a
form of automatic memory management.
PAGE
12