0% found this document useful (0 votes)
61 views11 pages

Oops Through Java

Oops Java programming

Uploaded by

shankarsomana036
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
61 views11 pages

Oops Through Java

Oops Java programming

Uploaded by

shankarsomana036
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 11

Unit 1

1. Object oriented concepts

Object-oriented programming aims to implement real-world entities like inheritance, hiding,


polymorphism, etc. in programming. The main aim of OOPs is to bind together the data and
the functions that operate on them so that no other part of the code can access this data
except that function. OOPS concepts are as follows:
1. Class
2. Object
3. Method and method passing
4. Pillars of OOPs
 Abstraction
 Encapsulation
 Inheritance
 Polymorphism
o Compile-time polymorphism
o Runtime polymorphism

A class is a user-defined blueprint or prototype from which objects are created. It represents
the set of properties or methods that are common to all objects of one type.

An object is a basic unit of Object-Oriented Programming that represents real-life entities. A


typical Java program creates many objects, which as you know, interact by invoking methods.

Data Abstraction is the property by virtue of which only the essential details are displayed to
the user. The trivial or non-essential units are not displayed to the user. Ex: A car is viewed as
a car rather than its individual components.

Encapsulation defined as the wrapping up of data under a single unit. It is the mechanism
that binds together the code and the data it manipulates.

SK KHADAR BASHA M Tech


Dept Of CSE, UCEN Page 1
Inheritance is an important pillar of OOP (Object Oriented Programming). It is the mechanism
in Java by which one class is allowed to inherit the features (fields and methods) of another
class.

It refers to the ability of object-oriented programming languages to differentiate between


entities with the same name efficiently.

The Object Oriented Programming (OOPs) concept in Java is a powerful way to organize and
write code. It uses key ideas like classes, objects, inheritance, polymorphism, encapsulation,
and abstraction to create flexible and reusable code. By using the Java OOPs concept,
programmers can build complex applications more efficiently, making the code easier to
manage, understand, and modify. Overall, Java’s OOPs concepts help in creating robust and
scalable software solutions.

2. Structure of Java Program

Java is an object-oriented programming, platform-independent, and secures programming


language that makes it popular. Using the Java programming language, we can develop a wide
variety of applications. So, before diving in depth, it is necessary to understand the basic
structure of Java program in detail. In this section, we have discussed the basic structure of a
Java program. At the end of this section, you will able to develop the Hello world Java program,
easily.

SK KHADAR BASHA M Tech


Dept Of CSE, UCEN Page 2
The documentation section is an important section but optional for a Java program. It
includes basic information about a Java program. The information includes the author's name,
date of creation,

o Single-line Comment: It starts with a pair of forwarding slash (//). For example:

//First Java Program


o Multi-line Comment: It starts with a /* and ends with */. We write between these two
symbols. For example:

/*It is an example of multiline comment*/

The package declaration is optional. It is placed just after the documentation section. In this
section, we declare the package name in which the class is placed.

package java point; //where java point is the package name

The package contains the many predefined classes and interfaces. If we want to use any class of
a particular package, we need to import that class. The import statement represents the class
stored in the other package. We use the import keyword to import the class.

Import java.util.*; //it imports all the class of the java.util package

It is an optional section. We can create an interface in this section if required. We use


the interface keyword to create an interface. An interface is a slightly different from the class.
interface car
{
void start();
void stop();
}
In this section, we define the class. It is vital part of a Java program. Without the class, we
cannot create any Java program. A Java program may conation more than one class definition.
We use the class keyword to define the class. The class is a blueprint of a Java program.

In this section, we define the main() method. It is essential for all Java programs. Because the
execution of all Java programs starts from the main() method.

SK KHADAR BASHA M Tech


Dept Of CSE, UCEN Page 3
3. Installation

Procedure to write simple java Program

To write a java program First we have install the JDK.

To create a simple java program, you


need to create a class that contains main
method. Let's understand the
requirement first.

install the JDK and install it.

set path of the jdk

create the java program

compile and run the java program

Setting Up the Path for Windows

Assuming you have installed Java in c:\Program Files\java\jdk directory −

Right-click on 'My Computer' and select 'Properties'.

Click the 'Environment variables' button under the 'Advanced' tab.

Now, alter the 'Path' variable so that it also contains the path to the Java executable.
Example, if the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your path to
read 'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin

Setting Up the Path for Linux, UNIX, Solaris, FreeBSD

Environment variable PATH should be set to point to where the Java binaries have been
installed. Refer to your shell documentation, if you have trouble doing this. For Example if you
use bash as your shell, then you would add the following line to the end of your '.bashrc: export
PATH = /path/to/java:$PATH'

Popular Java Editors

Notepad − On Windows machine, you can use any simple text editor like Notepad
(Recommended for this tutorial), TextPad.

SK KHADAR BASHA M Tech


Dept Of CSE, UCEN Page 4
Netbeans − A Java IDE that is open-source and free which can be downloaded from Eclipse −
A Java IDE developed by the eclipse open-source community and can be downloaded from

4.Object Oriented Programming System(OOPS)


Object means a real word entity such as pen, chair, table etc. Object-Oriented
Programming is a methodology or paradigm to design a program using classes and
objects. It simplifies the software development and maintenance by providing some
concepts:
Object
Class
Inheritance
Polymorphism
Abstraction
Encapsulation

If any language fallows the OOPS concepts that language we call it as object oriented
language

5. Need have oops

Object-oriented programming (OOP) is useful because it allows you to organize code in a way
that models real-world objects or concepts. Here are some simple reasons why OOP is
important:

1. Modularity: OOP promotes breaking down complex problems into smaller, manageable parts
(objects), making it easier to understand and maintain.

2. Reuse: Objects can be reused in different parts of a program or in different programs


altogether, reducing duplication and saving development time.

3. Encapsulation: Objects encapsulate data (attributes) and behavior (methods) into a single
unit, protecting data from unintended access and modification.

4. Abstraction: Abstracting complex systems allows developers to focus on high-level design


without worrying about low-level implementation details.

5. Inheritance: Classes can inherit attributes and methods from other classes, promoting code
reusability and enabling hierarchical relationships between classes.

SK KHADAR BASHA M Tech


Dept Of CSE, UCEN Page 5
6. Polymorphism: Objects can be treated as instances of their parent class, allowing for
flexibility and enabling multiple implementations of methods.

In essence, OOP provides a structured way to design and build software systems that are
scalable, maintainable, and easier to debug. It aligns well with real-world modeling, making it
intuitive for developers to conceptualize and implement solutions.

6. Principles of Object-Oriented Programming

Here are the principles of Object-Oriented Programming (OOP) explained simply:

1. Encapsulation: Bundling data (attributes) and methods (functions) that operate on the data
into a single unit (object). This protects the data from outside interference and misuse.

2. Abstraction: Hiding complex implementation details behind a simplified interface. It focuses


on what an object does rather than how it does it, allowing users to interact with objects
without needing to understand their internal workings.

3. Inheritance: Allowing new classes (subclasses or derived classes) to inherit attributes and
behaviors from existing classes (superclasses or base classes). This promotes code reusability
and enables hierarchical relationships between classes.

4. Polymorphism: Providing a way to perform a single action in different ways. This allows
objects of different classes to be treated as objects of a common superclass, but each subclass
can have its own implementation of methods.

These principles together help developers create modular, maintainable, and scalable software
by organizing code into objects that model real-world entities or abstract concepts.

7. Procedural Programming

Procedural Programming can be defined as a programming model which is derived from


structured programming, based upon the concept of calling procedure. Procedures, also
known as routines, subroutines or functions, simply consist of a series of computational steps
to be carried out. During a program’s execution, any given procedure might be called at any
point, including by other procedures or itself.
Languages used in Procedural Programming:
FORTRAN, ALGOL, COBOL,
BASIC, Pascal and C.

SK KHADAR BASHA M Tech


Dept Of CSE, UCEN Page 6
Object-Oriented Programming

Object-oriented programming can be defined as a programming model which is based upon


the concept of objects. Objects contain data in the form of attributes and code in the form of
methods. In object-oriented programming, computer programs are designed using the
concept of objects that interact with the real world. Object-oriented programming languages
are various but the most popular ones are class-based, meaning that objects are instances of
classes, which also determine their types.
Languages used in Object-Oriented Programming:
Java, C++, C#, Python,
PHP, JavaScript, Ruby, Perl,
Objective-C, Dart, Swift, Scala.

Procedural Programming vs Object-Oriented Programming

Below are some of the differences between procedural and object-oriented programming:

Procedural Oriented Programming Object-Oriented Programming

In object-oriented programming, the


In procedural programming, the program is
program is divided into small parts
divided into small parts called functions.
called objects.

Procedural programming follows a top-down Object-oriented programming follows


approach. a bottom-up approach.

There is no access specifier in procedural Object-oriented programming has access


programming. specifiers like private, public, protected, etc.

Adding new data and functions is not easy. Adding new data and function is easy.

Procedural programming does not have any Object-oriented programming provides data
proper way of hiding data so it is less secure. hiding so it is more secure.

In procedural programming, overloading is not Overloading is possible in object-oriented

SK KHADAR BASHA M Tech


Dept Of CSE, UCEN Page 7
Procedural Oriented Programming Object-Oriented Programming

possible. programming.

In procedural programming, there is no In object-oriented programming, the concept


concept of data hiding and inheritance. of data hiding and inheritance is used.

In procedural programming, the function is In object-oriented programming, data is


more important than the data. more important than function.

Procedural programming is based on Object-oriented programming is based on


the unreal world. the real world.

Procedural programming is used for designing Object-oriented programming is used for


medium-sized programs. designing large and complex programs.

Procedural programming uses the concept of Object-oriented programming uses the


procedure abstraction. concept of data abstraction.

Code reusability absent in procedural Code reusability present in object-oriented


programming, programming.

Examples: C, FORTRAN, Pascal, Basic, etc. Examples: C++, Java, Python, C#, etc.

History of Java
James Gosling, Patrick Naught on and Mike Sheridan initiated the Java language project in 1991.
Team of sun engineers designed for small, embedded systems in electronic appliances like set-
top boxes. Initially it was called "Green talk" later it was called Oak.
Java is open source software produced by Sun micro system under the terms of the GNU
General Public License (GPL).

SK KHADAR BASHA M Tech


Dept Of CSE, UCEN Page 8
Application of java
1. Desktop Applications
2. Web Applications
3. Mobile
4. Enterprise Applications
5. Smart Card
6. Embedded System
7. Games
8. Robotics etc

What is Java?
Java is a high Level programming language and it is also called as a platform. Java is a secured
and robust high level object-oriented programming language.
Platform: Any software or hardware environment in which a program runs is known as a
platform. Java has its own runtime environment (JRE) and API so java is also called as platform.
Java fallows the concept of Write Once, Run Anywhere.

JVM (Java Virtual Machine)


JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime
environment in which java byte code can be executed. JVMs are available for many hardware
and software platforms (i.e. JVM is platform dependent).

What is JVM?
1. A specification where working of Java Virtual Machine is specified. But implementation
provider is independent to choose the algorithm. Its implementation has been provided by Sun
and other companies.
2. An implementation its implementation is known as JRE (Java Runtime Environment).
3. Runtime Instance whenever you write java command on the command prompt to run the
java class, an instance of JVM is created.

SK KHADAR BASHA M Tech


Dept Of CSE, UCEN Page 9
What it does
The JVM performs following operation:
Loads code
Verifies code
Executes code
Provides runtime environment

JAVA VIRTUAL MACHINE


Java’s Magic: The Byte code output of a Java compiler is not executable code. Rather, it is byte
code. Byte code is a highly optimized set of instructions designed to be executed by the Java
run-time system, which is called the Java Virtual Machine (JVM).
Java complier translates the java source code into byte code or intermediate code ,not the
executable file .JVM take the byte code and convert into executable code corresponding to
Operating system
Because of the above feature java is portable

Features of Java:
1. Object Oriented – Java implements basic concepts of Object oriented programming System
(OOPS) ie Object, Class, Inheritance, Polymorphism, Abstraction, Encapsulation. In Java,
everything is an Object. Java can be easily extended since it is based on the Object model.
2. Platform Independent − unlike many other programming languages including C and C++,
when Java is compiled, it is not compiled into platform specific machine, rather into platform
independent byte code. This byte code is distributed over the web and interpreted by the
Virtual Machine (JVM) on whichever platform it is being run on.
3.Simple – Java fallows the basic Syntax of C,C++. If you understand the basic concept of OOPS
then it is easy to master in java.

SK KHADAR BASHA M Tech


Dept Of CSE, UCEN Page 10
Secure − With Java's secure feature it enables to develop virus-free, tamper-free systems.
Authentication techniques are based on public-key encryption.
Architecture-neutral − Java compiler generates an architecture-neutral object file format,
which makes the compiled code executable on many processors, with the presence of Java
runtime system.
Portable − Being architecture-neutral and having no implementation dependent aspects of
the specification makes Java portable. Compiler in Java is written in ANSI C with a clean
portability boundary, which is a POSIX subset.
Robust − Java makes an effort to eliminate error prone situations by emphasizing mainly on
compile time error checking and runtime checking.
Multithreaded − With Java's multithreaded feature In java we can write programs that can
perform many tasks simultaneously. This design feature allows the developers to construct
interactive applications that can run smoothly.
Interpreted − Java byte code is translated on the fly to native machine instructions and is not
stored anywhere. The development process is more rapid and analytical since the linking is an
incremental and light-weight process.
High Performance − With the use of Just-In-Time compilers, Java enables high performance.
Distributed − Java is designed for the distributed environment of the internet.
Dynamic − Java is considered to be more dynamic than C or C++ since it is designed to adapt
to an evolving environment. Java

SK KHADAR BASHA M Tech


Dept Of CSE, UCEN Page 11

You might also like