OOPS Concept
OOPS Concept
language encapsulation can be achieve using class keyword, state represents declaration of
Advantage of Encapsulation
The main advantage of using of encapsulation is to secure the data from other methods,
when we make a data private then these data only use within the class, but these data not
The common example of encapsulation is capsule. In capsule all medicine are encapsulated
in side capsule.
Benefits of encapsulation
Hiding of data is known as data abstraction. In object oriented programming language this
is implemented automatically while writing the code in the form of class and object.
Abstraction shows only important things to the user and hides the internal details, for
example, when we ride a bike, we only know about how to ride bikes but can not know
about how it work? And also we do not know the internal functionality of a bike.
Data abstraction can be used to provide security for the data from the unauthorized
methods.
Read more about Interface and Abstract class in the previous section.
Abstraction deals with hiding the details and showing the essential things to the user
whereas encapsulation bind your data and code together as a single unit.
Encapsulation is not providing full security because we can access private member of the
class using reflection API, but in case of Abstraction we can't access static, abstract data
member of a class.
In java you can say it takes all your methods, variables and bind them together in a single
class.
Abstraction is implemented in Java using interface and abstract class while Encapsulation is
Here we discuss some of its benefits in order to acknowledge its significance. The benefits of
5. Collections in Java
Simply put, a Servlet is a class that handles requests, processes them and reply back
with a response.
For example, we can use a Servlet to collect input from a user through an HTML
form, query records from a database, and create web pages dynamically.
Object means a real-world entity such as a pen, chair, table, computer, watch,
etc. Object-Oriented Programming is a methodology or paradigm to design a
program using classes and objects. It simplifies software development and maintenance
by providing some concepts:
o Object
o Class
o Inheritance
o Polymorphism
o Abstraction
o Encapsulation
What is the difference between error and exception?
Exceptions and errors both are subclasses of Throwable class. The error indicates a problem that
mainly occurs due to the lack of system resources and our application should not catch these
types of problems. Some of the examples of errors are system crash error and out of memory
error. Errors mostly occur at runtime that's they belong to an unchecked type.
Exceptions are the problems which can occur at runtime and compile time. It mainly occurs in
the code written by the developers. Exceptions are divided into two categories such as checked
exceptions and unchecked exceptions.
4 It can't be occur at compile time It can occur at run time compile time
both
Both throw and throws are the concepts of exception handing in which throw is used to
explicitly throw an exception from a method or any block of code while throws are used in the
signature of the method to indicate that this method might throw one of the listed type
exceptions.
The following are the important differences between throw and throws.
Definition Throw is a keyword which is used Throws is a keyword used in the method
to throw an exception explicitly in signature used to declare an exception
1
the program inside a function or which might get thrown by the function
inside a block of code. while executing the code.
exception at a time i.e we cannot get thrown by the function where throws
throw multiple exception with keyword is used.
throw keyword.
Type of With throw keyword we can On other hand with throws keyword both
exception propagate only unchecked checked and unchecked exceptions can be
3 exception i.e checked exception declared and for the propagation checked
cannot be propagated using throw. exception must use throws keyword
followed by specific exception class name.
Syntax Syntax wise throw keyword is On other hand syntax wise throws keyword
4
followed by the instance variable. is followed by exception class names.
Declaration In order to use throw keyword we On other hand throws keyword is used with
5 should know that throw keyword is the method signature.
used within the method.
Example
JavaTester.java
Live Demo
Output
You shouldn't divide number by zero
Polymorphism means "many forms", and it occurs when we have many classes
that are related to each other by inheritance.
JSP is used to create web applications just like Servlet technology. A JSP is a
text document that contains two types of text: static data and dynamic data. The
static data can be expressed in any text-based format (like HTML, XML, SVG,
and WML), and the dynamic content can be expressed by JSP elements.
Difference between Servlet and JSP
The difference between Servlet and JSP is as follows:
Servlet JSP
What is API?
API stands for Application Programming Interface. APIs are mechanisms that enable two
software components to communicate with each other using a set of definitions and
protocols. For example, the weather bureau's software system contains daily weather data.
The weather app on your phone “talks” to this system via APIs and shows you daily weather
updates on your phone.
What is the difference between Java and c++?
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\
What is the difference between c and java? Which is better?
C Java
Union and structure datatypes are Java does not supports union and
supported by C. structures.
Data hiding is done by using static in C. Data hiding is done by using private
C Java
in Java.
A primary key is used to assure the value in the particular column is unique. The foreign
key provides the link between the two tables. Find out the major difference between primary key
and unique key.
Macro in C programming is known as the piece of code defined with the help of the #define
directive. Macros in C are very useful at multiple places to replace the piece of code with a
single value of the macro.
lass fibonacci {
static int fib(int n)
{
if (n <= 1)
return n;
return fib(n - 1) + fib(n - 2);
}
In Dynamic Memory
Allocation, there is
memory re-usability and
In Static Memory Allocation, memory can be freed
5 there is no memory re-usability when not required
The main difference between Array and Pointers is the fixed size of the memory block. When
Arrays are created the fixed size of the memory block is allocated. But with Pointers the memory
is dynamically allocated.