Compiler Errors
Definition
Code Snippets
Coding Exercise
100

'(' or '[' expected

You missing a pair of parentheses or didn't close a pair somewhere

100

!

Logical 'not' operator, and a way to negate a clause

100

!true

!false

!!true

!!!true

// false

// true

// true

// false

100

Create a boolean variable with the value of not false.

boolean a = true;

200

cannot return a value from method whose result type is void

Your code is returning a value when its return type in the method header is void (which isn't supposed to return anything)

200

autoboxing

The name for the Java compiler's automatic conversion between primitive data types and their corresponding Wrapper classes.

200

Math.abs(-16);

Math.abs(98.8);

// returns 16

// returns 98.8

200

Find the minimum value of these 2 values: -2, 2

Math.min(-2, 2);

300

bad operand types for binary operator '/'

You're trying to divide by something that's not a number.

300

alist.add("Add me");

An ArrayList named alist is calling a method called "add", which is a built-in method of ArrayLists that adds an item at the end of the list. The method adds the String literal "Add me".

300

ArrayList ourList = new ArrayList();

ourList.isEmpty(); 

ourList.add("Hello");

ourList.isEmpty();  

ourList.clear();

ourList.isEmpty(); 

// Line 2: returns true

// Line 4: returns false

// Line 6: returns true

300

Create 2 String variables s1, s2 with the String literal "hello!" using 2 different syntaxes. Create a third variable s3 that stores the reference to str2.

String s1 = "hello!";

String s2 = new String("hello!");

String s3 = s2;

400

reached end of file while parsing

Missing a closing curly brace to finish your program

400

Variable scope

The way you talk about which variables different parts of a program can "see". Loops, conditionals, methods, and classes each have their own scope.

400

String str = "Hello world!";

str.indexOf("World"); 

str.indexOf("world");

str.indexOf("hi");

str.indexOf("Hello world!");


// -1

// 6

// -1

// 0

400

Create an array that stores the numbers from 1 to 10. Then create an ArrayList that stores those numbers backwards. Do all of this within 1 loop.

int[] arr = new int[10];

ArrayList<Integer> list = new ArrayList<Integer>();

for (int i = 1; i <= 10; i++) {

   arr[i] = i;

   list.add(0, i);

}

500

<identifier> expected

You have not defined a method around your code. (Fields are ok)

500

StringIndexOutOfBoundsException

An exception (error) that happens when Java tries to access an index that doesn't exist in a String. Often this happens when the index is negative or greater than the string's length.

500

What is happening in main?

class Book {

    String title;

    String author;


    Book(String titleFromuser, authorFromuser){

        this.title = titleFromuser;

        this.author = authorFromuser;

    }


    public static void main(String[] args){

        Book b = new Book("Alice in Wonderland", "Lewis Carroll");

    }

}

A new variable called "b", which can only store Book objects, stores a new Book object that initializes the field "title" to the String literal "Alice in Wonderland" and initializes the field "author" to the String literal "Lewis Carroll"

500

Write an instance method called celsiusToFahrenheit that converts a temperature, stored as an int in degrees fahrenheit, to celsius and returns it. The formula is (°F − 32) × 5/9. Write an overloaded method that converts the temperature (in degrees fahrenheit) stored as a double.

public int celsiusToFahrenheit(int degreesF){

    return (degreesF - 32) * (5 / 9);

}

public double celsiusToFahrenheit(double degreesF){

    return (degreesF - 32) * (5 / 9);

}

M
e
n
u