May 15, 2025
File > New > Java ProjectNew > Classpublic static void main optionint a = 5; (int: integer type)char, long, doubleString name = "Susan";System.out.println();name.toUpperCase();public static void or return typespublic static void addExclamation(String s) {
System.out.println(s + "!");
}
Animal:
public class Animal {
public String IAmDog() {
return "I am a dog";
}
}
Animal a = new Animal();
String dogMessage = a.IAmDog();
if, else if, elsefor loop:
for (int i = 0; i < 5; i++) {
// code to repeat
}
while loop:
while (a < 50) {
// code to execute
a++;
}
try and catch to handle exceptions:
try {
// code that may throw an exception
} catch (Exception e) {
// handle exception
}