0% found this document useful (0 votes)
28 views9 pages

advanced oop

The document provides an overview of programming languages, categorizing them into machine-level, assembly-level, and high-level languages, with a focus on object-oriented programming (OOP) concepts. It details the characteristics and benefits of OOP, including encapsulation, inheritance, and polymorphism, as well as the Java programming language's features and syntax. Additionally, it explains the process of creating, compiling, and executing Java programs, highlighting the importance of class definitions and the main method.

Uploaded by

kaneno karabu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
28 views9 pages

advanced oop

The document provides an overview of programming languages, categorizing them into machine-level, assembly-level, and high-level languages, with a focus on object-oriented programming (OOP) concepts. It details the characteristics and benefits of OOP, including encapsulation, inheritance, and polymorphism, as well as the Java programming language's features and syntax. Additionally, it explains the process of creating, compiling, and executing Java programs, highlighting the importance of class definitions and the main method.

Uploaded by

kaneno karabu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 9

Programmers write instructions in various programming languages to perform their computation

tasks such as:


(i) Machine level Language
(ii) (ii) Assembly level Language
(iii) (iii) High level Language
Machine level Language: Machine code or machine language is a set of instructions executed
directly by a computer's central processing unit (CPU). Each instruction performs a very specific
task, such as a load, a jump, or an ALU operation on a unit of data in a CPU register or memory.
Every program directly executed by a CPU is made up of a series of such instructions.
Assembly level Language: An assembly language (or assembler language) is a low-level
programming language for a computer, or other programmable device, in which there is a very
strong (generally one-to-one) correspondence between the language and the architecture’s
machine code instructions. Assembly language is converted into executable machine code by a
utility program referred to as an assembler; the conversion process is referred to as
assembly, or assembling the code.
High level Language: High-level language is any programming language that enables
development of a program in much simpler programming context and is generally independent
of the computer's hardware architecture. High-level language has a higher level of abstraction
from the computer, and focuses more on the programming logic rather than the underlying
hardware components such as memory addressing and register utilization. The first high-level
programming languages were designed in the 1950s. Now there are dozens of different
languages, including Ada , Algol, BASIC, COBOL, C, C++, JAVA, FORTRAN, LISP,
Pascal, and Prolog. Such languages are considered high-level because they are closer to
human languages and farther from machine languages. In contrast, assembly languages are
considered low-level because they are very close to machine languages. The high-level
programming languages are broadly categorized in to two categories:

(i) Procedure oriented programming(POP) language.


(ii) (ii) Object oriented programming(OOP) language.

Procedure Oriented Programming Language


In the procedure oriented approach, the problem is viewed as sequence of things to be
done such as reading , calculation and printing. Procedure oriented programming basically
consist of writing a list of instruction or actions for the computer to follow and organizing
these instruction into groups known as functions.
Characteristics of procedure-oriented programming:
1. Emphasis is on doing things(algorithm)
2. Large programs are divided into smaller programs known as functions.
3. Most of the functions share global data
4. Data move openly around the system from function to function
5. Function transforms data from one form to another.
6. Employs top-down approach in program design

Object Oriented Programing


“Object oriented programming as an approach that provides a way of
modularizing programs by creating partitioned memory area for both data and functions
that can be used as templates for creating copies of such modules on demand”
Features of the Object-Oriented programming
1. Emphasis is on doing rather than procedure.
2. programs are divided into what are known as objects.
3. Data structures are designed such that they characterize the objects.
4. Functions that operate on the data of an object are tied together in the data structure.
5. Data is hidden and can’t be accessed by external functions.
6. Objects may communicate with each other through functions.
7. New data and functions can be easily added.
8. Follows bottom-up approach in program design.

BENEFITS OF OOP:
Oop offers several benefits to both the program designer and the user. Object-oriented
contributes to the solution of many problems associated with the development and quality of
software products.
The principal advantages are:
1. Through inheritance we can eliminate redundant code and extend the use of existing
classes.
2. We can build programs from the standard working modules that communicate with one
another, rather than having to start writing the code from scratch. This leads to saving of
development time and higher productivity.
3. This principle of data hiding helps the programmer to build secure programs that can’t
be invaded by code in other parts of the program.
4. It is possible to have multiple instances of an object to co-exist without any
interference.
5. It is easy to partition the work in a project based on objects.
6. Object-oriented systems can be easily upgraded from small to large systems.
7. Message passing techniques for communication between objects makes the interface
description with external systems much simpler.
8. Software complexity can be easily managed.

APPLICATION OF OOP:

The most popular application of oops up to now, has been in the area of user interface
design such as windows. There are hundreds of windowing systems developed using oop
techniques.
Real business systems are often much more complex and contain many more objects
with complicated attributes and methods. Oop is useful in this type of applications because it
can simplify a complex problem. The promising areas for application of oop includes.

1. Real – Time systems.


2. Simulation and modeling
3. Object oriented databases.
4. Hypertext, hypermedia and expertext.
5. Al and expert systems.
6. Neural networks and parallel programming.
7. Decision support and office automation systems.
8. CIM / CAM / CAD system.

LECTURE 2: BASIC CONCEPTS OF OBJECTS ORIENTED PROGRAMMING


1. Objects
2. Classes
3. Data abstraction and encapsulation
4. Inheritance
5. Polymorphism
6. Dynamic binding
7. Message passing
OBJECTS
Objects are the basic run-time entities in an object-oriented system. They may represent a
person, a place, a bank account, a table of data or any item that the program must handle. The
fundamental idea behind object oriented approach is to combine both data and function into a
single unit and these units are called objects. The term objects means a combination of data
and program that represent some real word entity. For example: consider an example named
Amit; Amit is 25 years old and his salary is 2500. The Amit may be represented in a computer
program as an object. The data part of the object would be (name: Amit, age: 25, salary: 2500)
The program part of the object may be collection of programs (retrive of data, change age,
change of salary). In general even any user –defined type-such as employee may be
used. In the Amit object the name, age and salary are called attributes of the object.
DATA ABSTRACTION : Abstraction refers to the act of representing essential
features without including the back ground details or explanations. Classes use the concept of
abstraction and are defined as size, width and cost and functions to operate on the attributes.
DATA ENCAPSALATION : The wrapping up of data and function into a single
unit (called class) is known as encapsulation. The data is not accessible to the outside
world and only those functions which are wrapped in the class can access it. These functions
provide the interface between the objects data and the program.
INHERITENCE : Inheritance is the process by which objects of one class acquire
the properties of another class. In the concept of inheritance provides the idea of
reusablity. This mean that we can add additional features to an existing class with out
modifying it. This is possible by desining a new class will have the combined features of both the
classes.
POLYMORPHISIM: Polymorphism means the ability to take more than one
form. An operation may exhibit different instance. The behaviour depends upon the type of
data used in the operation. A language feature that allows a function or operator to be given
more than one definition. The types of the arguments with which the function or operator is
called determines which definition will be used. Overloading may be operator overloading or
function overloading. It is able to express the operation of addition by a single operater say ‘+’.
When this is possible you use the expression x + y to denote the sum of x and y, for many
different types of x and y; integers , float and complex no. You can even define the + operation
for two strings to mean the concatenation of the strings.
DYNAMIC BINDING : Binding refers to the linking of a procedure call to the
code to the executed in response to the call. Dynamic binding means the code associated with
a given procedure call is not known until the time of the call at run-time. It is associated with a
polymorphic reference depends upon the dynamic type of that reference.
JAVA
Java is a popular programming language used to develop mobile apps, web apps, desktop apps,
games and much more.
is a full-featured, general-purpose programming language that can be used to develop robust
mission-critical applications. Today, it is employed not only for Web programming but also for
developing standalone applications across platforms on servers, desktop computers, and mobile
devices.
Its rapid rise and wide acceptance can be traced to its design characteristics, particularly its
promise that you can write a program once and run it anywhere.
Java features
simple,
object oriented,
distributed,
interpreted,
robust,
secure,
architecture neutral,
portable,
high performance,
multithreaded, and dynamic.
The Java language specification and the Java API define the Java standards. The Java language
specification is a technical definition of the Java programming language’s syntax and semantics.
The application program interface (API), also known as library, contains predefined classes and
interfaces for developing Java programs. The API is still expanding.
Java is a full-fledged and powerful language that can be used in many ways. It comes in three
editions:
 Java Standard Edition (Java SE) to develop client-side applications. The applications
can run standalone or as applets running from a Web browser.
 Java Enterprise Edition (Java EE) to develop server-side applications, such as Java
servlets, JavaServer Pages (JSP), and JavaServer Faces (JSF).
 Java Micro Edition (Java ME) to develop applications for mobile devices, such as cell
phones.
Java SE is the foundation upon which all other Java technology is based. There are
manyversions of Java SE. Oracle releases each version with a Java Development Toolkit (JDK).
TheJDK consists of a set of separate programs, each invoked from a command line, for
developing
and testing Java programs. Instead of using the JDK, you can use a Java development tool (e.g.,
NetBeans, Eclipse, and TextPad)—software that provides an integrated development
environment (IDE) for developing Java programs quickly. Editing, compiling,
building,
debugging, and online help are integrated in one graphical user interface. You simply enter
source code in one window or open an existing file in a window, and then click a button or menu
item or press a function key to compile and run the program.

Creating, Compiling and executing a Java Program


You have to create your program and compile it before it can be executed. This process is
repetitive. If your program has compile errors, you have to modify the program to fix them, and
then recompile it. If your program has runtime errors or does not produce the correct result, you
have to modify the program, recompile it, and execute it again.
A Java compiler translates a Java source file into a Java bytecode file. If there aren’t any syntax
errors, the compiler generates a bytecode file with a .class extension. The Java language is a
high-level language, but Java bytecode is a low-level language. The bytecode is
similar to machine instructions but is architecture neutral and can run on any platform that has a
Java Virtual Machine (JVM). Rather than a physical machine, the virtual machine is a program
that interprets Java bytecode. This is one of Java’s primary advantages: Java bytecode can run on
a variety of hardware platforms and operating systems. Java source code is compiled into Java
bytecode and Java bytecode is interpreted by the JVM. The JVM executes your code along with
the code in the library. To execute a Java program is to run the program’s bytecode. You can
execute the bytecode on any platform with a JVM, which is an interpreter. It translates the
individual instructions in the bytecode into the target machine language code one at a time rather
than the whole program as a single unit. Each step is executed immediately after it is translated.
Suppose we have a simple program to display the statement “Welcome to Java!” and the source
code is saved in a file named Welcome. Java. If there are no errors, bytecode will be generated
and stored in Welcome.class file. The JVM will then interpret the bytecode to machine code as
shown below

Popular Java Editors


To write your Java programs, you will need a text editor. There are even more sophisticated
IDEs available in the market. But for now, you can consider one of the following −
 Notepad − On Windows machine, you can use any simple text editor like Notepad.
 Netbeans − A Java IDE that is open-source and free which can be downloaded
from https://www.netbeans.org/index.html.
 Eclipse − A Java IDE developed by the eclipse open-source community and can be
downloaded from https://www.eclipse.org/.
Java - Basic Syntax
When we consider a Java program, it can be defined as a collection of objects that communicate
via invoking each other's methods. Let us now briefly look into what do class, object, methods,
and instance variables mean.
 Object − Objects have states and behaviors. Example: A dog has states - color, name,
breed as well as behavior such as wagging their tail, barking, eating. An object is an
instance of a class.
 Class − A class can be defined as a template/blueprint that describes the behavior/state
that the object of its type supports.
 Methods − A method is basically a behavior. A class can contain many methods. It is in
methods where the logics are written, data is manipulated and all the actions are
executed.
 Instance Variables − Each object has its unique set of instance variables. An object's
state is created by the values assigned to these instance variables.
About Java programs, it is very important to keep in mind the following points.
 Case Sensitivity − Java is case sensitive, 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()
 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 'MyFirstJavaProgram.java'
 public static void main(String args[]) − Java program processing starts from the main()
method which is a mandatory part of every Java program.

Class Definition
A Java program may contain several class definitions, classes are an essential part of any Java
program. It defines the information about the user-defined classes in a program.
A class is a collection of variables and methods that operate on the fields. Every program in Java
will have at least one class with the main method.

Main Method Class


The main method is from where the execution actually starts and follows the order specified for
the following statements. Let’s take a look at a sample program to understand how it is
structured.
public class Example{
//main method declaration
public static void main(String[] args){
System.out.println("hello world");
}
}
Let’s analyze the above program line by line to understand how it works.
public class Example
This creates a class called Example. You should make sure that the class name starts with a
capital letter, and the public word means it is accessible from any other classes.
Comments
To improve the readability, we can use comments to define a specific note or functionality of
methods, etc for the programmer.
Braces
The curly brackets are used to group all the commands together. To make sure that the
commands belong to a class or a method.

public static void main


When the main method is declared public, it can also be used outside of this class.
The word static means that we want to access a method without making its objects. As we call
the main method without creating any objects.
The word void indicates that it does not return any value. The main is declared as void because it
does not return any value.
Main is the method, which is an essential part of any Java program.
String[] args
It is an array where each element is a string, which is named as args. You can pass the input
parameter if you run the Java code through a console. The main() takes it as an input.

System.out.println();
The statement is used to print the output on the screen where the system is a predefined class, out
is an object of the PrintWriter class. The method println prints the text on the screen with a new
line. All Java statements end with a semicolon.

Java Identifiers
All Java components require names. Names used for classes, variables, and methods are
called identifiers.
In Java, there are several points to remember about identifiers. They are as follows −
 All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an
underscore (_).
 After the first character, identifiers can have any combination of characters.
 A key word cannot be used as an identifier.
 Most importantly, identifiers are case sensitive.
 Examples of legal identifiers: age, $salary, _value, __1_value.
 Examples of illegal identifiers: 123abc, -salary.

You might also like