CS: Java: Classes, Methods, and Public Static Void Main
Understanding Java program structure, methods, and the main method
Understanding Java program structure, methods, and the main method
CS - Grade 9-12
- 1
In your own words, explain what a class is in Java. Then explain why the file name often matches the public class name.
- 2
Look at this Java code: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, Java!"); } } Identify the class name, the method name, and the statement that prints text.
- 3
Write the standard header for the Java main method exactly as it is usually written.
- 4
Explain what the word public means in public static void main(String[] args).
- 5
Explain what the word static means in public static void main(String[] args).
- 6
Explain what the word void means in public static void main(String[] args).
- 7
What does String[] args represent in the main method header? Give a simple example of when it might be used.
- 8
Complete this Java program so it prints your name on one line and your favorite subject on the next line: public class AboutMe { public static void main(String[] args) { } }
- 9
The following code has errors: public class Test public static void main(String[] args) { System.out.println("Hi"); } } Rewrite it with the braces in the correct places.
- 10
Write a Java class named CalculatorDemo with a main method. Inside main, print the result of 8 + 5 using System.out.println.
- 11
Create a method named greet that prints "Welcome!". Then call greet from the main method. Write the full Java class named GreetingProgram.
- 12
Trace the order of execution in this program: public class OrderDemo { public static void main(String[] args) { System.out.println("A"); showLetter(); System.out.println("C"); } public static void showLetter() { System.out.println("B"); } } What is printed, and why?
More CS Worksheets
CS: Algorithms and Flowcharts
Grade 6-8 · 12 problems
CS: Arrays and Lists
Grade 9-12 · 12 problems
CS: Big-O Notation and Algorithm Efficiency
Grade 9-12 · 12 problems
CS: Binary Numbers and Number Systems
Grade 6-8 · 12 problems
More Grade 9-12 Worksheets
Linear Equations
Math · 8 problems
Cell Biology
Biology · 8 problems
Reading Comprehension
Language Arts · 8 problems
Historical Thinking & Evidence
Social Studies · 8 problems