Java was the language of the first serious wave of object-oriented programming for most engineering students, and it still runs a huge share of enterprise back ends, Android apps and big-data tools (Kafka, Elasticsearch, Cassandra). This article revisits the five units of the JNTUK course: the object-oriented ideas and how Java expresses them.
Unit 1: Object-oriented thinking and Java basics
The four pillars
| Pillar | Meaning | Java mechanism |
|---|---|---|
| Encapsulation | Bundle data and the methods that use it, hide the internals | private fields with public getters and setters |
| Abstraction | Expose what something does, hide how | Abstract classes, interfaces |
| Inheritance | A new class reuses and extends an existing one | extends |
| Polymorphism | One interface, many behaviours | Overriding, overloading |
A class is a blueprint; an object is an instance of it. Procedure-oriented languages (C) organise code around functions; object-oriented languages organise it around objects that combine state and behaviour.
How Java runs
Java source (.java) is compiled by javac to bytecode (.class), which the Java Virtual Machine (JVM) runs. This is the “write once, run anywhere” idea. The JRE is the runtime and the JDK adds the compiler and tools. The JVM does just-in-time (JIT) compilation of hot code and garbage collection to free unused objects, so there is no free().
Language basics
- Primitive types:
byte,short,int,long,float,double,char,boolean. Everything else is a reference type, and wrapper classes (Integer,Double) box the primitives. - Operators, control flow, arrays and strings: as in C.
Stringis immutable;StringBuilderis for building text efficiently. - Classes and methods: fields, constructors (which initialize an object and can be overloaded),
this,staticmembers shared by the class, andfinalfor constants. - Command-line input,
Scanner, andpublic static void main(String[] args)as the entry point.
Today: the JVM is also a platform for other languages (Kotlin, Scala, Groovy), and its garbage-collector tuning and heap sizing (
-Xmx) are everyday topics when running Java in containers.
Unit 2: Inheritance, polymorphism and abstraction
Inheritance
A subclass uses extends to inherit the fields and methods of its superclass. Java allows single inheritance of classes (a class has one parent), which avoids the ambiguity of multiple inheritance. super refers to the parent, and the parent constructor runs first. All classes ultimately extend Object.
Polymorphism
| Kind | How | Resolved |
|---|---|---|
| Method overloading | Same name, different parameters in one class | At compile time |
| Method overriding | A subclass redefines a parent method with the same signature | At run time (dynamic dispatch) |
A parent reference can hold a child object (Animal a = new Dog();) and calling a.speak() runs the Dog version. This is what makes code like “process a list of shapes” work without knowing each exact type.
Abstract classes, final and access control
- An abstract class cannot be instantiated and may have abstract methods that subclasses must implement.
finalstops a class from being extended, a method from being overridden or a variable from being changed.- Access modifiers:
| Modifier | Visible to |
|---|---|
private |
The same class |
| (default) | The same package |
protected |
The same package and subclasses |
public |
Everywhere |
The Object class
Every class inherits toString(), equals() and hashCode(). If you override equals(), override hashCode() too, or hash-based collections will misbehave.
Today: polymorphism is the basis of frameworks such as Spring, where you code to an interface and the framework supplies the implementation. “Prefer composition over inheritance” is a modern design guideline: build behaviour by combining objects rather than deep class hierarchies.
Unit 3: Interfaces, packages and inner classes
Interfaces
An interface is a contract: a set of methods a class promises to provide. A class implements any number of interfaces, which is how Java gets the benefits of multiple inheritance without the problems.
| Feature | Abstract class | Interface |
|---|---|---|
| Inheritance | A class extends only one | A class implements many |
| State (fields) | Can have instance fields | Only constants |
| Methods | Abstract and concrete | Abstract, plus default and static methods (Java 8 onwards) |
| Use when | Sharing code between related classes | Defining a capability that unrelated classes share |
A functional interface has a single abstract method and can be written as a lambda expression, such as (a, b) -> a + b. Examples include Runnable, Comparator and Function.
Packages
A package groups related classes and controls naming and access (java.util, com.company.app). The import statement brings classes in. Standard packages: java.lang (imported automatically), java.util, java.io, java.net, java.sql. Modern projects are built with Maven or Gradle, which also manage dependencies.
Inner classes
A class can be declared inside another: member, local, anonymous (a one-off implementation of an interface) and static nested classes. Lambdas now replace most anonymous classes.
Today: the
List,MapandComparatorinterfaces you meet in every program show this idea: you write code againstListand chooseArrayListorLinkedListlater. Dependency injection frameworks rely on interfaces too.
Unit 4: Exception handling and multithreading
Exceptions
An exception is an event that interrupts normal flow. Java organises them in a hierarchy under Throwable.
| Kind | Examples | Must you handle it? |
|---|---|---|
| Checked | IOException, SQLException |
Yes, with try/catch or throws |
| Unchecked (runtime) | NullPointerException, ArrayIndexOutOfBoundsException |
Not required |
| Errors | OutOfMemoryError, StackOverflowError |
Usually not recoverable |
Syntax: try (code that may fail), catch (handler), finally (always runs, for cleanup), throw (raise one) and throws (declare it). try-with-resources closes files and connections automatically. You can define custom exceptions by extending Exception.
Multithreading
A thread is a unit of execution inside a process; threads share memory, so they must coordinate. You create one by extending Thread or implementing Runnable (or using an executor).
| Concept | Meaning |
|---|---|
| Thread states | New, runnable, running, blocked or waiting, terminated |
| Synchronization | The synchronized keyword gives one thread at a time access to a block; prevents race conditions |
| Inter-thread communication | wait(), notify(), notifyAll() |
| Deadlock | Two threads each wait for a lock the other holds |
| Thread pools | ExecutorService reuses threads instead of creating new ones |
| Priorities | Hints to the scheduler, not guarantees |
Modern Java adds java.util.concurrent (concurrent collections, locks, atomic variables), CompletableFuture for asynchronous work and, in recent versions, virtual threads that make very large numbers of concurrent tasks cheap.
Today: web servers handle each request on a thread, which is why “thread pool exhausted” appears in production incidents. Thread dumps (
jstack) reveal deadlocks, and aNullPointerExceptionin a log is the most common Java error you will read.
Unit 5: Collections, I/O, GUI and database access
Collections framework
| Interface | Implementations | Behaviour |
|---|---|---|
| List | ArrayList, LinkedList |
Ordered, allows duplicates; ArrayList is fast for random access |
| Set | HashSet, LinkedHashSet, TreeSet |
No duplicates; TreeSet keeps them sorted |
| Map | HashMap, LinkedHashMap, TreeMap |
Key-value pairs |
| Queue / Deque | PriorityQueue, ArrayDeque |
FIFO, priority or double-ended |
Generics (List<String>) make collections type-safe at compile time. Iterators and the enhanced for loop traverse them, and Comparable and Comparator define ordering. The Stream API (Java 8) processes collections with filter, map and collect, for example list.stream().filter(x -> x > 10).count().
Input and output
java.io uses streams: byte streams (InputStream, OutputStream) and character streams (Reader, Writer), with BufferedReader for efficiency. File and the newer java.nio.file package manage files, and serialization converts objects to bytes.
GUI and events
The AWT and Swing toolkits build desktop interfaces with components (buttons, text fields), layout managers and event handling through listeners (ActionListener). JavaFX is the newer option. Applets, once in the syllabus, are obsolete.
Database connectivity
JDBC connects Java to databases: load the driver, open a Connection, create a PreparedStatement (which also prevents SQL injection), run a query and read the ResultSet. In practice, frameworks such as JPA/Hibernate map classes to tables.
Today:
HashMap,ArrayListand streams fill most application code. Spring Boot builds on the same ideas (interfaces, annotations, JDBC underneath) and is the standard for Java micro-services, which are typically packaged in a Docker image and deployed on Kubernetes.
One-minute recap
| Unit | Key idea | You meet it in |
|---|---|---|
| 1. OOP basics and Java | Four pillars; bytecode and the JVM | JVM tuning, container memory limits |
| 2. Inheritance and polymorphism | extends, overriding, dynamic dispatch |
Framework design, polymorphic APIs |
| 3. Interfaces, packages | Contracts, lambdas, Maven and Gradle | Dependency injection, build pipelines |
| 4. Exceptions and threads | Checked vs unchecked; synchronized, thread pools |
Thread dumps, race conditions, deadlocks |
| 5. Collections, I/O, JDBC | List, Set, Map, streams, JDBC | Spring Boot services, database access |
Next in Engineering Revisited: Principles of Communications.
Written by Claude, Anthropic’s AI assistant, as part of Engineering Revisited, a quick refresher of the B.Tech subjects one at a time.