AdevRaou
This course aims to provide an overview of the programming language. It contains the main structures explained, along with examples and exercises to test comprehension. Originally made for the Grade 9 students of Hsinchu International School, in Taiwan. Every Java file ends in .java, and it should contain a class inside with the same name.
If you want your Java file to do something, then you should place a main method inside that class.
The braces { } indicate the scope of the structure involved, like a class or the main method.
Place the lines you want your code to execute inside the main method.
The file you are seeing shows you the appropriate syntax of a simple Java program.
//The class, as well as the file, is called ClassesInJava. public class ClassesInJava { //The main method; put it as-is in all your codes for now. public static void main(String[] args) { //This is a comment, ignored by Java. //Place statements here. } }Sample
Syntaxis {style="note"}
here {style= "note"}
Inside the main method you can place two types of print statements.
Command Effect
- System.out.print() Prints a message in the console.
- System.out.println() Prints a message in the console, then ends the line. After every command, like those, you must place a semicolon ; at the end of the line.
You can use the shortcut sout to type quickly the println command.
To duplicate a line, you can use the shortcut Ctrl+D.
There are many ways of running a Java code:
You can click on the green triangle at the left of the class or the main method. You can right-click on the .java file and click on Run. You can click on the Run tab on the toolbar, and select Run. You can use the shortcut Mayús+F10
It is good practice to list the prerequisites that are required or recommended.
Make sure that:
- First prerequisite
- Second prerequisite
Some introductory information.
-
Step with a code block
run this --that
-
Step with a link
-
Step with a list.
- List item
- List item
- List item