Loading…
Loading…
Language
Articles and problems tagged Java.
Object is the superclass of every Java class. Learn what Object variables can hold, the difference between == and equals, how to write a correct equals method, the five rules of the equals contract, getClass vs instanceof in class hierarchies, and the classic mistakes to avoid.
Control and navigate Java class hierarchies: final classes and methods (and why constructors should never call overridable methods), casting object references safely, ClassCastException, pattern matching for instanceof, record patterns, and how protected access really works.
Understand polymorphism in Java: the is-a rule and substitution principle, declared vs actual types, why arrays are covariant and throw ArrayStoreException, the exact steps of a method call (overload resolution, static vs dynamic binding, method tables), covariant return types and override rules.
Learn Java inheritance step by step: defining subclasses with extends, what a subclass inherits, overriding methods and calling super.method(), the @Override annotation, subclass constructors with super(...), inheritance hierarchies, and why Java has no multiple inheritance of classes.
Seven practical rules for designing Java classes: keep data private, initialize everything, replace primitive clusters with classes, skip needless getters and setters, split classes with several responsibilities, choose good names, and prefer immutability, illustrated with records and enums.
Write professional Java API documentation with javadoc: /** */ comments for classes, methods, fields and packages, @param, @return, @throws, @see and {@link}, {@code} and HTML, code snippets (Java 18), Markdown doc comments (Java 23), and generating HTML with the javadoc tool.
Package Java applications and libraries as JAR files: the jar tool and its options, the META-INF/MANIFEST.MF manifest, executable JARs with Main-Class and java -jar, multi-release JARs, modern --long options, JDK_JAVA_OPTIONS, fat JARs and jpackage installers.
Understand Java's default package access and why forgetting private breaks encapsulation, then master the class path: how the JVM and javac locate classes in directories and JAR files, -cp and --class-path, wildcards, the CLASSPATH variable, and fixing ClassNotFoundException.
How Java packages organize classes and prevent name clashes: reverse-domain package names, fully qualified names, single-type and on-demand imports, resolving conflicts like java.util.Date vs java.sql.Date, static imports, module imports in Java 25, and placing classes into packages and directories.
Java records explained: declaring immutable data carriers in one line, components and accessors like x(), generated toString, equals and hashCode, adding methods and static members, canonical, compact and custom constructors for validation and normalization, and when to choose a record over a class.
Every way to initialize Java objects: overloading and signatures, default field values, no-argument constructors, field initializers, parameter naming with this, calling this(...), initialization blocks, static initializers, construction order and cleanup without destructors.
Java always passes arguments by value, including object references. See why a method can't change a primitive argument, why it can change an object's state, why a swap method can't work, how this differs from C++ references, and how to return several results instead.
What static means in Java: static fields shared by all objects, static final constants like Math.PI and System.out, static methods without this, when to use them, static factory methods (and why they beat constructors), and why main is static, plus Java 25 instance main methods.
Why Java classes hide their fields behind methods: the benefits of accessors and mutators, the danger of returning mutable objects (and defensive copies), class-based access to private data, private helper methods, and final instance fields, including final references to mutable objects.
Write your first real Java class: an Employee with private fields, a constructor and methods. Covers multiple classes and source files, how javac finds dependencies, constructor rules, var for local variables, handling null with Objects.requireNonNull, and implicit vs. explicit parameters and this.
Learn to work with objects from the Java library: constructors and new, the difference between objects and object variables, references and null, why Java has LocalDate instead of a date type, factory methods, accessor vs. mutator methods, and a complete calendar program.
The ideas behind object-oriented programming in Java: classes and objects, encapsulation, an object's behavior, state and identity, finding classes from nouns and verbs, and the uses-a, has-a and is-a relationships between classes with UML notation.
Sort and search arrays with java.util.Arrays, draw raffle winners without repeats, generate random numbers the modern way, build tables with two-dimensional arrays, and understand Java's arrays of arrays: deepToString, swapping rows, and ragged (triangular) arrays.
One-dimensional Java arrays: declaring and creating arrays, initializers and anonymous arrays, default values, indexes and ArrayIndexOutOfBoundsException, the enhanced for-each loop, printing with Arrays.toString, reference vs. value copying with Arrays.copyOf, and command-line arguments.
When long and double aren't enough: BigInteger for huge whole numbers and BigDecimal for exact decimal arithmetic like money. Covers valueOf vs constructors, add/multiply/divide/mod/pow, why new BigDecimal(0.1) is wrong, scale and rounding modes, compareTo vs equals, and performance tips.