4 Flashcards
switch (var) { case 1://if var = 1 //What happens break; case 2 \://if var = 2 //What happens break; default://Otherwise //What happens break; }
How do you make a Switch statement?
for (int i; i < 10; i++) { //Program }
How do you make loops?
In java, we have primitive types & objects.
Primitive types hold the actual value in memory.
Object hold references in memory.
What is a primitive type in Java?
- Is a - inheritance
- Has a - composition / aggregation
V47
Describe 2 classes can have.
BSILF DB CS
byte short int long float
double
boolean
char
String
Name 9 primitive types
- Almost all inheritance can be rewritten
- Less about modeling the real world and more about modeling interactions in a system and roles and responsibilities
- Inheritance is difficult to maintain
V52
Name 3 reasons why favor composition over inheritance
x = x + 3;
What is this “x+=3” the equivalent of?
= \+= -= *= /= %= ----------------- v20
What are 6 assignment operators?
- Treated like a primitive type (can be assigned w/o the New keyword) but it’s an object
- They’re immutable (can’t be changed). If you give a string a different value, it create an new string in memory.
Java Fundamentals - v22
Name to things about strings in Java.
System.out.println(firstName.indexOf(‘e’));
v23
Given: String firstName = “reynald”;
Writhe the line of code to out the index of letter ‘a’
int[] numbers = new int[3];
- Create an Array called ‘number’ w/ 3 slots
2. Write out the 2nd number
Calls the default constructor on the Printer class.
What does the ‘new’ key word do here when creating an instance?
Printer myPrinter = new Printer();
- String[] colors = new String[] {“red”,”blue”, “Green”};
- for (String c : colors){
System.out.println(c);
}
v42
Create an array called ‘colors’ and add to it :”red”,”blue”, “Green”
- Create a foreach loop the writes out the contents of the arra
int ten = 10; while(copies > ten) { System.out.println("Reynald"); copies --; }
- Define a variable that = to ten.
2. Create a while loop that prints you name tens time.
public void printColors()
{
String[] colors = new String[] {“red”,”blue”, “green”,”yellow”};
for (String c : colors) { if("green".equals(c)) continue; System.out.println(c); } }
Given this method below, implements ‘continue’ or ‘break’ statement if color is ‘green’
public void printColors()
{
String[] colors = new String[] {“red”,”blue”, “green”,”yellow”};
for (String c : colors) { System.out.println(c); } }