OUR STRUCTURE OF JAVA PROGRAMS We will start with a simplified structure for Java programs initially and expand it as we go. 1. Simplest: one class, one method: For now any Java program that you write will be in this structure. That is, a Java program consists of only one class containing only one function (method). In that one function you will exercise your creativity. public class ____ { public static void main (String[] args) { ... } } Your creativity will be exercised in coming up with the name of the class that you will be creating and the body of the method called 'main'. The ____ part is where you put the class name, and the ... part is where the body of your main goes. Most of the time I will give you the name of the class that you will be creating, specially if you are creating a class in the context of a homework assignment. So, your creativity will be confined to the ... part of the program - at least for now. The other things that you see in the structure above are just decorations that you need to (blindly) copy for now until I explain what they all mean later. Yes, I will explain all of those when the right time comes. Example: the Hello program that we saw in Hello.java last time is in this structure as will other programs that we will study for a while. Note: A class named X should reside in a file named X.java, e.g., Hello class in Hello.java, at least for now. One exception to this structure at this point: When you use the Scanner class a little later, you will see that we use import java.util.Scanner at the top of the file. That will be the only exception to the structure that you should know about at this point. 2. One class, multiple methods/functions: It is time to expand our structure so that we can have multiple functions in a class. We expand our Java program structure by allowing multiple functions inside a single class in the following form: public class ____ { public static --- () { ... } ... public static void main (String[] args) { ... } // Any number of functions of this form, // one of which is named 'main'. } So, your creativity now is to come up with multiple methods. That involves exercising your creativity in the ____ part and the --- and ... parts of each method, as well as learning how to make those methods work together. REMEMBER: Your programs MUST be in the STRUCTURE that I give you. That is, your Java program cannot deviate from the above structure at this point, UNTIL I give you an updated structure! You cannot include a method definition inside another method definition because that is not allowed by the structure I give you here (and furthermore it is not legal in Java). You cannot use multiple classes to make up a Java program because MY STRUCTURE SO FAR DOES NOT ALLOW IT even though it is legal in Java. Later, I will expand our structure to include such things. Let's see how the complexity of our Java programs grows as we go according to my plan! One exception: You may include zero or more import statements at the top of a Java file as we saw in Read.java. 3. Will expand more later