{ }codelper

Learn Java

Learn programming basics in Java. Each lesson has a runnable example and notes on how other languages differ.

A

Basics

4 lessons
  1. 01Printing to the screenYour first line of code: print text and the result of a calculation.
  2. 02Variables and valuesGive a value a name so you can reuse and change it.
  3. 03Reading inputRead text and numbers from the keyboard (standard input).
  4. 04Arithmetic and divisionAdd, subtract and multiply work the same everywhere — division doesn't.
B

Control flow

4 lessons
  1. 05ConditionsDo different things depending on a condition: if · else if · else, plus switch.
  2. 06LoopsDo the same thing many times: for and while.
  3. 07More loopsTaking values one by one, going backwards, reading up to an end marker, and the run-at-least-once do-while.
  4. 08Booleans and the ternary operatorKeeping true/false in a variable, choosing one of two values, and asking "is it one of these?".
C

Data

5 lessons
  1. 09StringsLength, uppercase, reverse, and picking one character.
  2. 10Lists and arraysMany values in a row: count, first and last, sum, transform all.
  3. 11Working with single charactersOne character as a value: its code, letter arithmetic, the i-th character, repeating.
  4. 12Building stringsBuild a string from pieces, join with a separator, print values on one line.
  5. 13Editing listsContains, remove, reverse, swap, fill with one value, copy.
D

Functions

2 lessons
  1. 14FunctionsBundle work under a name, take values and return a result — plus recursion.
  2. 15More about functionsScope, returning several values, and passing functions as values.
E

Going further

10 lessons
  1. 16Dictionaries (maps)Find and update values by key: counting words, checking for a key, iterating in key order.
  2. 17SortingPut values in order: smallest first, largest first, or by a rule you choose.
  3. 182D lists (grids)Grids of rows and columns: reading them, row and column sums, and neighbours inside the bounds.
  4. 19Working with stringsSlicing, finding, replacing, trimming, comparing and padding.
  5. 20Integers and floating pointWhy 0.1 + 0.2 isn't 0.3, printing a fixed number of decimals, rounding rules and integer overflow.
  6. 21RecursionA function that calls itself: base cases, call-stack depth, loops and memoization.
  7. 22Common mistakes and error messagesHow to read error messages, and the mistakes every language shares: off-by-one, = vs ==, integer division, null, out-of-range indexes.
  8. 23Absolute value, powers, square rootsDropping the sign, multiplying many times, and finding the value whose square is a number.
  9. 24Counting, running totals, groupingIn one pass: count what matches, carry the value so far, and collect items by key.
  10. 25Lists of records and enumsCollect records in a list, and give names to a small fixed set of values.
F

Algorithms

8 lessons
  1. 26Simulation and Brute ForceDo exactly what the story says, step by step, and try every candidate without skipping one.
  2. 27Stacks and QueuesA stack hands back the newest item first; a queue hands back the oldest first.
  3. 28Binary SearchThrow away half of a sorted range at a time to find a value, or the first position that meets a condition.
  4. 29Prefix sums and two pointersGet the sum of any range with one subtraction, and find a range by moving two positions forward only.
  5. 30GCD, primes and number basesFind the GCD with remainders, sift out primes with a sieve, and write a number in another base.
  6. 31The greedy method and priority queuesTake what looks best at each step, and use a queue that hands out the smallest value right away.
  7. 32Graphs and depth-first searchWrite down who is connected to whom, then visit everything you can reach.
  8. 33Breadth-first search and topological sortSpread out from the nearest places with a queue to get the fewest steps, and line tasks up so prerequisites come first.
G

Language-specific

3 lessons
  1. 37Classes and objectsPython · JavaScript · TypeScript · Java · C# · C++Bundle data (fields) and behavior (methods) into one blueprint, then make many objects from it.
  2. 38Interfaces and genericsTypeScript · Java · C#An interface promises "these methods exist"; generics let one function work for many types.
  3. 39LINQ and streamsJava · C#Chain filtering, mapping, grouping and sorting into one pipeline instead of writing loops.