Java
Java
History of Java
Key Terminology
o JVM
o Java class libraries
o Java class loaders
Garbage Collector:
Classpath:
The classpath is the file path where the Java runtime and Java
compiler look for .class files to load. By default, JDK provides
many libraries. If you want to include external libraries, they
should be added to the classpath.
Features of Java
Useful Links
Every variable in Java has a data type. Data types specify the size
and type of values that can be stored in an identifier.
Note
Use float for memory efficiency when precision (around 6-7
decimal places) is sufficient. Use double for high precision
(around 15-16 decimal places) when memory is not a major
concern.
Arrays
Classes
Strings
String is a collection of characters surrounded by
double quotes which are used to store texts.
In Java, string objects are immutable. Immutable
simply means unmodifiable or unchangeable. Once a
string object is created its data or state can’t be
changed but a new string object is created.
Interfaces
Enums
Note
Wrapper Classes
Example:
Output:
BufferedReader Class
StringBuffer Class
StringBuilder Class
Note
Jagged Arrays
OOPs
Advantages of OOPs:
1. Code Reusability
2. Reduced Redundancy
3. Modularity
Disadvantages of OOPs:
1. Classes
2. Objects
3. Constructors
4. Constructor Chaining
5. This keyword
6. Interfaces
7. Access Modifiers
Classes:
Objects:
Constructors:
Parameterized Constructors:
Copy Constructors:
Constructor Chaining:
Interfaces:
Access Modifiers:
Encapsulation
Example:
Inheritance
Note:
Types of Inheritance
Single Inheritance: When one sub class inherits from one super
class, we call this inheritance as Single Inheritance.
Hybrid Inheritance:
When one class can have more than one super class and
can inherit features from all super classes, we call this type
of inheritance as Multiple inheritance.
Java doesn’t support Multiple Inheritance with classes. In
Java we can achieve multiple inheritance only through
interfaces.
Polymorphism
Abstraction
Encapsulation vs Abstraction
Lambda Expressions
Comparable vs Comparator
JDBC
DriverManager: It
uses some database-
specific drivers to
effectively connect
enterprise
applications to
databases.
JDBC drivers: To
communicate with a
data source through
JDBC, you need a
JDBC driver that
intelligently
communicates with the respective data source.