0% found this document useful (0 votes)
72 views18 pages

CS3391

The document outlines the syllabus for a course on Object-Oriented Programming (OOP) using Java, covering key concepts such as OOP principles, inheritance, exception handling, multithreading, and JavaFX. It provides a detailed breakdown of each unit, including topics like classes, objects, encapsulation, polymorphism, and Java's unique features. The document serves as a comprehensive guide for students to understand the foundational elements of Java programming and OOP methodologies.

Uploaded by

vvishnu0213
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views18 pages

CS3391

The document outlines the syllabus for a course on Object-Oriented Programming (OOP) using Java, covering key concepts such as OOP principles, inheritance, exception handling, multithreading, and JavaFX. It provides a detailed breakdown of each unit, including topics like classes, objects, encapsulation, polymorphism, and Java's unique features. The document serves as a comprehensive guide for students to understand the foundational elements of Java programming and OOP methodologies.

Uploaded by

vvishnu0213
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

CS3391 - OBJECT ORIENTED PROGRAMMING

SYLLABUS

UNIT -1 INTORDUCTION TO OOP AND JAVA

Overview of OOP – Object Oriented Programming Paradigms – Features of Object


Oriented Programming – Java Buzzwords – Overview of Java – Data Types,
Variables and Arrays – Operators – Control Statements – Programming Structures in
Java – Defining Classes in Java – Constructors – Methods – Access Specifiers – Static
Members – JavaDoc Comments.

UNIT- II INHERITANCE, PACKAGES AND INTERFACES

Overloading Methods – Objects as Parameters – Returning Objects – Static, Nested


and Inner Classes. Inheritance: Basics – Types of Inheritance – super keyword –
Method Overriding – Dynamic Method Dispatch – Abstract Classes – final with
Inheritance. Packages and Interfaces: Packages – Packages and Member Access –
Importing Packages – Interfaces.

UNIT- III EXCEPTION HANDLING AND MULTITHREADING

Exception Handling basics - Multiple catch Clauses- Nested try Statements - Java’s
built-in exceptions, User defined exception, Multithreaded Programming: Java Thread
Model, Creating a thread and multiple threads - Priorities- Synchronization - Inter-
Thread communication-Suspending-Resuming and Stopping Threads – Multithreading
. Wrappers- Auto boxing.

UNIT- IV I/O, GENERICS, STRING HANDLING

I/O Basics – Reading and Writing Console I/O – Reading and Writing Files. Generics:
Generic Programming – Generic classes – Generic Methods – Bounded Types –
Restrictions and Limitations. Strings: Basic String class, methods and String Buffer
Class.

1
`
UNIT - V JAVAFX EVENT HANDLING, CONTROLS AND COMPONENTS

JAVAFX Events and Controls: Event Basics – Handling Key and Mouse Events.
Controls: Checkbox, ToggleButton – RadioButtons – ListView – ComboBox –
ChoiceBox – TextControls – ScrollPane. Layouts – FlowPane – HBox and VBox –
Border Pane – Stack Pane – GridPane. Menus – Basics – Menu – Menu bars – Menu
Item.

2
`
UNIT -1 INTORDUCTION TO OOP AND JAVA

Overview of OOP – Object Oriented Programming Paradigms – Features of Object


Oriented Programming – Java Buzzwords – Overview of Java – Data Types,
Variables and Arrays – Operators – Control Statements – Programming Structures in
Java – Defining Classes in Java – Constructors – Methods – Access Specifiers – Static
Members – JavaDoc Comments.

1.1: OVERVIEW OF OOP


Object-Oriented Programming System (OOPs) is a programming paradigm based on
the concept of ―objects that contain data and methods, instead of just functions and
procedures.
 The primary purpose of object-oriented programming is to increase the flexibility
and maintainability of programs.
 Object oriented programming brings together data and its behavior (methods) in to
a single entity (object) which makes it easier to understand how a program works.

Features / advantages of Object Oriented Programming :-


1. It emphasis in own data rather than procedure.
2. It is based on the principles of inheritance, polymorphism, encapsulation and data
abstraction.
3. Programs are divided into objects.
4. Data and the functions are wrapped into a single unit called class so that data is
hidden and is safe from accidental alternation.
5. Objects communicate with each other through functions.
6. New data and functions can be easily added whenever necessary.

3
`
7. Employs bottom-up approach in program design.

PROCEDURE-ORIENTED PROGRAMMING [POP]:


Procedure-Oriented Programming is a conventional programming which consists of
writing a list of instructions for the computer to follow and organizing these
instructions into groups known as Functions (or) Procedures (or) subroutines (or)
Modules.
Example: A program may involve the following operations:
 Collecting data from user (Reading)
 Calculations on collected data (Calculation)
 Displaying the result to the user (Printing)

Characteristics of Procedural oriented programming:-


1. It focuses on process rather than data.
2. It takes a problem as a sequence of things to be done such as reading, calculating
and printing. Hence, a number of functions are written to solve a problem.
3. A program is divided into a number of functions and each function has clearly
defined purpose.
4. Most of the functions share global data.
5. Data moves openly around the system from function to function.
6. Employs top-down approach in program design.

Drawback of POP
 Procedural languages are difficult to relate with the real world objects.
 Procedural codes are very difficult to maintain, if the code grows larger.
 Procedural languages do not have automatic memory management as like in Java.
Hence, it makes the programmer to concern more about the memory management of
the program.
 The data, which is used in procedural languages, are exposed to the whole
program. So, there is no security for the data.
 Examples of Procedural languages :
o BASIC
oC
o Pascal
o FORTRAN

4
`
Difference between POP and OOP:

POP OOP
Divided Into In POP, program is divided into small In OOP, program is divided into parts
parts called functions. called objects.
Importance In POP, Importance is not given to data In OOP, Importance is given to the data
but to functions as well as sequence of rather than procedures or functions
actions to be done. because it works as a real world.
Approach POP follows Top Down approach. OOP follows Bottom Up approach.
Access Specifiers POP does not have any OOP has access specifiers named
access specifier. Public, Private, Protected, etc.
Data Moving In POP, Data can move freely from In OOP, objects can move and
function to function in the system. communicate with each other through
member functions.
Expansion To add new data and function in POP is OOP provides an easy way to add new
not so easy. data and function.
Data Access In POP, Most function uses Global data In OOP, data cannot move easily from
for sharing that can be accessed freely function to function, it can be kept
from function to function in the system. public or private so we can control the
access of data.
Data Hiding POP does not have any proper way for OOP provides Data Hiding so provides
hiding data so it is less secure. more security.
Overloading In POP, Overloading is not possible. In OOP, overloading is possible in the
form of Function Overloading and
Operator Overloading.
Examples Examples of POP are: C,VB, Examples of OOP are: C++, JAVA,
FORTRAN, and Pascal. VB.NET, C#.NET.

1.2: FEATURES / CHARACHTERISTICS OF OBJECT ORIENTED


PROGRAMMING CONCEPTS

Object-Oriented Programming (OOP) is a programming language model


organized around objects rather than actions and data. An object-oriented
program can be characterized as data controlling access to code. Concepts of
OOPS
 Class
 Object
 Inheritance
 Polymorphism
 Abstraction
 Encapsulation

5
`
Class:
A class is a collection of similar objects and it contains data and methods that
operate on that data. In other words ― Class is a blueprint or template for a set of
objects that share a common structure and a common behavior. It is a logical
entity.
A class in Java can contain:
 fields
 methods
 constructors
 blocks
 nested class and interface

Syntax to declare a class:


Example:
class <class_name>
{
field;
method;
}

6
`
Object:
Any entity that has state and behavior is known as an object. Object is an instance of
a class.
 For example: chair, pen, table, keyboard, bike etc. It can be physical and logical.
 The object of a class can be created by using the new keyword in Java
Programming language.
class_name object_name = new class_name;
(or) class_name object_name;
object_name = new class_name();

Syntax to create Object in Java:

An object has three characteristics:


1. State: represents data (value) of an object.
2. Behavior: represents the behavior (functionality) of an object such as deposit,
withdraw etc.
3. Identity: Object identity is an unique ID used internally by the JVM to identify
each object uniquely.
4. For Example: Pen is an object. Its name is Reynolds, color is white etc. known
as its state. It is used to write, so writing is its behavior.

Difference between Object and Object Class


Class S.No.
1) Object is an instance of a class. Class is a blueprint or template
from which objects are created.
2) Object is a real world entity such Class is a group of similar
as pen, laptop, mobile, bed, objects.
keyboard, mouse, chair etc.
3) Object is a physical entity. Class is a logical entity.
4) Object is created through new Class is declared using class
keyword mainly e.g. keyword
Student s1=new Student(); e.g. class Student{}
5) Object is created many times as Class is declared once.
per requirement.
6) Object allocates memory when it is Class doesn't allocated memory
created. when it is created.
7) There are many ways to create There is only one way to define

7
`
object in java such as new class
keyword, newInstance() method,
clone() method, factory method
and deserialization.

Encapsulation:
Wrapping of data and method together into a single unit is known as
Encapsulation.

For example: capsule, it is wrapped with different medicines.


 In OOP, data and methods operating on that data are combined together to
form a single unit, this is referred to as a Class.
 Encapsulation is the mechanism that binds together code and the data it manipulates
and keeps both safe from outside interference and misuse.
 The insulation of the data from direct access by the program is called ―data
hiding. Since the data stored in an object cannot be accessed directly, the data is safe
i.e., the data is unknown to other methods and objects.

Polymorphism:
 Polymorphism is a concept by which we can perform a single action by different
ways. It is the ability of an object to take more than one form.
 The word "poly" means many and "morphs" means forms. So polymorphism means
many forms.
 An operation may exhibit different behaviors in different instances. The behavior
depends on the data types used in the operation.
 For Example:- Suppose if you are in a classroom that time you behave like a
student, when you are in the market at that time you behave like a customer, when you
at your home at that time you behave like a son or daughter, Here one person present
in different-different behaviors.
Two types of polymorphism:
1. Compile time polymorphism / Method Overloading: - In this method, object is
bound to the function call at the compile time itself.
2. Runtime polymorphism / Method Overriding: - In this method, object is bound
to the function call only at the run time.
 In java, we use method overloading and method overriding to achieve
polymorphism.

8
`
 Example:
1. draw(int x, int y, int z)
2. draw(int l, int b)
3. draw(int r)

Abstraction:

 Abstraction refers to the act of representing essential features without including the
background details or explanations. i.e., Abstraction means hiding lower-level
details and exposing only the essential and relevant details to the users.
 For Example: - Consider an ATM Machine; All are performing operations on the
ATM machine like cash withdrawal, money transfer, retrieve mini-statement…etc. but
we can't know internal details about ATM.
 Abstraction provides advantage of code reuse.
 Abstraction enables program open for extension.

 In java, abstract classes and interfaces are used to achieve Abstraction.

Inheritance:
 Inheritance in java is a mechanism in which one object acquires all the properties
and behaviors of another object.
 The idea behind inheritance in java is that we can create new classes that are built
upon existing classes. When we inherit from an existing class, we can reuse methods
and fields of parent class, and we can add new methods and fields also.
 Inheritance represents the IS-A relationship, also known as parent-child
relationship.
 For example:- In a child and parent relationship, all the properties of a father are
inherited by his son.
Syntax of Java Inheritance:
class Subclass-name extends Superclass-name
{
//methods and fields
}

9
`
Message Passing:
Message Communication:
 Objects interact and communicate with each other by sending messages to each
other. This information is passed along with the message as parameters.

 A message for an object is a request for execution of a procedure and therefore will
invoke a method (procedure) in the receiving object that generates the desired result.
 Message passing involves specifying the name of the object, the name of the
method (message) and the information to be sent.
 Example:
Employee.getName(name);
Where,
Employee – object name
getName – method name (message) name – information

1.3 Java Buzzwords


The following are the features of the Java language:
1. Object Oriented
2. Simple
3. Secure
4. Platform Independent
5. Robust
6. Portable
7. Architecture Neutral
8. Dynamic
9. Interpreted
10. High Performance
11. Multithreaded
12. Distributed

10
`
1. Object Oriented:
 Java programming is pure object-oriented programming language. Like C++, Java
provides most of the object oriented features.
 Though C++ is also an object oriented language, we can write programs in C++
without a class but it is not possible to write a Java program without classes.
 Example: Printing “Hello” Message.
C++ ( can be without class) Java – No programs without classes and objects
With Class: With class:
#include<iostream.h> import java.io.*;
class display { class Hello {
public: public static void main(String args[])
void disp() {
{ System.out.println(“Hello!”);
cout<<”Hello!”; }
} }
}; Without class is not possible
main()
{
display d;
d.disp();
}
Without class: #include<iostream.h>
void main()
{
clrscr();
cout<<”\n Hello!”;
getch();
}

2. Simple:
 Java is Easy to write and more readable and eye catching.
 Most of the concepts are drew from C++ thus making Java learning simpler.

11
`
3. Secure :
 Since Java is intended to be used in networked/distributed environments, lot of
emphasis has been placed on security.
 Java provides a secure means of creating Internet applications and to access web
applications.
 Java enables the construction of secured, virus-free, tamper-free system.

4. Platform Independent:
 Unlike C, C++, when Java program is compiled, it is not compiled into platform-
specific machine code, rather it is converted into platform independent code called
bytecode.
 The Java bytecodes are not specific to any processor. They can be executed in any
computer without any error.
 Because of the bytecode, Java is called as Platform Independent

5. Robust:
 Java encourages error-free programming by being strictly typed and performing
run-time checks.

6. Portable:
 Java bytecode can be distributed over the web and interpreted by Java Virtual
Machine (JVM)
 Java programs can run on any platform (Linux, Window, Mac)
 Java programs can be transferred over world wide web (e.g applets)

7. Architecture Neutral:
 Java is not tied to a specific machine or operating system architecture.
 Machine Independent i.e Java is independent of hardware.
 Bytecode instructions are designed to be both easy to interpret on any machine and
easily translated into native machine code.

8. Dynamic and Extensible:

12
`
 Java is a more dynamic language than C or C++. It was developed to adapt to an
evolving environment.
 Java programs carry with them substantial amounts of run-time information that are
used to verify and resolve accesses to objects at run time.
9. Interpreted:
 Java supports cross-platform code through the use of Java bytecode.
 The Java interpreter can execute Java Bytecodes directly on any machine to which
the interpreter has been ported.

10. High Performance:


 Bytecodes are highly optimized.
 JVM can execute the bytecodes much faster.
 With the use of Just-In-Time (JIT) compiler, it enables high performance.

11. Multithreaded:
 Java provides integrated support for multithreaded programming.
 Using multithreading capability, we can write programs that can do many tasks
simultaneously.
 The benefits of multithreading are better responsiveness and real-time behavior.

12. Distributed:
 Java is designed for the distributed environment for the Internet because it handles
TCP/IP protocols.
 Java programs can be transmit and run over internet.

1.4: Overview of Java

 Java programming language was originally developed by Sun Microsystems which


was initiated by James Gosling and released in 1995 as core component of Sun
Microsystems' Java platform (Java 1.0 [J2SE]).
Java is a high-level object-oriented programming language, which provides
developers with the means to create powerful applications, which are very
small in size, platform independent, secure and robust

 Java runs on a variety of platforms, such as Windows, Mac OS, and the various
versions of UNIX.
1. Java is mainly used for Internet Programming.
2. Java is related to the languages C and C++. From C, Java inherits its syntax and
from C++, Java inherits its OOP concepts.
3. Ancestors of Java: - C, C++, B, BCPL.

13
`
Five primary goals in the creation of the Java language:
1. It should use the object-oriented programming methodology.
2. It should allow the same program to be executed on multiple operating systems.
3. It should contain built-in support for using computer networks.
4. It should be designed to execute code from remote sources securely.
5. It should be easy to use.

Java is a high-level object-oriented programming language, which provides


developers with the means to create powerful applications, which are very small
in size, platform independent, secure and robust.

1.4.1: BASIC JAVA TERMINALOGIES:

1. BYTECODE:
Byte code is an intermediate code generated from the source code by java compiler
and it is platform independent.

2. JAVA DEVELOPMENT KIT (JDK):


 The Java Development Kit (JDK) is a software development environment used for
developing Java applications and applets.
 It includes the Java Runtime Environment (JRE), an interpreter/loader (java), a
compiler (javac), an archiver (jar), a documentation generator (javadoc) and other
tools needed in Java development.

3. JAVA RUNTIME ENVIRONMENT (JRE):


JRE is used to provide runtime environment for JVM. It contains set of libraries +
other files that JVM uses at runtime.

4. JAVA VIRTUAL MACHINE (JVM):


 JVM is an interpreter that converts a program in Java bytecode (intermediate
language) into native machine code and executes it.
 JVM needs to be implemented for each platform because it will differ from
platform to platform.

14
`
 The JVM performs following main tasks:
• Loads code
• Verifies code
• Executes code
• Provides runtime environment

5. JIT (JUST IN TIME) COMPILER:


It is used to improve the performance. JIT compiles parts of the byte code that have
similar functionality at the same time, and hence reduces the amount of time needed
for compilation.

Types of Java program:


In Java, there are two types of programs namely,

1. Application Program
2. Applet Program

15
`
1. Application Program
Application programs are stand-alone programs that are written to carry out certain
tasks on local computer such as solving equations, reading and writing files etc. The
application programs can be executed using two steps:
1. Compile source code to generate Byte code using javac compiler.
2. Execute the byte code program using Java interpreter.

2. Applet programs:
Applets are small Java programs developed for Internet applications. An applet
located in distant computer can be downloaded via Internet and executed on a local
computer using Java capable browser. The Java applets can also be executed in the
command line using appletviewer, which is part of the JDK.

1.4.2: JAVA SOURCE FILE - STRUCTURE – COMPILATION


THE JAVA SOURCE FILE:
A Java source file is a plain text file containing Java source code and having .java
extension. The .java extension means that the file is the Java source file. Java source
code file contains source code for a class, interface, enumeration, or annotation type.
There are some rules associated to Java source file.

Java Program Structure:


Java program may contain many classes of which only one class defines the main
method.
A Java program may contain one or more sections.
Documentation
Section
Package Statement
Import Statements
Interface Statements
Class Definitions
main Method Calss
{
Main Method
Definition
}
Of the above Sections shown in the figure, the Main Method class is Essential part,
Documentation Section is a suggested part and all the other parts are optional.

Documentation Section
 It Comprises a Set of comment lines giving the name of the program, the author and
other details.

 Comments help in Maintaining the Program.


 Java uses a Style of comment called documentation comment.

16
`
/* * …… */

 This type of comment helps is generating the documentation automatically.

 Example:
/*
* Title: Conversion of Degrees
* Aim: To convert Celsius to Fahrenheit and vice versa

* Date: 31/08/2000
* Author: tim

*/

Package Statement
 The first statement allowed in a Java file is a package statement.
 It declares the package name and informs the compiler that the classes defined
belong to this package.

 Example :
package student;
package basepackage.subpackage.class;
 It is an optional declaration.

Import Statements
 The statement instructs the interpreter to load a class contained in a particular
package.
 Example :
import student.test;

Where, student is the package and test is the class.

Interface Statements
 An interface is similar to classes which consist of group of method declaration.
 Like classes, interfaces contain methods and variable.
 To link the interface to our program, the keyword implements is used.

 Example:
public class xx extends Applet implements ActionListener

where, xx – class name (subclass of Applet) Applet – Base class name


ActionListener – interface Extends & implements - keywords
 It is used when we want to implement the feature of Multiple Inheritance in Java

17
`
 It is an optional declaration.

Class Definitions
 A Java Program can have any number of class declarations.

 The number of classes depends on the complexity of the program.

Main Method Class


 Every Java Standalone program requires a main method as its starting point.
 A Simple Java Program will contain only the main method class.
 It creates objects of various classes and uses those objects for performing various
operations.
 When the end of main is reached the program terminates and the control transferred
back to the Operating system.

 Syntax for writing main:

public static void main(String arg[])


where,

public – It is an access specifier to control the visibility of class members. main()


must be declared as public, since it must be called by code outside of its class when
the program is started.

static – this keyword allows main() method to be called without having to instantiate
the instance of the class.

void – this keyword tells the compiler that main() does not return any value.

main() – is the method called when a Java application begins.

String arg[] – arg is an string array which receives any command-line arguments
present when the program is executed.

18
`

You might also like