The crew gathers around the bench to celebrate. FieldSim has samples, a rover, a grid, searches, sorts and recursion.
Comet spins her pencil. "What can we make next? Could FieldSim be written in another language?"
Wren crosses his arms. "What does the evidence say? We should check that a new language really says the same thing before we trust it."
Nova glides between them and splits her projection in two. Python glows on the left, and a new language glows on the right. "How can I help?" she asks. "This is Java. I compiled and ran it already. Read it beside the Python you know."
Comet squints at all the braces. "Lead programmer, can you spot what matches?"
AP Computer Science A is a course that uses Java and centers on object-oriented programming. This course prepares for the ideas in it.
You already know those ideas in Python: classes, objects, lists, grids, searching, sorting and recursion. These two weeks show the same ideas in Java.
You will read and trace Java only. You do not need to install anything new.
# ready.py rover = "Pip" print(rover + " is ready")
// Ready.java
// The same two lines as ready.py, written in Java.
public class Ready {
public static void main(String[] args) {
String rover = "Pip";
System.out.println(rover + " is ready");
}
} Both programs print the same line when run:
Pip is ready
# steps.py
for i in range(3):
print("step " + str(i)) // Steps.java
public class Steps {
public static void main(String[] args) {
for (int i = 0; i < 3; i++) {
System.out.println("step " + i);
}
}
} step 0 step 1 step 2
# steps.py (indent removed)
for i in range(3):
print("step " + str(i)) File "steps.py", line 3
print("step " + str(i))
^^^^^
IndentationError: expected an indented block after 'for' statement on line 2 | Statement | True or false? |
|---|---|
| Java source code goes in files ending in .java. | ? |
| The Java compiler reads comments and runs them. | ? |
| Every Java application has a main method. | ? |
| Python groups a loop body with indentation. | ? |
You just read your first Java program, lead programmer. Tomorrow you will meet Java's types and statements.