0% found this document useful (0 votes)
276 views

5.1 Java Cheat Sheet and Map PDF

This document provides an overview of common programming concepts including objects, variables, classes, methods, conditionals, and arrays. It defines: - How to create objects from classes and call methods on objects - How to declare and assign values to variables of built-in types like int, float, double, boolean, and String - The basic structure of a class including fields, constructors, and methods - How to declare methods with different visibilities, return types, and parameters - The syntax of if/else conditional blocks - How to declare and access elements in an array

Uploaded by

HarouneDeGamal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
276 views

5.1 Java Cheat Sheet and Map PDF

This document provides an overview of common programming concepts including objects, variables, classes, methods, conditionals, and arrays. It defines: - How to create objects from classes and call methods on objects - How to declare and assign values to variables of built-in types like int, float, double, boolean, and String - The basic structure of a class including fields, constructors, and methods - How to declare methods with different visibilities, return types, and parameters - The syntax of if/else conditional blocks - How to declare and access elements in an array

Uploaded by

HarouneDeGamal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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
}

You might also like