Fundamentals 19 min read

Summary of Java Fundamentals and Core Concepts

This article provides a comprehensive review of essential Java fundamentals, covering object‑oriented principles, primitive types, strings, final keyword, abstract classes and interfaces, class loading order, packages, exceptions, generics, reflection, enums, serialization, dynamic proxies, multithreading, I/O streams, network programming, and Java 8 features.

Java Captain
Java Captain
Java Captain
Summary of Java Fundamentals and Core Concepts

Java Fundamentals Summary

This article is a personal summary written while reviewing Java core concepts. It aims to deepen understanding of many Java topics, many of which are difficult to grasp fully without exploring their underlying implementation.

The author has studied each part in depth and provided code examples, attempting to cover most basic Java knowledge points, though some omissions or errors may exist.

Three Major OOP Features

Inheritance: A class can inherit only one superclass; inner classes can achieve multiple inheritance; interfaces can extend multiple interfaces. Encapsulation: Access levels are public > protected > package > private; inner classes also provide encapsulation. Polymorphism: Compile‑time polymorphism appears in up‑casting and down‑casting, determining which method to call based on the reference type (static dispatch). Runtime polymorphism occurs when methods with the same name have different parameter lists (dynamic dispatch).

Primitive Data Types

1. Size of primitive types, autoboxing, constant pool. 2. For example, a byte occupies 1 byte (8 bits) and can represent values from –128 to 127 (256 distinct values). 3. On 32‑bit and 64‑bit machines, int is 4 bytes (32 bits), char is 1 byte (8 bits), float is 4 bytes, double is 8 bytes, long is 8 bytes. 4. Wrapper classes use the constant pool only for values –128 to 127; values outside this range create new objects.

String and Wrapper Classes

1. String is a final class; its memory address is immutable after allocation. 2. Internally it holds a final char[] array whose address is also immutable. 3. Although the array cannot be accessed directly, its contents can be changed via reflection, but this does not alter the original String instance. 4. Assigning a new literal (e.g., str = "abc" ) only changes the reference, not the original object. 5. StringBuffer and StringBuilder use a mutable char[] array and inherit from AbstractStringBuilder.

final Keyword

1. When applied to primitive types, it guarantees immutability. 2. When applied to a reference, it prevents the reference from pointing to another object. 3. When applied to a class, the class cannot be subclassed; its methods cannot be overridden, which affects frameworks like CGLIB that rely on subclassing for dynamic proxies. 4. When applied to a method, the method cannot be overridden by subclasses.

Abstract Classes and Interfaces

1. Abstract classes may contain method implementations, non‑final fields, and constructors; they can be instantiated only by subclasses. 2. Interfaces can extend multiple other interfaces (multiple inheritance). All fields are implicitly public static final, and methods are abstract (no bodies) unless they are default or static (Java 8+). Interfaces cannot be instantiated but can be used as reference types.

Code Blocks and Loading Order

When a class is instantiated for the first time, static members and static blocks are initialized in the order they appear in the source code, followed by instance blocks and finally the constructor.

Packages, Inner and Outer Classes

1. Java projects follow a directory structure that mirrors the package hierarchy (e.g., src/com/example/A.java ). 2. An outer class can be declared public or package‑private; a public class is accessible everywhere, while a package‑private class is accessible only within its package. 3. Inner classes have the same access modifiers as regular members; a non‑static inner class is tied to an instance of its outer class, whereas a static inner class is independent and can be accessed via OuterClass.InnerClass .

Exceptions

1. The top of the exception hierarchy is Throwable , with subclasses Error and Exception . Exception further divides into RuntimeException (unchecked) and other checked exceptions. 2. Error represents unrecoverable JVM errors. 3. Runtime exceptions arise from programming mistakes (e.g., ArrayIndexOutOfBoundsException ) and are not required to be caught. 4. Checked exceptions (e.g., IOException , SQLException ) must be declared or handled. 5. Logging frameworks such as Log4j and SLF4J are essential for reporting exceptions.

Generics

1. Java generics are a compile‑time feature; type information is erased at runtime. 2. A generic class can be declared as class A&lt;T&gt; { ... } , allowing fields and methods to use T as a type placeholder. 3. Generic methods can declare their own type parameters, e.g., void <E> go(); . 4. Wildcards ( ? ) enable unbounded or bounded type parameters (e.g., ? extends Number ).

Class and Object Classes

1. The foundation of Java reflection is the Class class, which holds metadata for each loaded class. 2. Class instances can be obtained via A.class , new A().getClass() , or Class.forName("com.example.A") . 3. Object is the root of the class hierarchy, providing common methods inherited by all classes.

javac and java

1. javac compiles Java source files with various options for classpath, source version, etc. 2. java runs compiled classes or JAR files, also supporting command‑line arguments. 3. javap disassembles class files, revealing bytecode and other details.

Reflection

1. The reflection API provides classes such as Class , Method , Field , and Constructor to inspect and manipulate class members at runtime. 2. Private members can be accessed by calling setAccessible(true) . 3. Dynamic proxies generate bytecode at runtime, define the proxy class via defineClass , and invoke methods on the target object through an InvocationHandler .

Enum Types

1. Enums implicitly extend java.lang.Enum , and each enum constant is a singleton instance. 2. Enums are useful for representing a fixed set of constants (e.g., days of the week). 3. The compiler implements enums as syntactic sugar, initializing them with a static block and ensuring immutability of their fields.

Serialization

1. A class must implement Serializable to be serializable. 2. The transient modifier excludes fields from the serialized form. 3. Custom serialization logic can be provided via readObject and writeObject methods.

Dynamic Proxies

1. JDK dynamic proxies work for interfaces; CGLIB proxies can target concrete classes. 2. Proxies generate bytecode at runtime, define the class with defineClass , and create an instance. 3. An InvocationHandler (JDK) or MethodInterceptor (CGLIB) handles pre‑ and post‑processing of method calls.

Multithreading

1. Threads can be created by extending Thread or implementing Runnable ; thread pools and Callable / Future enable result retrieval. 2. A thread has seven states: NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, TERMINATED. 3. Thread.join() causes one thread to wait for another to finish. 4. Object.wait() releases the monitor and blocks; notify() wakes a waiting thread without releasing the lock. 5. synchronized uses a mutex; the JVM maintains a wait queue for contended locks, resulting in a non‑fair lock. 6. Thread.sleep() and Thread.interrupt() affect the current thread. 7. Starting a thread twice throws IllegalThreadStateException .

I/O Streams

1. Java I/O includes byte streams, character streams, and file streams. 2. Many I/O classes follow the Decorator pattern, allowing buffering and conversion between byte and character streams; encoding issues can cause garbled output. 3. I/O streams are fundamental to network programming; sockets provide input and output streams for TCP communication, handling segmentation, error checking, retransmission, and flow control.

Network Programming

1. TCP sockets use streams; UDP uses DatagramPacket with fixed‑size packets. 2. Java offers APIs such as URL and InetAddress to simplify network operations.

Java 8

1. Interfaces can contain default methods with implementations. 2. Lambda expressions enable functional programming; a functional interface has a single abstract method. 3. Optional provides a container for nullable values. 4. Various API updates include changes to collections like HashMap . 5. The Stream API introduces functional-style operations on collections, supporting map, filter, reduce, and parallel execution.

PS: If you find this sharing useful, feel free to like and share.

(End)

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaGenericsOOP
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.