★ syntax

below is the basic setup of a java class (the main method/code).

https://lh7-rt.googleusercontent.com/docsz/AD_4nXeB-_TVoXISapGOR5ZFyjJAOcmT1t8x_5UlZkphSwn_iJBsCNIT5Tj0BLrlZZQNtd9GzCzgoYpTstwy9a2gCDG6etABJ5Bp526m809z07Atmm1bvY8bimeBDnWhI0Jgtr29SWaHHcLG8_iaUX2ssd733uI?key=HwOS_EcXozl-R-_TXHh4Hg

printing

System.out.print(" "); //no line break
System.out.println(" "); // with a line break

commenting

AP Exam Tip: Use comments in your FRQ to make it clear to the grader what you’re doing!

types of errors

helpful commands

★ variables & data types

variables

Primitive Types: int, double (decimals), char (’a’), boolean (true/false)

Object (aka Reference) Types: String (”hello”)

String concatenation operator ( + )

//Example of using it: 
System.out.println(”This is my name: “ + name);

Example of how to declare and initialize a String variable:

String name = "Josie";

Example of how to declare and initialize an int variable:

int shoeSize = 9;

Declaring a variable: int shoeSize; | String name;

Initializing a variable: shoeSize = 9; | name = “Josie”;

★ expressions & assignment statements

Assignment statements initialize or change the value stored in a variable using the assignment operator (=)

int score = 0;
int points = 5;
score = points*10;

Increment operator

x++;
/*This is equal to:
x = x + 1
x += 1
*/

Decrement Operator

x--;
/*This is equal to:
x = x - 1
x -= 1
*/

★ casting & ranges of values

Type casting is used to convert value from one type to another

double d = (double) 5/2; //2.5

★ compound assignment operators

Compound assignment operators are shortcuts that combine an operation with assignment. So, instead of writing x = x + 5, it is possible to write x +=5, which achieves the same thing.

Common Operators

| --- | --- | --- |

★ application program interfaces (API) and libraries

An API is a collection of prewritten classes and methods you can use instead of writing everything from scratch.

//Examples
Math.sqrt(25);
Math.random