References

Java reference

Understand object oriented programs and the JVM.

Java Basics

Start with a class and main method.

Java conditions, arrays, and loops

Count values that satisfy a boundary condition.

Java methods and exception handling

Separate conversion errors from valid numeric values.

Java recursion and bounded factorial

Use a base case and validate the representable range.

Java variables, types, and casting

Declare typed variables and understand integer division, overflow, and conversions.

Java arrays and strings

Work with fixed-size arrays, common String methods, and the difference between == and equals.

Java method overloading, varargs, and pass by value

Declare several methods with the same name and see what a method can and cannot change.

Java constructors and encapsulation

Initialize private fields and validate changes through methods.

Java inheritance and method overriding

Use a superclass reference to call subclass behavior.

Java interfaces and composition

Depend on a contract and inject a collaborating object.

Java abstract classes and enums

Define a shared base with an abstract method, and a fixed set of constants with fields.

Java generics and bounded types

Write one class and one method that work for many types while the compiler checks them.

Java equals, hashCode, and toString

Define when two objects are equal so that they work correctly in sets and maps.

Java ArrayList and generics

Use a resizable, type-checked sequence.

Java binary search and interval bounds

Implement logarithmic search on an ascending array.

Java stacks and balanced brackets

Use a stack to check that brackets are properly nested.

Java ArrayDeque as a queue

Choose queue operations with explicit empty-queue behavior.

Java maps, sets, and duplicate counting

Track counts and distinct values with separate collection roles.

Java singly linked lists

Build a list of nodes by hand, insert at the front and the back, and reverse it.

Java binary search trees

Insert values into a tree that keeps smaller values on the left, and traverse it in sorted order.

Java sorting: insertion sort, merge sort, and comparators

Implement two sorts by hand and sort objects with a Comparator.

Java priority queues and heaps

Always remove the smallest (or largest) item, and find the k largest values.

Java: counting operations to see growth rates

Count loop iterations instead of timing them to compare linear, quadratic, and logarithmic growth.

Java: amortized cost of a growing array

Show that doubling a backing array makes append cost O(1) on average even though some appends copy everything.

Java: a hash join and why it beats a nested loop

Join two collections by building a hash table on one side and probing it with the other.

Java: an ordered index with TreeMap

Use a sorted map the way a database uses an ordered index to answer range and nearest-key queries.

Java: simulating round-robin CPU scheduling

Rotate jobs through a ready queue with a fixed time slice and record when each one finishes.

Java: mutual exclusion with synchronized

Protect a shared counter from lost updates when two threads increment it.

Java: a TCP echo server on the loopback interface

Open a server socket on an ephemeral port and connect to it with a client socket in the same program.

Java: IPv4 addresses, masks, and CIDR blocks

Compute the network address, broadcast address, and host count of a subnet with bitwise operations.

Java: testing a method with a tiny test runner

Check normal cases, boundaries, and error cases, and report which ones pass.

Java: strategy and observer with interfaces and lambdas

Swap behavior behind an interface and notify listeners without coupling the sender to them.

Java: SHA-256 hashing for integrity

Compute a SHA-256 digest with MessageDigest and see that a tiny change produces a completely different value.

Java: storing passwords with a salt and PBKDF2

Derive a password hash with a random salt and many iterations, then verify a login attempt.

Java: splitting work across a thread pool

Divide a sum into chunks, run them on an ExecutorService, and combine the Future results.

Java: parallel streams and CompletableFuture

Count items with a parallel stream and combine two asynchronous results.

Java: breadth-first search for a shortest path

Search a grid with a queue to find the fewest moves from the start to the goal around walls.

Java: game-tree search with minimax (negamax)

Search every move in a take-away game to find which positions are winning for the player to move.

Java: propositional entailment by model checking

Enumerate every truth assignment to decide whether a knowledge base entails a query.

Java: forward chaining with if-then rules

Repeatedly apply rules whose conditions are known until no new facts can be derived.

Java: linear regression with gradient descent

Fit a straight line to data by repeatedly stepping the weights against the gradient of the squared error.

Java: k-nearest-neighbors classification

Classify a point by letting its k closest training points vote.

Java: training a perceptron to learn AND

Update the weights of a single neuron with the perceptron rule until it classifies all four inputs correctly.

Java: a two-layer network that computes XOR

Combine two hidden neurons so that a network solves the problem a single perceptron cannot.

Java: filtering an image with a convolution kernel

Slide a 3×3 averaging kernel over a small grayscale image to smooth it.

Java: finding edges with the Sobel operator

Estimate the horizontal intensity change at each pixel and mark strong edges.