Oops Through Java
Oops Through Java
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.
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.
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.
o Single-line Comment: It starts with a pair of forwarding slash (//). For example:
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.
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
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.
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
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'
Notepad − On Windows machine, you can use any simple text editor like Notepad
(Recommended for this tutorial), TextPad.
If any language fallows the OOPS concepts that language we call it as object oriented
language
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.
3. Encapsulation: Objects encapsulate data (attributes) and behavior (methods) into a single
unit, protecting data from unintended access and modification.
5. Inheritance: Classes can inherit attributes and methods from other classes, promoting code
reusability and enabling hierarchical relationships between classes.
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.
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.
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
Below are some of the differences between procedural and object-oriented programming:
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.
possible. 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).
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.
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.
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.