Methods and variables
Classes, objects, and primitives
To be or not to be
Decisions decisions
What it do?
100

Java keyword used to indicate that the value of the variable cannot be changed once it is initially assigned

What is "final"?

100

List at least 4 different data types

 String, boolean, int, double, char

100

both conditions must be true for the resulting expression to evaluate to true

What is AND?

100

used to evaluate the relationship between two conditions to either true or false

What are relational operators (eg., ==, !=, >, <, <=, >=)? 

100

Consider the following code segment.

System.out.println(Math.abs(11%4*2)/2);

3

200

The value of x when

int x = 21/5;

4

200

What special method is required in order to compile code? (I will give double points if you know it from memory)

The main method

public static void main(String [] args)

200

if one condition is true, then the resulting expression evaluates to true


What is OR?

200

what would you use to have mutually exclusive conditional statements?

else if statements

200

The value of y when

double y = (double)(33/5);

6.0

300

Any text that is enclosed in double quotes.

What is a string literal?

300

What is the process called whenever you want to change one data type to another?

casting

300

What is the difference between = and ==?

= assigns a value to a variable while == compares values of two variables

300

statements in a program that interrupt the sequential execution of statements

What are conditional or selection statements?

300

The possible values of a when

int a = (int)(Math.random()) * 4 + 6;

6,7,8,9

400

what does void mean when written in a method header?

It means you return nothing.

400

Give an example of the valid way to create an Athlete object  in a different class given the following Athlete class definition: 

public class Athlete {

  private String first_name;

  private String last_name;

  private int jersey;

   public Athlete(String first_name, String last_name, int jersey) {

    this.first_name = first_name;

    this.last_name = last_name;

    this.jersey = jersey;

  } 

}

Athlete athlete1 = new Athlete("Lebron", "James", 23);

400

evaluates to the opposite of the expression, denoted with a !


What is NOT?

400

The value of result after the following command:

String a = "abcdefgh";

String b = "hgfedcba";

String result = a.substring(2) + b.substring(5);

cdefghcba

400

rearrange("orange") when...

public static String rearrange(String str) {
   String temp = "";
   for (int i = str.length() - 1; i > 0; i--) {
      temp += str.substring(i - 1, i);
   }
   return temp;
}

What is "gnaro"?

500

Describe in detail what the return statement does in a method


In Java, every method is declared with a return type such as int, float, double, string, etc.

These return types required a return statement at the end of the method. A return keyword is used for returning the resulted value.

The void return type doesn't require any return statement. If we try to return a value from a void method, the compiler shows an error.

500

the automatic conversion the Java compiler makes from the wrapper class to the primitive type, Integer to int, Double to double

What is unboxing?

500

Consider the following code:

String str = "Computer";

How would you correctly extract the last letter of this string?


System.out.println(str.substring(7));

500

The logic error in the code below:

// Children 3 and under are free
// Ages 4 to under 18: $10 per ticket
// Senior citizen 65 +: $10 per ticket
// All others: $20 per ticket

int price = 0;
if ( age < 18 )
    price = 10
else
   if ( age >= 65 )
     price = 10
   else
     price = 20

What is...

ages 3 and under will not be free

if ( age >= 4 && age < 18 )
    price = 10

500

abMethod("mississippi", "ss") when

public static String abMethod(String a, String b) {
   int x = a.indexOf(b);
   while (x >= 0) {
      a = a.substring(0, x) + a.substring(x + b.length());
      x = a.indexOf(b);
   }
   return a;
}

What is "miiippi"?