Syntax/grammer Flashcards
The way byte code understands code
Assignment Statement
::===
ex balance= nuBalance
Message Statement
.([actual parameter]);
ex. myaccount.setBalance(1234)
Return statement
::== return[];
ex. return balance;
What does () mean? ex. account();
“This”
ex This account.
What is a class?
Template of an object (cookie cutter, press)
contains methods and variables.
What is a variable?
Variable contains information
What is a Method?
Perform actions, Allows classes to do things.
primitives in Java:
byte (number, 1 byte) short (number, 2 bytes) int (number, 4 bytes) long (number, 8 bytes) float (float number, 4 bytes) double (float number, 8 bytes) char (a character, 2 bytes) boolean (true or false, 1 byte)
To declare and assign a number
int myNumber;
myNumber = 5;
or
int myNumber = 5;
To define a floating point number,
float f = (float) 4.5;
syntax for chars
char c = ‘g’;
ways to use a string
// Create a string with a constructor String s1 = new String("Who let the dogs out?"); // Just using "" creates a string, so no need to write it the previous way. String s2 = "Who who who who!"; // Java defined the operator + on strings String s3 = s1 + s2;
Boolean
boolean b = false;
b = true;
boolean toBe = false; b = toBe || !toBe; if (b) { System.out.println(toBe); }
int children = 0; b = children; // Will not work if (children) { // Will not work // Will not work }
The Arithmetic Operators (5)
\+ additive operator (also used for String concatenation) - subtraction operator * multiplication operator / division operator % remainder operator
The Unary Operators(5)
\+ Unary plus operator; indicates positive value (numbers are positive without this, however) - Unary minus operator; negates an expression \++ Increment operator; increments a value by 1 -- Decrement operator; decrements a value by 1 ! Logical complement operator; inverts the value of a boolean
The Equality and Relational Operators(6)
== equal to != not equal to > greater than >= greater than or equal to < less than <= less than or equal to
The Conditional Operators(2)
&& Conditional-AND
|| Conditional-OR
instanceof <—-what does it do?
The instanceof operator compares an object to a specified type