Java objects are created using the new keyword and class name. Variables are declared with a type and name, and assigned values. Classes contain methods that can be called on objects. Methods are declared with a visibility, return type, name and parameters. Arrays store multiple values of the same type and can be accessed by index. If/else blocks allow for conditional execution based on boolean expressions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2K views
061 Java Cheat Sheet
Java objects are created using the new keyword and class name. Variables are declared with a type and name, and assigned values. Classes contain methods that can be called on objects. Methods are declared with a visibility, return type, name and parameters. Arrays store multiple values of the same type and can be accessed by index. If/else blocks allow for conditional execution based on boolean expressions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
Java Cheat Sheet
Objects Variables Types
Create an object: Declare a variable: int 1, -25, 0 Type VarName = new ClassName(params); Visibility Type VariableName; float 1.6f, 6.89f Car myFerrari = new Car(300); private int theAnswer; double 3.1415925 Car myFiat = new Car(120); private Button trueButton; boolean true, false Call an object's method: Assign a value to a variable: String "Philipp" myFerrari.drive(); theAnswer = 42;
Classes Methods Arrays
public class Car { Declare a method: Declare an array: private int speedField; Visibility ReturnType Name (inputs) {...} int[ ] myInts; // The Constructor: public void myMethod () { Set the array size: public Car (int speedInput) { // "void" does not return anything } myInts = new int[5]; speedField = speedInput; public int methodWithParam (int a, int b) { Assign values by index: } return a + b; } // Car class methods } myInts[0] = 5; myInts[1] = 74; If-Else Blocks Logic Retrieve an element: if (condition 1) { Symbol Meaning Example 1stElement = myInts[0]; // do x if condition 1 is true == EQUAL TO x == 4 2ndElement = myInts[1]; } else if (condition 2) { != NOT EQUAL TO x != 3 3rdElement = myInts[2]; // do y if condition 2 is true && AND x > 0 && x < 5 } else { || OR x < 0 || x > 10 // default case }