Before we can start our simple/complicated Java programs, we need to set up the standard format for our code. Let's begin!
First we want to make a new class, the name does not matter for this lesson. A simple explanation for a class is that it is a blueprint for creating objects which are instances that have states an behaviors.
Next we want to import our Java library, which has all of our necessary functions and operations for basic Java programming. Simply start by typing in import java. util.*; which will import the library for all java functions.
import java.util.*;
(totally not necessary -Dexin noted)
NOTE: Sometimes a compiler for Java does not include the class layout. If yours does not, type: (Main should be your class name):
public class Main {
}
Then we want to make a method which is a function (like the one in math) that will manipulate the data that the program will receive. Type:
public class Main {
public static void main(String[] args) {
}
}
Up to this point your code should look like the following above. The public identifier means that this instance can be accessed by other classes.
Next we go to static, which means that the method/constant/etc. does not rely on the class and could be copied into another class.
The void keyword means that this method will not return any values after it is done executing.
Lastly in the parenthesis, String[] args means that you can pass in arguments that will be stored in a list/array(you'll learn more about arrays later).
Congratulations, you just set up the standard format for basic Java programming. Oh, if the vocab didn't make any sense to you, don't worry about it 'cause you will see them in action later as you go on. Now let's move on to saying "hello" and "world!"
-Luke Kim 3/27/2018
edited: Dexin 4/12/18