Programming Paradigms
Structured Programming
Object Based Programming
Object Oriented Programming
Case
Definition
■ Object Oriented Programming (OOP is a
programming method that combines data and
instructions into a self-sufficient "object".
OBJECTS AND OBJECT CLASSES
■ Object - Objects have states and behaviors. Example: A dog has
states - color, name, breed as well as behaviors -wagging,
barking, eating.
■ An object is an instance of a class. (in relation to programming
language)
■ Software objects also have a state and behavior. A software
object's state is stored in fields and behavior is shown via
methods.
■ So in software development, methods operate on the internal
state of an object and the object-to-object communication is
done via methods.
Creating an Object:
There are three steps when creating an object from a class:
Declaration: A variable declaration with a variable name
with an object type.
Instantiation: The 'new' key word is used to create the
object.
Initialization: The 'new' keyword is followed by a call to a
constructor. This call initializes the new object.
A Class
■ Class - A class can be defined as a template/blueprint that
describes the behaviors/states that object of its type
support.
■ In software, a class is a blue print from which individual
objects are created.
Example
public class Dog
{
String breed ;
int age ;
String color ;
void barking() {
}
void hungry() {
}
void sleeping() {
}
}
Java
■ Java is a high-level programming language originally developed by Sun Microsystems
and released in 1995.
■ Java runs on a variety of platforms, such as Windows, Mac OS, and the various
versions of UNIX.
First Java Program
public class MyFirstJavaProgram
{
public static void main(String [] args)
{
[Link]("Hello World");
}
}
Basic Syntax:
■ Case Sensitivity - which means identifier Hello and hello would have different
meaning in Java.
■ Class Names - For all class names the first letter should be in Upper Case.
If several words are used to form a name of the class, each inner word's first letter
should be in Upper Case.
Example class MyFirstJavaClass
■ Method Names - All method names should start with a Lower Case letter.
If several words are used to form the name of the method, then each inner word's
first letter should be in Upper Case.
Example public void myMethodName()
Cont..
■ Program File Name - Name of the program file should exactly match the class name.
When saving the file, you should save it using the class name (Remember Java is
case sensitive) and append '.java' to the end of the name (if the file name and the
class name do not match your program will not compile).
Example : Assume 'MyFirstJavaProgram' is the class name. Then the file should be
saved as ' [Link]
■ public static void main(String args[]) - Java program processing starts from the
main() method which is a mandatory part of every Java program..