1 OOPs Concept
1 OOPs Concept
Java is not fully object oriented because it supports primitive data type like it,byte,long etc.,which
are not objects. Because in JAVA we use data types like int, float, double etc which are not object
oriented, and of course is what opposite of OOP is. That is why JAVA is not 100% objected oriented.
Java has predefined primitive data types (which are not objects).
You can access the members of a static class without creating an object of it.
Therefore, Java is not considered as fully object-oriented Technology.
To make it 100% OO, we have wrapper classes which actually wrap the primitive data type into
object of that class.
A Wrapper class is a class whose object wraps or contains primitive data types. When we create an
object to a wrapper class, it contains a field and, in this field, we can store primitive data types. In
other words, we can wrap a primitive value into a wrapper class object.
Autoboxing: Automatic conversion of primitive types to the object of their corresponding wrapper
classes is known as autoboxing. For example – conversion of int to Integer, long to Long, double to
Double etc.
2. Security: By not allowing pointers, Java effectively provides another level of abstraction to the
developer. No pointer support make Java more secure because they point to memory location or
used for memory management that loses the security as we use them directly.
3. Passing argument by reference: Passing a reference which allows you to change the value of a
variable in the caller's scope. Java doesn't have this, but it's a pretty rare use case and can easily be
done in other ways. This is in general equivalent to changing a field in an object scope that both the
caller and callee can see.
4. Manual memory management: you can use pointers to manually control and allocate blocks of
memory . This is useful for some bigger applications like games, device drivers etc. but for general
purpose Object Oriented programming it is simply not worth the effort. Java instead provides very
good automatic Garbage Collection (GC) which takes care of memory management.
JDK – Java Development Kit (in short JDK) is Kit which provides the environment
to develop and execute(run) the Java program. JDK is a kit(or package) which includes
two things
1. Development Tools(to provide an environment to develop your
java programs)
2. JRE (to execute your java program).
Note : JDK is only used by Java Developers.
JRE – Java Runtime Environment (to say JRE) is an installation package which provides
environment to only run(not develop) the java program(or application)onto your
machine. JRE is only used by them who only wants to run the Java Programs i.e. end
users of your system.
(.java to .class)
JVM – Java Virtual machine(JVM) is a very important part of both JDK and JRE because
it is contained or inbuilt in both. Whatever Java program you run using JRE or JDK goes
into JVM and JVM is responsible for executing the java program line by line hence it is
also known as interpreter.
The Just-In-Time (JIT) compiler is a an essential part of the JRE i.e. Java Runtime
Environment, that is responsible for performance optimization of java based
applications at run time. Compiler is one of the key aspects in deciding performance of
an application for both parties i.e. the end user and the application developer.
What is marker Interface?
A marker interface is an interface that has no methods or constants inside it. It provides run-time
type information about objects, so the compiler and JVM have additional information about the
object. A marker interface is also called a tagging interface. Examples of marker interface are
Serializable, Cloneable and Remote interface. All these interfaces are empty interfaces.
How to create Singleton Class: At any moment we must have only one instance of that class.
1. Static instance creation of its own object
2. Define a constructor which is private
3. Create a static method which return instance of class
What is String Buffer and String Builder:
String allocate memory in SCP or heap (if that string is present already and we use new keyword
then it will save in Heap otherwise it will be in SCP)
But String Buffer and String Builder will be saved in heap only and both are mutable.
They both less memory as compare to String.
String is not thread safe, the methods of string are non-synchronized. And in String Buffer all
methods are synchronized so it is thread safe. In String Builder methods are non-synchronous so it
is also not thread safe.
Thread safe means, one thread will not affect with another thread in case of multithreading. Other
thread should wait.
Constructor:
Every time an object is created using the new() keyword, at least one constructor is
called.