Java Documentation
Concise, example-driven Java reference. Read the concept, see the code, then practice it in a Coddy journey.
Start a guided Java journeyGetting Started
- What Is JavaWhat Java actually is, how the JVM lets one compiled program run anywhere, and the kinds of software Java is used to build.
- Install JavaHow to install the Java Development Kit (JDK), pick a version and vendor, and confirm java and javac work from the command line.
- Running JavaThe two-step compile-then-run cycle behind every Java program: turn .java source into bytecode with javac, then run the .class file with java.
- Java SyntaxThe shape of a Java program - the `main` method, statements and semicolons, blocks and braces, and the rules that the compiler enforces before your code ever runs.
- CommentsHow to write comments in Java - single-line // comments, multi-line /* */ blocks, and Javadoc /** */ doc comments - plus when to use each and what to avoid.
Variables & Types
- VariablesHow variables work in Java - declaring with a type, assigning values, naming rules, the var keyword, constants with final, and the scope rules that decide where a variable lives.
- Data TypesJava's data types explained - the eight primitive types, reference types, default values, literals and suffixes, overflow, and when to use which numeric type.
- StringsHow Java strings work - creating them, joining with +, why they are immutable, comparing with equals, and the everyday String methods like length, substring, and replace.
- String FormatHow to format strings in Java with String.format and printf - the format specifiers for numbers, padding, decimals, and the text blocks and formatted method.
- OperatorsHow Java operators work - arithmetic, comparison, logical, assignment, increment, and the ternary operator - plus integer division, precedence, and the gotchas that bite beginners.
- Type CastingHow Java converts between types - automatic widening, explicit narrowing casts, what data you lose when narrowing, and converting between numbers and strings.
Control Flow
- if-elseHow to make decisions in Java with if, else if, and else - boolean conditions, chaining branches, nesting, the ternary operator, and the common mistakes that trip people up.
- switchThe Java switch statement explained - case labels, break and fall-through, the default branch, grouping cases, the modern arrow form, and switch expressions.
- for LoopThe Java for loop explained - the classic three-part loop, looping over arrays and lists, nested loops, break and continue, and the enhanced for-each.
- while LoopsThe Java while loop explained - the condition-first while, the run-at-least-once do-while, reading input until a sentinel, break and continue, and avoiding infinite loops.
- for-each LoopThe Java for-each (enhanced for) loop explained - clean iteration over arrays and collections, when to use it, and the modification gotcha that trips everyone up.
Arrays & Collections
- ArraysHow arrays work in Java - fixed length, declaring and initializing them, indexing, length, looping, multidimensional arrays, and the Arrays helper class.
- ArrayListHow to use Java's ArrayList - the resizable list you reach for instead of a plain array - covering add, get, remove, size, looping, and sorting.
- HashMapHow to use Java's HashMap for key-value lookups - put, get, getOrDefault, containsKey, iterate over entries, and the patterns you reach for most.
- HashSetHow to use Java's HashSet for collections of unique values - add, contains, remove, dedupe a list, and combine sets with union, intersection, and difference.
- Iterating CollectionsThe ways to loop over Java collections - the for-each loop, the Iterator, index loops, and the forEach method - and how to remove elements safely while iterating.
Methods
- MethodsWhat a Java method is, how to declare and call one, return values vs void, the static main method, and how methods keep code organized and reusable.
- Method ParametersHow Java method parameters work - passing arguments, the difference between parameters and arguments, Java's pass-by-value rule, and returning values.
- Method OverloadingHow Java method overloading lets several methods share a name but take different parameters, how the compiler picks an overload, and the ambiguity traps to avoid.
- VarargsHow Java's varargs (...) let a method accept any number of arguments, how they become an array, the one-vararg-last rule, and the empty-call and ambiguity gotchas.
Classes & Objects
- ClassesWhat a Java class is, how to define fields and methods, create objects with new, the role of this, and why instance state lives on the object.
- ConstructorsHow Java constructors work: the default constructor, parameterized constructors, this, constructor overloading, and chaining with this() and super().
- InheritanceHow a Java subclass inherits fields and methods with extends, calls the parent through super, and overrides behavior - plus the common gotchas.
- InterfacesWhat a Java interface is, how to define and implement one, default and static methods, and how interfaces differ from abstract classes.
- Abstract ClassesWhat a Java abstract class is, how to declare abstract methods, why you can't instantiate one, and when to choose an abstract class over an interface.
- PolymorphismHow Java polymorphism lets one variable refer to many types, why overridden methods dispatch at runtime, and how to use upcasting, downcasting, and instanceof safely.
- Access ModifiersHow Java's four access levels - public, private, protected, and package-private - control what other code can see and touch.
- Static MembersWhat the static keyword does in Java, how static fields and methods belong to the class instead of objects, and when to reach for static blocks and constants.
- EnumsWhat a Java enum is, how to declare one, add fields and methods, switch over it, and why an enum beats a pile of int or String constants.
Generics & Functional
- GenericsWhat Java generics are, how to write generic classes and methods, bounded type parameters, wildcards, and why type erasure matters.
- Lambda ExpressionsWhat a Java lambda expression is, the arrow syntax, how it implements a functional interface, method references, and capturing variables.
- StreamsHow to process collections with Java's Stream API - filter, map, sorted, collect, count, and reduce - building readable pipelines instead of manual loops.
- OptionalWhat java.util.Optional is, how to create one, and how to read its value safely with map, filter, orElse, and ifPresent instead of null checks.
Errors & Debugging
- ExceptionsWhat a Java exception is, how to read a stack trace, the checked vs unchecked distinction, the exception hierarchy, and how to throw your own.
- try-catchHow to use Java's try-catch to handle exceptions - catching specific types, the finally block, try-with-resources, and the mistakes that hide bugs.
- NullPointerExceptionWhat a Java NullPointerException really means, the common ways you trigger one, how to read the message, and the patterns that prevent it.