call System class methods to generate output to the console
recognize the difference between display behavior of System.out.print and System.out.println
create string literals
CSP VS. CSA
Before we get started, there are some major differences between the two AP Computer Science courses offered by the College Board and I want to make sure you are in the class that is right for you.
AP CSP
Difficulty: Beginner - Intermediate
Broad overview of Computer Science
Programming Language: Teacher Choice
Exam: 2 hours, multiple-choice only
1 Performance Task (Create PT)
30% for Create PT and 70% for exam
AP CSA
Difficulty: Intermediate - Advanced
Programming Focused
Programming Language: Java
Exam: 3 hours, multiple-choice and Free Response Questions (FRQs)
50% for multiple-choice and 50% for FRQs
INTRO TO JAVA
What do Android phones, Minecraft, and Netflix have in common?
They’re all programmed in Java!
Java is a programming language that is used worldwide to create software that we all use.
Every program in Java is written as a class.
Java is an object-oriented languageand we will learn more about classes and objects later.
When you ask the Java run-time to run a class, it will always start execution in the main method.
Usually, the class that contains the main method is named Main, but it isn't required (unless you are coding on Repl.it which forces it to be named Main).
The main method looks like this:
Every open curly brace { must have a close curly brace }!
These are used to start and end class and method definitions.
Ask most programmers what their first program was, and most likely it was a "Hello, World!" program.
I like to format my "Hello, World" like Brian Kernighan did in 1978.
If you are interested, check out the history of the "Hello, World!" program: https://en.wikipedia.org
The message, "hello, world" is called a string literal, and can have zero to many characters enclosed in double quotes "".
I use https://replit.com/ as my programming environment because it is cloud-based and will work on any device.
Because it is cloud-based, Repl.it is SLOWER than software-based IDEs like Eclipse, intelliJ, etc.
But Repl.it has advantages!
As long as you are connected to the Internet it works like a Google Doc, constantly saving changes to your work.
Repl.it also makes it very easy to share your programs with others!
If you choose to use a different integrated development environment (IDE) make sure to name the file the same name as the class with ".java" as the extension.
All programs must be defined inside a class in a source file, and the name of the class must match the file name.
Print commands are used to print output to the screen:
System.out.println(value); prints the value followed by a new line (ln)
System.out.print(value); prints the value without advancing to the next line
Did you notice that the output for the last few print statements is all "jammed together"?
In general, the programmer is responsible for adding spaces to get the proper output.
I could have put a space after the o in "Hello", or before the w in "world!".
Most command keywords must be lowercase, but class names like System are capitalized.
Commands MUST end with a semicolon ;.
Forgetting the semicolon is a computer science meme lol
Source code files (human-readable) are compiled or "translated" into .class files that the computer can understand.
For Repl.it, the source code file is sent over the Internet to a server which processes the file using javac, the Java programming language compiler, to generate the output before returning it to the console on your screen.
Be patient, this can take time...
Syntax errors are reported to you by the compiler if you do not write your code properly.
Common syntax errors include:
missing a semicolon ;
missing an open curly brace { or close curly brace }
missing an open quote " or close quote "
Syntax errors are also known as bugs, and the process of removing syntax errors is known as debugging.
IMPORTANT: Sometimes the error is actually on the line above where the compiler claims it is...
An early computer science pioneer Grace Hopper documented a real bug, a moth that flew into a computer in 1947!
Debugging is a normal part of coding.
It can be frustrating at times, but you will get better at it with practice!
Sometimes it just takes another pair of eyes, so ask me or a friend if you get stuck.
You can also try explaining your code line by line to someone or even a rubber duck.
In Java and many text-based coding languages, // is used to mark the beginning of a comment.
For multi-line comments, use /* to start the comment and */ to end the comment.
The compiler will skip over comments.
There are advantages to using comments, but in general they are notes to yourself and other programmers working with you.
I will often use single and multi-line comments like a "light switch" while debugging.
Commenting out certain lines of code can be very helpful in narrowing in on the error you are dealing with.
Here is an example of some good commenting:
In this class, you are encouraged to work together in pairs to complete programming challenges.
Pair programming is a successful software development technique in which two programmers work together at one computer.
One, the driver, types in code while the other, the navigator, gives idea and feedback.
The two coders switch roles frequently.
If you are working alone, I recommend explaining your code to a rubber duck...
SUMMARY
A basic Java program looks like the following:
public class MyClass
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
A Java program starts with public class NameOfClass { }. If you are using your own files for your code, each class should be in a separate file that matches the class name inside it, for example NameOfClass.java.
Most Java classes have a main method that will be run automatically. It looks like this: public static void main(String[] args { }).
The System.out.print( ) and System.out.println( ) methods display information given inside the parentheses on the computer monitor.
System.out.println( ) moves the cursor to a new line after the information has been displayed, while System.out.print( ) does not.
A string literal is enclosed in double quotes (" ").
Java command lines end in a semicolon ( ; ).
Curly braces { } are used to enclose blocks of code.
// and /* */ are used for comments.
A compiler translates Java code into a class file that can be run on your computer. Compiler or syntax errors are reported to you by the compiler if the Java code is not correctly written. Some things to check for are ; at the end of command lines, matching { }, ( ), and " ".
EVIDENCE
PART 1)
Complete the following Google Form. This form must be 100% correct and includes released AP practice questions. To stop working and return later, hit submit! You can "edit your response" and continue where you left off.
In PAIRS, use Pair Programming to create a program in which you use the skills from this lesson to introduce your partner to me. Make sure both people are introduced (in the same program)! It doesn't have to be a long introduction but if it is too short I will ask you to add more about yourselves. When you are ready, come visit me at my desk or ask me to stop by your table. There will be a debugging portion to this assignment which I will explain in person.
PART 3)
Use your College Board username and password tosign in to My AP or create an account using your MEVSD.NET email address.
This is the same login you use to access your AP scores, PSAT/NMSQT scores, or register for the SAT—or that you used to access My AP last year.
Click the Join a Course or Exam button, enter the join code below, and click Submit.
5TH BellVR2XJ7
Make sure the information that comes up is for the course you are taking. If it is, click Yes.
If this is your first time joining an AP class, you’ll need to provide some additional information.