Interview Question

Java Tutorial Basics to Advance

Java Tutorial Basics to Advance
Java Tutorial Basics to Advance

Java tutorial Basics to Advance are the fastest way to turn textbook theory into real coding ability. Reading about loops does not make you a programmer. Writing two hundred small programs does.

This tutorial gives you a structured practice roadmap for 2026: seven levels, from your first Hello World to sorting algorithms, recursion and file handling. Every exercise below is a problem statement with a hint, not a finished solution, because the struggle is where the learning happens.

Who This Java Practice Tutorial Is For

  • BCA and MCA students preparing for semester practicals and lab files
  • B.Tech CS/IT students building a base before DSA and placement rounds
  • Diploma and first-year students who have finished Java syntax but cannot yet write programs independently
  • Self-learners switching to Java from Python, C or PHP
  • Interview candidates who need to code confidently on paper or a whiteboard

What You Need Before Starting Java Tutorial: Basics to Advanced

  • JDK 21 or newer installed and added to your system PATH
  • An editor or IDE: IntelliJ IDEA Community, VS Code with the Java pack, or Eclipse
  • Basic syntax knowledge: variables, data types, operators, and how a class and main() Methods are structured
  • A dedicated practice folder with one subfolder per level, so your work stays organised

Verify your setup before you begin:

java -version
javac -version

How to Use This Exercise Roadmap

  • Do not skip levels. Each level assumes the previous one is comfortable, not memorised
  • Time-box every problem. Give yourself 20 minutes. If you are stuck, read the hint, not a solution
  • Type the code manually. Copy-paste teaches nothing
  • Test edge cases every time: zero, negative values, empty input, single-element arrays
  • Rewrite from scratch after a week. If you cannot rebuild it without notes, you have not learned it
  • Commit to Git daily. A public repository of 150 solved exercises is a real placement asset

Level 1 – Java Basics and Conditional Logic

Goal: get comfortable with compiling, printing output and branching.

  • Hello World: compile and run from the terminal, not just the IDE run button
  • Pass or fail checker: print PASS when marks are 50 or above, FAIL otherwise
  • Odd or even: use the modulus operator on an integer variable
  • Largest of three numbers: solve it twice, once with nested if and once with the ternary operator
  • Digit to word: convert 1 to 9 into ONE through NINE using a switch expression
  • Day of week printer: map 0 to 6 onto Sunday through Saturday, with a default for invalid input
  • Leap year checker: divisible by 4 but not 100, unless also divisible by 400
  • Grade calculator: convert a percentage into an A to F grade band

Modern switch expressions are cleaner than the old switch-case-break style. Practise both, because university exams still expect the classic form:

String day = switch (dayNumber) {
    case 0 -> "Sunday";
    case 1 -> "Monday";
    case 6 -> "Saturday";
    default -> "Invalid day";
};
System.out.println(day);

Level 2 – Loops, Nested Loops and Pattern Printing

Goal: control repetition and think in rows and columns. Pattern questions appear constantly in Indian university practicals and first-round interviews.

  • Sum and average of all integers from a lower bound to an upper bound
  • Factorial of a number, then observe where int overflows and switch to long
  • Multiplication table formatted into aligned columns using printf
  • Fibonacci series: print the first 20 terms and their average
  • Reverse an integer and separately sum its digits, using repeated modulus and division
  • Armstrong, perfect and prime number checkers
  • Square, triangle, pyramid and diamond patterns built with nested loops
  • Number pyramid and Pascal triangle
  • Approximate pi using an alternating series and compare against Math.PI

The universal skeleton for any two-dimensional pattern:

for (int row = 1; row <= size; row++) {
    for (int col = 1; col <= size; col++) {
        System.out.print(condition ? "* " : "  ");
    }
    System.out.println();
}

Name your loop variables row and col, never i and j. Examiners notice readable code.

Level 3 – User Input, Strings and Character Handling

Goal: build programs that respond to real input instead of hardcoded values.

  • Simple calculator reading two numbers and an operator from Scanner
  • Circle and cylinder calculator printing results rounded to two decimal places
  • Income tax calculator using progressive slab rates
  • Sentinel loop: keep accepting input until the user enters -1
  • Input validation loop that rejects out-of-range marks and re-prompts
  • Reverse a string manually using charAt(), without StringBuilder
  • Count vowels, consonants and digits in a sentence and show percentages
  • Palindrome checker for both single words and full phrases, ignoring spaces and case
  • Caesar cipher: encrypt and decrypt with a shift of three
  • Binary, octal and hexadecimal validators and converters to decimal
  • Word frequency counter for a paragraph of text

Level 4 – Arrays and Methods

Goal: work with collections of data and break programs into reusable functions.

  • Print an array as [a1, a2, a3] with no trailing comma
  • Find minimum, maximum, average and median of an integer array
  • Standard deviation calculator for a set of student marks
  • Linear search returning the index or -1
  • Reverse an array in place using two pointers moving inward
  • Remove duplicates from an array without using a Set
  • Second largest element found in a single pass
  • Matrix operations: addition, subtraction, multiplication and transpose on 2D arrays
  • Grade histogram printed both horizontally and vertically
  • Method overloading practice: write a print() method for int[]double[] and String[]
public static void reverse(int[] array) {
    for (int front = 0, back = array.length - 1; front < back; front++, back--) {
        int temp = array[front];
        array[front] = array[back];
        array[back] = temp;
    }
}

Level 5 – Recursion and Object-Oriented Programming

Goal: think recursively and start designing with classes rather than a single long main() method.

Recursion Exercises

  • Factorial and Fibonacci written recursively, then compared with the loop version for speed
  • GCD using the Euclidean algorithm
  • Tower of Hanoi with a printed move sequence
  • Recursive binary search on a sorted array
  • Sum of digits and string reversal without any loop
  • Permutations of a short string

OOP Exercises

  • BankAccount class with private balance, deposit, withdraw and overdraft protection
  • Student class with encapsulated fields, a constructor and a toString() override
  • Shape hierarchy: an abstract Shape with Circle, Rectangle and Triangle subclasses
  • Interface practice: a Payable interface implemented by Employee and Contractor
  • DateUtil utility class with leap year checking, date validation and day-of-week calculation
  • Custom exception: throw an InsufficientBalanceException from your bank account

Level 6 – Algorithms, Sorting and Searching

Goal: implement the algorithms that dominate placement tests. Write each one yourself before ever calling Arrays.sort().

  • Bubble sort with an early-exit flag for already sorted arrays
  • Selection sort and insertion sort
  • Merge sort and quick sort, both recursive
  • Heap sort using an array-backed heap
  • Binary search in both iterative and recursive forms
  • Sieve of Eratosthenes for all primes below a limit
  • Prime factorisation of a large integer
  • Perfect, deficient, and abundant number classification
  • Time comparison: benchmark your sorts on 10,000 random values using System.nanoTime()

Learn to state the time complexity of each one out loud. Viva examiners ask for it far more often than they ask for the code.

Level 7 – Advanced Java Practice

Goal: move from academic exercises to production-style Java.

  • Collections: rebuild your array exercises using ArrayList, HashMap, HashSet and TreeMap
  • Generics: write a type-safe Pair<K, V> class and a generic max() method
  • Streams and lambdas: filter, map, sort and group a list of Student objects in a single chain
  • File handling: read a CSV of marks, calculate statistics and write a formatted report
  • Exception handling: practise try-with-resources and multi-catch blocks
  • Multithreading: the classic producer-consumer problem using wait() and notify()
  • JDBC: connect to MySQL and build full CRUD operations for a student table
  • Mini project: a console library management system combining collections, files and OOP
List<String> toppers = students.stream()
        .filter(s -> s.getMarks() >= 75)
        .sorted(Comparator.comparing(Student::getName))
        .map(Student::getName)
        .toList();

Suggested 8-Week Practice Plan

WeekFocusTarget
1Level 1 – Basics and conditionals15 programs
2Level 2 – Loops and patterns20 programs
3Level 3 – Input and strings18 programs
4Level 4 – Arrays and methods20 programs
5Level 5 – Recursion12 programs
6Level 5 – OOP concepts10 classes
7Level 6 – Sorting and searching12 algorithms
8Level 7 – Collections, streams, JDBC1 mini project

Common Mistakes That Slow Learners Down

  • Reading solutions too early. Twenty minutes of being stuck teaches more than an hour of reading correct code
  • Ignoring integer division. In Java, 5 / 2 gives 2, not 2.5. Cast to double before dividing
  • Comparing strings with ==. Use equals() for content comparison, always
  • Meaningless variable names like a, b, x1 and n. Use totalMarksstudentCountupperBound
  • Skipping edge cases. Test empty arrays, negative numbers and zero on every single program
  • Never refactoring. Once a program works, rewrite it shorter and cleaner
  • Practising without version control. Push to GitHub daily and your practice becomes a portfolio

Want video walkthroughs of these exercises with complete solutions explained line by line?

Subscribe to DecodeIT2 on YouTube

Frequently Asked Questions

How many Java exercises should I complete before applying for jobs?

Aim for 100 to 150 solved problems spread across all seven levels. Quality matters more than volume. Fifty programs you can rewrite from memory beat three hundred you copied.

Should I use an IDE or a plain text editor for practice?

Start with a text editor and the terminal for Level 1 and 2 so you understand compilation and classpath errors. Switch to IntelliJ or Eclipse from Level 3 onward, once debugging and refactoring become more valuable than manual compiling.

Are these Java exercises enough for placement preparation?

Levels 1 to 6 build the foundation you need. After finishing them, move to dedicated data structures and algorithms practice covering trees, graphs, stacks, queues and dynamic programming.

Which Java version should I practise with in 2026?

Use JDK 21 or newer. It is a long-term support release with switch expressions, records, text blocks and pattern matching, all of which now appear regularly in interviews.

Do I need to memorise these programs for my university exam?

No. Understand the logic pattern instead. Most exam questions are variations of the same core patterns: accumulate in a loop, extract digits with modulus and divide, use two pointers, or use a boolean flag. Master those four and you can derive almost any answer on the spot.

Final Notes

  • Programming is a skill built by repetition, not by reading
  • Write code every day, even for just thirty minutes
  • Solve first, optimise second, refactor third
  • Keep every solution in a Git repository and your practice becomes proof of ability

Work through these levels honestly and you will finish with something far more valuable than a lab file: the ability to sit in front of a blank editor and build whatever is asked of you.

Source Code Available

Interested in This Project?

Get the complete source code for this project at a very affordable price — perfect for your portfolio, college submission, or learning. Message us on WhatsApp and we'll get back to you instantly!

Full source code included Step-by-step setup guide Instant delivery on WhatsApp Instant reply on WhatsApp
Chat on WhatsApp

We usually reply within a few minutes

2 responses to “Java Tutorial Basics to Advance”

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat with us