SoftwareTestPilot

Beginner · Certificate included

Java Programming Basics for QA Engineers

8 practical lessons in 45 minutes: the Java a QA engineer really uses — setup, types and Strings, conditions and loops, methods, OOP for Page Objects, collections for test data, exceptions and files, and your first TestNG + Selenium-ready project.

8 lessons45 minCertificate+90 points
01

Lesson 1 of 86 min read

Why Java for QA, and your setup

Java is the most common language in QA job listings for Selenium automation, especially at service companies, banks and large enterprises. In this lesson you install the JDK, create a Maven project and run your first program, and you learn what every line of 'Hello World' actually means — a classic interview question.

Key takeaways

  1. 1Install a JDK (Java 17 or 21 LTS, e.g. Eclipse Temurin). Check with java -version and javac -version. JDK = tools to compile + run; JRE = only run; JVM = the engine that runs bytecode.
  2. 2Use IntelliJ IDEA Community (or Eclipse). Create a Maven project: Maven downloads libraries (Selenium, TestNG, RestAssured) listed in pom.xml, so you never copy JAR files by hand.
  3. 3Java is compiled: javac turns .java source into .class bytecode, and the JVM runs that bytecode on any OS. 'Write once, run anywhere' is why the same test runs on Windows laptops and Linux CI.
  4. 4Every program starts at public static void main(String[] args). File name must match the public class name: LoginTest.java contains public class LoginTest.
  5. 5Java is strict: every statement ends with ;, blocks use { }, and it's case-sensitive (String is not string). The compiler catches many mistakes before the test even runs.

Maven project layout + first program

qa-java/ pom.xml src/main/java/ # helpers, page objects src/test/java/ # test classes

Java
// src/test/java/HelloQa.java
public class HelloQa {
    public static void main(String[] args) {
        String tester = "Riya";
        int bugsFound = 7;
        System.out.println(tester + " found " + bugsFound + " bugs today");

        if (bugsFound > 5) {
            System.out.println("Busy day! Retest the fixes.");
        }
    }
}

// Output:
// Riya found 7 bugs today
// Busy day! Retest the fixes.

Go deeper

Expert notes beyond the basics

4 topics
  1. 01

    JDK, JRE and JVM in one picture

    The JVM (Java Virtual Machine) runs bytecode. The JRE (Runtime Environment) is the JVM plus the standard libraries needed to run programs. The JDK (Development Kit) is the JRE plus developer tools such as javac (compiler), jar and a debugger. Testers need the JDK because we compile tests. Since Java 11 a separate JRE download mostly disappeared, so 'install the JDK' is the right answer. Interviewers ask this to check you understand the toolchain, not just the IDE.

  2. 02

    Why Maven matters from day one

    Without Maven you'd download Selenium JARs by hand, add them to the classpath and repeat on every machine. With Maven you list dependencies in pom.xml and run mvn test; Maven downloads exact versions into ~/.m2 and the same command works in Jenkins or GitHub Actions. Learn the lifecycle words: compile, test, package, install. Gradle is an alternative with the same idea. Many interview questions ask 'how do you run tests from CI?' — the answer starts with mvn test (or mvn test -Dgroups=smoke).

  3. 03

    Java versions: which one to use

    Pick an LTS (Long-Term Support) release: Java 17 or 21. Selenium 4 needs Java 11+, and modern libraries increasingly require 17. Useful newer features you'll see in examples: var for local variables (Java 10), switch expressions with -> (Java 14), text blocks with triple quotes for JSON payloads (Java 15), and records for small data classes (Java 16). If a project fails to compile with 'invalid target release', the pom's maven.compiler.release doesn't match the installed JDK.

  4. 04

    Reading your first compiler errors

    javac reports file name, line number and the problem. Common ones: 'cannot find symbol' (typo, missing import or variable declared later), 'class X is public, should be declared in a file named X.java', 'missing return statement', and '; expected'. Because Java checks these before running, many bugs a Python or JavaScript tester would find at runtime are caught at compile time. Fix the FIRST error first; later errors are often side effects.

Common mistakes to avoid

  • - Installing only a JRE and then wondering why javac or Maven fails.
  • - File name not matching the public class name (LoginTest.java must contain public class LoginTest).
  • - Writing string or system.out with a lowercase letter — Java is case-sensitive.
  • - Downloading JAR files manually instead of letting Maven manage dependencies.
  • - Putting test classes in src/main/java, so Maven's test phase never finds them.

Try it yourself

Create a Maven project qa-java, add TestNG to pom.xml, and write a class EnvCheck with a main method that prints the Java version (System.getProperty("java.version")), the OS name, and a message saying whether the version is 17 or newer.

Write your answer on paper or in a sheet first, then compare.

Interview questions

How to answer like a confident QA engineer

4 questions
  1. Q1

    Explain public static void main(String[] args).

    Model answer

    public means the JVM can call it from outside the class. static means it runs without creating an object of the class. void means it returns nothing. main is the fixed name the JVM looks for as the entry point. String[] args holds command-line arguments, for example an environment name passed when running the program. In test frameworks like TestNG we usually don't write main ourselves; the runner calls our test methods.

  2. Q2

    What is the difference between JDK, JRE and JVM?

    Model answer

    The JVM executes bytecode and makes Java platform-independent. The JRE contains the JVM plus core libraries needed to run Java programs. The JDK contains the JRE plus development tools like the javac compiler. To write and compile automation code you need the JDK.

  3. Q3

    Why is Java called platform-independent?

    Model answer

    Source code is compiled to bytecode, not to machine code for one OS. Each OS has its own JVM that understands the same bytecode, so the same compiled tests run on Windows, Mac and Linux CI servers without changes.

  4. Q4

    What is Maven and why use it in test automation?

    Model answer

    Maven is a build and dependency management tool. pom.xml lists dependencies like Selenium, TestNG and RestAssured with versions, and Maven downloads them. It gives a standard folder structure and lifecycle, so mvn test runs the suite the same way locally and in CI, and plugins like Surefire control which TestNG suites or groups run.

Knowledge check

+5 points

What does the JVM actually run?

Student reviews

–

Loading…

– enrolled

  • 0%
  • 0%
  • 0%
  • 0%
  • 0%

Sign in and complete 20% of the course to leave a review.

Loading reviews…