CSE110 Principles of Programming with Java Lecture 03: Classes, methods, and variables Javier Gonzalez-Sanchez [email protected] javiergs.engineering.asu.edu | javiergs.com Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 24 Java Program Structure • A program is made up of one or more classes • A class contains one or more methods • A method contains program statements
Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 25 Java Program Structure • program statements can be: • Variables – places to store information • Instructions – actions to be done
Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 26 Previously… and static public class TheClassName { } public static void theFirstMethodName() { } public static void secondMethodName(){ } // instructions go here // instructions go here // variables go here // variables go here // variables go here public static void main( ) { } // instructions go here // variables go here
Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 28 main() method • All programs should have one and only one main() method. • Trying to execute a class without a main() method generates a compilation error
Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 31 Template public class TheClassName { } public static void theFirstMethodName() { } public static void secondMethodName(){ } // instructions go here // instructions go here // variables go here // variables go here // variables go here public static void main( ) { } // instructions go here // variables go here
CSE110 - Principles of Programming Javier Gonzalez-Sanchez [email protected] Summer 2022 Disclaimer. These slides can only be used as study material for the class CSE110 at ASU. They cannot be distributed or used for another purpose.