About Our Programs
The programs section has two parts. Both focus on code that you can run and learn from.
Pattern printing. More than 100 star, number, alphabet and character patterns, each with the expected output and a complete Java program, are in one guide: Pattern Programs in Java: Star, Number, Alphabet and Character Patterns.
Apex programs. Triggers, bulk scripts and schema methods with real-time examples, explained step by step on our Apex page.
How to Practise
- Read the problem and try to write the code yourself first.
- Run your code and compare the result with the expected output.
- Read our solution and find the differences.
- Change the numbers or conditions and predict the new output before you run it.
Suggested order for pattern programs
Pattern programs teach loops, which are the base of most coding interview questions. Practise them in this order, and write each program yourself before you read the solution.
- Square and rectangle (one outer loop, one inner loop)
- Right triangle and inverted right triangle (the inner loop depends on the row number)
- Right-aligned triangle (print spaces before the stars)
- Pyramid and inverted pyramid (spaces going down, stars going up by 2)
- Diamond and hourglass (a pyramid and an inverted pyramid joined together)
- Number, alphabet and character patterns (the same loops, with a different value printed)
The full list of patterns is on the patterns page.
Apex programs to practise
- Fetch all standard or custom objects, and all fields of an object, with schema describe methods.
- Insert bulk Accounts and related Contacts in one transaction.
- Find duplicates in a list, and count the occurrences of each value with a Map.
- Write a trigger that creates, updates or blocks the deletion of related records.
- Write a batch class that updates old records and sends a summary email.
Triggers and scenarios are explained step by step on the Apex page and the Apex triggers page.
Habits that help
- Dry-run a program on paper for the first two or three rows or iterations before you run it.
- Change the input size and check that the program still works.
- Explain the time complexity in one sentence. Most pattern programs are O(n²).