Download presentation
Presentation is loading. Please wait.
Published byArron McCarthy Modified over 9 years ago
1
Hello AP Computer Science!
2
What are some of the things that you have used computers for?
3
Break Down Hello World Go over Variables Go over Standard Input Go over Standard Output Objectives Students will be able to write a program that prompts the user for a set of variables and feedback information related to those variables
4
Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening. class HelloWorld { public static void main(String [] arg) { //This will print our message to the world System.out.println("Hello World!"); }
5
class -> indicates that you are starting a class HelloWorld -> the name of the class JAVA is what is known a an object oriented language. Because of that, ALL code is in some way attached to or as some would say encapsulated inside of a class. The main reason for this is organization although there are other benefits as well. There are other lower level programming languages that are procedural and ultimately all code behaves in a procedural manner on the CPU. You can think of this as filing papers in filing cabinets versus leaving them in a huge stack in the middle of the room.
6
All code for both a class as well as a methods, loops, and if statements is demarcated with an open and close curly. Programmer Tip – Be careful about the placement of a curly. Sometimes you will find that you will have multiple things nested inside of others and it becomes hard to tell when one thing starts and another ends. INDENTING helps with this!!!!!!
7
Within each class are variables, which we will get to later, and methods. Inside methods we put our lines of code that actually run. The reason that we call these things methods is that they define how our classes do certain things. Our method declaration is as follows: public static void main(String [] arg)
8
public – indicates that this method is public which means that can be called from outside the class static – indicates that this method is static which means we do not have to create an instance of the class before we can call the method main – the name of the method (String [] arg) – indicates the input variable(s), in this instance it is an array of Strings called arg. String variables can hold text and the brackets ([]) indicate that it is an array which can hold multiple values
9
System.out.println – in this part of our code we are calling the println method of the out class which is contained inside the System class. Where this will print out to is dependent on the computer that we are running it on. (“HelloWorld”) – The open and close parenthesis contain whatever we are passing into our method ; - after every variable declaration and line of regular code, we have to include a semi colon
10
Didn’t we miss something? What about that whole line of code that went: //This will print our message to the world Well that doesn’t do anything, for the computer anyway. That is a comment. For the programmer it could do a lot. It lets you know what a class, method, code, or variable does without interfering with the working of code. Sometimes it even helps to write all your comments before you type a single line of code! You can put comments into your code by putting a double slash. Or to put in comments with carriage returns you can use a slash star combo like so: /*This will print our message to the world*/
11
Recital Time!
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.