Java Interview Questions Cheat Sheet
by sdm7306 via cheatography.com/51374/cs/14061/
Main Features of Java Final, Finally, Finalize Abstract Classes
Object Oriented Final Makes a variable, method, or class An abstract class is a class which cannot be
Simple unchangeable. instantiated. An abstract class is used by
creating an inheriting subclass that can be
Final Exception handling after success or
Platform Independent
instantiated. An abstract class does a few
ly failure during a try catch block.
Secure things for the inheriting subclass:
Final Called by the garbage collector on an 1.Define methods which can be used by the
Robust
ize object when garbage collection
inheriting subclass.
Portable determines that there are no more
2.Define abstract methods which the inheriting
Multithreaded references to the object.
subclass must implement.
Distributed 3.Provide a common interface which allows the
Inheritance
subclass to be interchanged with all other
Principles of OOP Inheritance is one of the key principle of object subclasses.
oriented programming. Through inheritance,
Abstr Abstraction means using simple
one class can inherit the properties of another Exception Handling
action things to represent complexity using
class. The class from which properties are
object, classes, and variables. try The code to be monitored for
inherited is called super class and the class to
Encap This is the practice of keeping fields exceptions will be kept in this block.
which properties are inherited is called sub
sulati within a class private, then providing catch If any exceptions occurred in try block,
class.
on access to them via public methods. Does Java support multiple inheritance? those exceptions will be caught by this
It’s a protective barrier that keeps the block.
Java supports multiple inheritance but only
data and code safe within the class
through interfaces. That means a class can finall This block will be always executed
itself.
implement more than one interfaces but can y whether exception is raised or not and
Inherit It lets programmers create new not extend more than one class. raised exceptions are caught or not.
ance classes that share some of the
attributes of existing classes. This lets Constructor & Method Overloading Checked & Unchecked Exceptions
us build on previous work without
reinventing the wheel. A class can have any number of constructors. Checked Known and checked at compile
These constructors will have different list of time.
Polym Polymorphism refers to any entity
arguments. It is called constructor
orphis whether it is a method or a Uncheck Known at Runtime, unknown at
overloading. Constructor overloading provides
constructor or an operator which takes ed compile time.
m
different ways to instantiate a class.
many forms or can be used for
If a class has more than one method with same
multiple tasks. Static & Non-Static Methods
name but with different list of arguments, then it
is called method overloading. Static method is common to all instances of a
Multithreaded Programming
class. Static methods are stored in the class
Multithreaded programming is one of the key Overriding memory. Where as non-static methods are
features of java which allows multiple threads stored in the object memory. Each instance of a
If a super class method is modified in the sub
to execute their task simultaneously. class will have their own copy of non-static
class then it is called method overriding.
There are two ways to create threads in methods.
Java
a) by extending the Thread class Synchronization
b) by implementing the Runnable interface
Synchronization is a way of controlling the
access of a method or a block by multiple
threads. Only one thread can enter into a
method or a block which has been declared as
synchronized. Synchronization is one of the
way to achieve thread safety.
By sdm7306 Published 21st December, 2017. Sponsored by CrosswordCheats.com
cheatography.com/sdm7306/ Last updated 21st December, 2017. Learn to solve cryptic crosswords!
Page 1 of 2. http://crosswordcheats.com
Java Interview Questions Cheat Sheet
by sdm7306 via cheatography.com/51374/cs/14061/
Garbage Collection
Removing unwanted objects or abandoned objects from the memory is
called garbage collection. Garbage collection is done automatically in
java. You need not to remove the unwanted objects explicitly. Garbage
collector thread does this for you.
Cloning
Cloning is a process of creating an exact copy of an existing object in the
memory. Cloning may be shallow or deep. In java, clone() method is
used to create a clone of an object.
Interfaces
A Java interface is a bit like a class, except a Java interface can only
contain method signatures and fields. An Java interface cannot contain
an implementation of the methods, only the signature (name, parameters
and exceptions) of the method.
You can use interfaces in Java as a way to achieve polymorphism.
By sdm7306 Published 21st December, 2017. Sponsored by CrosswordCheats.com
cheatography.com/sdm7306/ Last updated 21st December, 2017. Learn to solve cryptic crosswords!
Page 2 of 2. http://crosswordcheats.com