0% found this document useful (0 votes)
4 views12 pages

II Sem Java Notes

The document provides an overview of Object-Oriented Programming (OOP) using Java, detailing its definition, basic concepts, benefits, and applications. It compares OOP with Procedure-Oriented Programming (POP) and outlines the history and features of Java as a programming language. Additionally, it discusses the different editions of Java and types of applications that can be developed using it.

Uploaded by

yugesh batti
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)
4 views12 pages

II Sem Java Notes

The document provides an overview of Object-Oriented Programming (OOP) using Java, detailing its definition, basic concepts, benefits, and applications. It compares OOP with Procedure-Oriented Programming (POP) and outlines the history and features of Java as a programming language. Additionally, it discusses the different editions of Java and types of applications that can be developed using it.

Uploaded by

yugesh batti
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

OOPS using JAVA – II SEM BCA 1

Unit – I
Definition of Programming Language:
A programming language is a set of rules, symbols, and syntax used to write
programs that instruct a computer to perform specific tasks.
Or
A programming language is a formal language used to write instructions that a
computer can understand and execute. These instructions are used to develop
software, applications, and programs that perform specific tasks.
Computers understand only machine language (binary: 0s and 1s). Programming
languages allow programmers to write instructions in a human-readable form, which
are then translated into machine language by compilers or interpreters.
Programming languages are classified into the following categories.
1) Monolytic Programming Language:
 It contains number of lines of data
 The program code is duplicated each time it is to be used.
 Examples: BASIC and Assembly languages
2) Procedural Programming Language
 Programs are organized in the form of subroutine
 Program controls are through jumps(goto) and calls to subroutine
 It follows top-down approach
 Data move around the system from function to function.
 Examples: FORTRAN, COBOL
3) Structured Programming Language
 It consists of Multiple Modules and each module has set of fuctions
related types.
 Programs are divided into individual procedures.
 Procedures have their own local data and processing logic.
4) Object Oriented Programming Language
 Programs are divided into objects
 Functions that operation data of an object are together the data structure
 Data hidden and cannot be accessed by externa funcitons
 Objects are communicate through functions whenever necessary
 It follows bottom up approach.
OOPS using JAVA – II SEM BCA 2

Introduction to OOP:
What is OOP?

Object Oriented Programming is software design method that models the


characteristics of abstract or real objects using classes and objects.

Or

Object-Oriented Programming (OOP) is a programming paradigm that organizes


programs using objects and classes. The concept of OOP was developed to
make software programs more modular, reusable, and easier to maintain. The
development of OOP evolved gradually over several years through different
programming languages.

Evolution of OOP Languages

Year Language Contribution


1967 Simula First OOP language
1970s Smalltalk Pure object-oriented language

1983 C++ Popularized OOP


1991 Python Multi-paradigm language
1995 Java Platform-independent OOP language
2000 C# Modern object-oriented language

Q1) Explain Basic Concepts of OOPs.


Ans) BASIC CONCEPT OF OBJECT-ORIENTED PROGRAMMING (OOP)
The General concepts of OOP’s are as follows
1. Objects
2. Classes
3. Data encapsulation
4. Data abstraction
5. Inheritance
OOPS using JAVA – II SEM BCA 3

6. Polymorphism
7. Dynamic binding
8. Message Passing

[Link]

A class is a blueprint or template used to create objects in object-oriented


programming. It defines

the properties (attributes or variables) and behaviors (methods or functions) that the
objects created from the class will have. A class helps organize data and functions
together, making programs more structured and reusable. For example, a class named
Student may contain attributes like roll number and name, and methods like display()
or calculateMarks().

2. Object

An object is an instance of a class and represents a real-world entity. It contains data


and methods defined by its class. Objects are used to access the properties and
behaviors of the class. Each object occupies memory and can have its own values for
the attributes. For example, if Student is a class, then student1 and student2 are objects
created from that class.

3. Encapsulation

Encapsulation is the process of wrapping data and methods together into a single unit
called a class. It also restricts direct access to data by using access modifiers such as
private, public, and protected. This helps protect the data from unauthorized access
and improves program security. Encapsulation ensures that data is accessed only
through defined methods, making the program easier to maintain and manage.

4. Abstraction

Abstraction is the concept of hiding internal implementation details and showing only
the necessary features to the user. It simplifies complex systems by focusing on what
an object does rather than how it does it. Abstraction helps programmers work with
high-level concepts without worrying about underlying complexities. Common
examples include ATM machines and mobile phones, where users interact with simple
interfaces without knowing the internal operations.
OOPS using JAVA – II SEM BCA 4

5. Inheritance

Inheritance is a mechanism in which one class acquires the properties and methods of
another class. The class that inherits the features is called the child or derived class,
and the class from which properties are inherited is called the parent or base class.
Inheritance promotes code reuse and reduces duplication in programs. It also allows
programmers to create hierarchical relationships between classes.

6. Polymorphism

Polymorphism means “many forms” and refers to the ability of a function or method
to perform different tasks depending on the context. In object-oriented programming,
the same method name can be used for different operations. Polymorphism improves
flexibility and readability of programs. It is mainly achieved through method
overloading (compile-time polymorphism) and method overriding (runtime
polymorphism).

[Link] binding:

Binding refers to the linking of a procedure call to the code to be executed in response
to the call. Dynamic binding also known as late binding means that the code
associated with a given procedure call is not known until the time of the call at run-
time.

8. Message Passing

Message passing is the process through which objects communicate with each other in
object-oriented programming. An object sends a message to another object by calling
its method to perform a specific operation. This interaction allows objects to work
together to complete tasks within a program. Message passing helps create modular
and well-organized programs where objects cooperate with each other.

Q2) Explain Benefits and Applications of OOPS.

Ans) Benefits and Applications of OOP

1. Real-Time Systems
Object-Oriented Programming is used in real-time systems where immediate
response is required, such as traffic control and embedded systems.
Objects help organize complex components and manage system interactions
efficiently.

2. Simulation and Modelling


OOPS using JAVA – II SEM BCA 5

OOP is widely used to simulate real-world systems such as weather systems, flight
simulators, and industrial processes. Objects represent real-world entities, making
modeling easier and more accurate.

3. Object-Oriented Databases
OOP concepts are used in object-oriented databases to store data in the form of
objects instead of [Link] allows better representation of complex data and
relationships.

4. Hypertext and Hypermedia


OOP helps in designing hypertext and hypermedia systems used in web applications
and multimedia systems. Objects manage links, media elements, and navigation
structures efficiently.

5. Artificial Intelligence and Expert Systems


OOP is useful in developing AI and expert systems where knowledge and rules are
organized as objects. It helps manage complex reasoning systems and intelligent
decision-making.

6. Neural Networks and Parallel Programming


OOP supports neural networks and parallel programming by organizing processing
units as objects. This allows efficient handling of multiple processes simultaneously.

7. Decision Support and Office Automation Systems


OOP is used in decision support systems and office automation software like
document management and workflow systems. It improves modularity,
maintainability, and system integration.

Q3)Differentiate between procedure oriented and object oriented programming


paradigm

ANS) Comparison of Procedure oriented and Object oriented programming


paradigm

Procedure-Oriented Programming (POP) and Object-Oriented Programming (OOP)


are two important programming paradigms used for software development. POP
focuses mainly on procedures or functions, while OOP focuses on objects and classes.

Feature Procedure-Oriented Object-Oriented


Programming (POP) Programming (OOP)
Basic Concept Focuses on procedures or Focuses on objects and
functions classes
OOPS using JAVA – II SEM BCA 6

Program Program is divided into Program is divided into


Structure functions objects
Approach Uses top-down approach Uses bottom-up approach
Data Handling Data is globally shared Data is encapsulated inside
objects
Data Security Less secure More secure due to
encapsulation
Code Reusability Limited code reuse High code reuse using
inheritance
Maintenance Difficult for large programs Easier to maintain large
programs
Real-world Not suitable for real-world Suitable for real-world
Modeling modeling modeling
Examples C, Pascal C++, Java, Python

BASICS OF JAVA PROGRAMMING

What is Java?
Java is a high-level, general-purpose, object-oriented, and secure programming
language developed by James Gosling at Sun Microsystems in 1991, Java was
named as Oak. So James Gosling and his team changed the name from Oak to Java
in 1995.

Editions of Java
There are three editions of Java: Each edition of Java has different capabilities.
1. Java Standard Editions (JSE): It is used to create programs for a desktop
computer.
2. Java Enterprise Edition (JEE): It is used to create large programs that run
on the server and manages heavy traffic and complex transactions.
3. Java Micro Edition (JME): It is used to develop applications for small
devices such as set- top boxes, phone, and appliances.

Types of Java Applications


There are four types of Java applications can be created using Java programming:
1. Standalone Applications: A Java standalone application uses GUI
components such as AWT (Abstract Window Toolkit), Swing, and Java
OOPS using JAVA – II SEM BCA 7

FX. These components contain buttons, list, menu, scroll panel, etc. It is
also known as desktop alienations.
2. Enterprise Applications: An application which is distributed in
nature is called enterprise applications.

3. Web Applications: An application that runs on the server is called web


applications. It includes JSP, Servlet, Spring, and Hibernate technologies for
creating web applications.

4. Mobile Applications: Java ME (Java Micro Edition) is a cross-platform to


develop mobile applications which run across smart phones. Java is a
platform for App Development in Android.

JAVA HISTORY
9. Java is a general-purpose, object-oriented programming language
developed by James Gosling from Sun Microsystems of USA in 1991.
10. Originally Java was called Oak.
11.
Year Development
1990 A team of Sun Microsystems programmers headed by James Gosling
was formed.
1991 The team announced a new language named “Oak”.
The team developed a Web browser called “Hot Java” to locate and
1994 run applet
programs on Internet.
Oak was renamed “Java”. Many popular companies including
1995 Netscape and
Microsoft announced their support to Java.
Java established itself not only as a leader for Internet programming
1996 but also as a general-purpose, object oriented programming
language. Sun releases Java
Development Kit 1.0.
1997 Sun releases Java Development Kit 1.1 (JDK 1.1)
OOPS using JAVA – II SEM BCA 8

Sun releases the Java 2 with version 1.2 of the Software


1998 Development Kit
(SDK 1.2)
Sun releases the Java 2 Platform, Standard Edition (J2SE) and
1999 Enterprise Edition
(J2EE)
2000 J2SE with SDK 1.3 was released.
2002 J2SE with SDK 1.4 was released.
2004 J2SE with SDK 5.0 (instead of JDK 1.5) was released. This is known as
J2SE 5.0

JAVA FEATURES
1. Compiled and Interpreted
2. Platform–independent and Portable
3. Object oriented
4. Robust and Secure
5. Distributed
6. Familiar, Simple and Small
7. Multithreaded and Interactive
8. High Performance
9. Dynamic and Extensible
1. Compiled and Interpreted: Computer Language is either compiled or

interpreted. Java combines both these approaches thus making Java a two
stage system. First stage Java Compiler translates source code into bytecode
instruction (Bytecodes are not machine instructions). Second stage Java
Interpreter generates machine code that can be directly executed by the
machine that is running the Java program.
Java compiler converts into source code (.java) into
bytecode (.class) Java Interpreter generates machine
code.

2. Platform Independent and Portable: The most significant contribution of


OOPS using JAVA – II SEM BCA 9

Java over other languages is its portability. Java programs can be easily
moved from one computer system to another, anywhere and anytime.
Changes and upgrades in operating systems, processors and system resources
will not force any changes in Java programs.
Java ensures portability in two ways. First, Java compiler generates bytecode
instructions that can be implemented on any machine. Secondly, the sizes of
the primitive data types are machine independent.

3. Object oriented: Java is a true object-oriented language. Almost everything

in Java is an object. All program code and data reside within objects and
classes. Java comes with an extensive set of classes, arranged in packages
that we can use in our programs by inheritance.

4. Robust and Secure: Java is a robust language. It provides many safeguards

to ensure reliable code. It has strict compile time and run time checking for
data types. It is designed as garbage collected language relieving the
programmers virtually all memory management problems. Java also
incorporates the concept of exception handling which captures series of errors
and eliminates any risk of crashing the system.
Java systems not only verify all memory access but also ensure that no
viruses are communicated with an applet.

5. Distributed: Java is designed as a distributed language for creating

applications on networks. It has the ability to share both data and programs.
Java applications can open and access remote objects on Internet. This
enables multiple programmers at multiple remote locations to collaborate and
work together on a single project.

6. Simple, Small and Familiar: Java is a small and simple language. To make

the language look familiar to the existing programmers, it was modelled on C


& C++ languages. Java uses many constructs of C & C++ and therefore, Java
OOPS using JAVA – II SEM BCA 10

code “looks like a C++”code. In fact, Java is a simplified version of C++.

7. Multithreaded and Interactive: Multithreaded means handling multiple

tasks simultaneously. Java supports multithreaded programs. This means that


we need not wait for the application to finish one task before beginning
another. This feature greatly improves the interactive performance of
graphical applications.

8. High-performance: Java performance is impressive for an interpreted

language, mainly due to the use of intermediate bytecode. Java speed is


comparable to the native C / C++. The incorporation of multithreading
enhances the overall execution speed of Java programs.

9. Dynamic and Extensible: Java is a dynamic language. Java is capable of

dynamically linking in new class libraries, methods and objects. Java can also
determine the type of class through a query, making it possible to either
dynamically link or abort the program, depending on the response. Java
programs support functions written in other languages such as C and C++.

Comparison in C and JAVA


OOPS using JAVA – II SEM BCA 11

Feature C Language Java Language

Programming Procedural-Oriented Object-Oriented Programming


Paradigm Programming

Development Developed by Dennis Developed by James Gosling


Ritchie (1972) (1995)

Program Program is divided into Program is divided into classes


Structure functions and objects

Platform Platform dependent Platform independent (Write


Dependency Once Run Anywhere)

Memory Manual memory Automatic memory


Management management using management using garbage
pointers collection

Security Less secure More secure

Pointer Support Supports pointers Does not support pointers


directly

Compilation Compiled directly into Compiled into bytecode and


machine code executed by JVM

Use of Header Uses header files like Does not use header files
Files stdio.h

Application System programming, Web applications, enterprise


Areas embedded systems applications, mobile apps

Comparison in Java and C++

Java C++
1 Java is true Object-oriented language. C++ is basically C with Object-
oriented
extension.
2 Java does not support operator C++ supports operator
overloading. overloading.
3 It supports labels with loops and It supports goto statement.
statement blocks
4 Java does not have template classes C++ has template classes.
as in C++.
OOPS using JAVA – II SEM BCA 12

5 Java compiled into byte code for the Source code can be written to be
Java Virtual Machine. The source platform independent and written
code is independent on operating to take advantage of platform.C+
system. + typically compiled into machine
code.
6 Java does not support multiple C++ supports multiple inheritance
inheritance of of classes.
classes but it supports interface.
7 Runs in a protected virtual machine. Exposes low-level system
facilities.
8 Java does not support global C++ support global variable.
variable. Every
variable should declare in class.
9 Java does not use pointer. C++ uses pointer.
10 It Strictly enforces an object It Allows both procedural
oriented programming and
programming paradigm. object-oriented programming.
11 There are no header files in Java. We have to use header file in C+
+.

You might also like