• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/23

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

23 Cards in this Set

  • Front
  • Back

What are the indexes for the first and last positions of an array called x?

x[0] and x[x.length-1]

Immediately after instantiating a new array of primitives(ints, doubles, etc.) what fills the array? What about an array of objects

Primitive Type: the default value of the primitive fills the array (0 for int, 0.0 for double, false for boolean)


Objects: null fills the array

What happens when you try to access an array element past the end of an array?

An exception of type ArrayIndexOutOfBoundsException is thrown

Instantiate three arrays called x, y and z of types int String and BankAccount, respectively, all of size 10.

int [] x = new int[10];


String[] y = new String[10];


BankAccount[] z = new BankAccount[10];

Method Overloading

two methods in the same class such that they have the same name but different signatures


EX: int calc(double n1, int n2)


int calc(int n1, int n2)

Use the following full array, x: {4,8,5,1,6,3,2}




a. What is the value given by x[1]?


b. What is the value given by x[6]?


c. What is the value given by x[7]?


d. What is the value given by x.length?

a. 8


b. 2


c. ArryaIndexOutOfBoundsException


d. 7



Write a for-loop to double each element in the array x given in question 6 above.

for (int i=0; i < x.length; i++){


x[i] *= 2;


}

What is a static variable?


What is a static method?

A static variable belongs to the class, as well as a static method - they are not bound to instances. For example, if I instantiate 100 instances of a class A that has a static variable num, then there is only one num in existance, since it is bound to the class A, and not each individual instance of A

public class AmazingClass {


private static int number;


public AmazingClass(int a){


number = a;


}


public int twice(){


number *= 2;


return number;


}


}




What is the of number after the following statements?


a. AmazingClass ac1 = new AmazingClass (3);


b. AmazingClass ac1 = new AmazingClass(7);


c. ac1.twice();


d. ac2.twice();




How many copies of the variable number exist after 374 different AmazingClass objects are instantiated?

a. 3


b. 7


c. 14


d. 28




There is only one copy due to it being static

What is the meaning of public?

refers to a visibility modifier in which anyone can see this item

What is the meaning of static?

the item is bound to the class in which it is, and not to the instance (there is only one copy of this item in existance)

What is the meaning of final?

once a value is assigned to a final variable it always contains the same value and can not be changed

What is the meaning of void?

"nothing" for methods it means the method does not return anything

What is the meaning of main?

the main method (entry point of the program)



What is the meaning of String[] args?

a String array that is all of the arguments that are passed to the main method from the command line

Circle the valid method headings assuming they are written inside a class named SomeClass




a. public void Void()


b. public String string (int n)


c. public double void f2 ()


d. public BankAccount bankAccount ()


e. public double sum (int left, right)

a. valid


b. valid


c. invalid because there are two return types


d. valid


e. invalid because the 2nd parameter does not have a type

In order to swap the values of two integers ( A and B), we do not need extra integer

False, you need a third integer to swap the values of A and B

Write a two line code to initialize a 2D array of integers called A with the following values. Afterward what is the value of A[1][2] and A[0][3]




1234


5678

int [] [] A = {{1,2,3,4},{5,6,7,8}};


A[1][2] = 7 A[0][3] = 4

If we have <String S = "equanimity">, what is the output of <S.substring(1,5)> and <S.substring(0,3)>?




a. "quani" and "equa"


b. "quani" and "equ"


c. "quan" and "equa"


d. "quan" and "equ"

D beginIndex is inclusive and endIndex is exclusive

What is the difference between between primitive types and objects in Java? Give an example of each of them

Primitive types are predefined by the language and is named by a reserved keyword.The eight primitive data types supported by the java programming language are byte, short, int, long, float, double, boolean, char.




Objects are entities that have state and behavior. Usually state is maintained with variables and behavior is maintainedby methods inside the object. Example of objects are arrays and classes.

What does a compiler do?

Translates programs written in a high level language into machine code

What would you save this program as?




public class VendingMachine{


public static void main(String[] args){


System.out.println("Please insert 25c");


}


}

VendingMachince.java

What is the output of the following program?




public class MethodExample{


public static void main(String[] args){


int y = 2, z = 1;


z = y * 2;


System.out.print(y + z);


}


}

It will print 6 because y is 2 and 2*2 will be stored in z and now z = 4 and y is the same value; 2. Therefore 4 + 2 = 6