1/80
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Which can be used as INPUT devices ?
a. joystick
b. classroom projector
c. webcam
d. touchpad
d. touchpad
Which type of memory does not "preserve data any more when the power is off"
a. RAM
b. ROM
c. Neither
a. RAM
Sort the following items by price
- 16GB USB DRIVE
- 4GB RAM in a MacBook
- 16GB SD Card in a camera
- 1 GB RAM in a Desktop PC
- 4 gb ram
- 1 gb ram
- 16 gb usb drive
- 16 gb sd card
(true/ false) 1 GB is 1,000,000,000 bits
False, 1 GB has a billion BYTES, but 8,589,934,592 bits
what kind of code can a computer programmer typically understand?
source code
Eclipse is...
a. a java program
b. the sourse code of certain programs
c. an IDE
d. a Java compiler
c. An IDE
File name extension of a java COMPILED file:_____
.class
which variable naming is allowed?
a. 123abcde
b. usa.com
c. e_mc2
d. class
c.e_mc2
Which variable name reflects a good programming practice?
a. AppleCompany
b. googleInc
c. m
d. project
b. googleInc
which statement is written correctly
a. if(a==3); a = 5;
b. if(a ==3) a = 5;
c. if(a=3) a ==5;
d. if(a ==3) a==5;
b. if(a ==3) a = 5;
How to write a condition : a is less than 10 and is greater or equal to 0?
if (a< 10 && a >= 0)
the double equals sign (==) works well if two ___ have the same value
integers (int data type)
(true/ false) you can write nothing in the area of update functions on the for loop. (i.e for(something; something; nothing)
true
What is the correct way to create a class instance?
ClassName instance = new ClassName();
A local variable is set as "private" type in one class so that...
such a variable cannot be accessed by any class outside
Which of the following statements is true about "void"?
a method with "void" can optionally have no statement of "return"
What is the correct way of writing a mutator[set] method?
public void set(int num) {number =num; }
What is the correct way of writing a accessor {get} method?
public int get() {return num;}
What statement is true about java constructor?
a constructor must not have a return type
(True/false) If the programmer does not write any constructor in a class, a default constructor will be created by the java program when a class object is created.
True
(True/false) The constructors name must be the same as the classes first objects name?
False
consider a variable defined as " static final double myData = 0.0;" in a class. What does it mean?
The variable myData is a class- level variable and cannot be changed
Which code is NOT a correct way of method overloading
a. public void action(double a)
public void action (double[] a)
b. public boolean action(boolean b)
public boolean action(boolean b1, boolean b2)
c. public int action(String s)
public long action(String s)
d. public double action(int a, char c)
public double action (char c, int a)
c. public int action(String s)
public long action(String s)
To create a 2D array, which line of statement works without causing a compiling error?
int [][] arr1 = new int[0][0];
When we process the inner for loop to iterate 2D array elements, what is "array[i].length" ?
the number of columns in the 2D array
For a 2D array defined as int[4][5], how many elements are there in this array?
20
What does the element of array[4][5] read?
row 5, column 6
(true/false) A class method may return an empty array.
true
Creating an array with 7 variables of type double
double[] temperature = new double [7];
Array Indices begin at?
zero
To access an element in an array use:
the name of the array, and an index number enclosed in braces
the number of elements in an array is the?
length
the type of the array elements is the?
arrays base type
Are square brackets used with arrays with a data type when declaring an array?
yes,
int [] pressure;
Are square brackets are used with arrays to enclose an integer expression to declare the length of the array ?
yes,
pressure = new int [100];
Are square brackets used with arrays to name an indexed value of the array?
yes,
pressure[3] = keyboard.nextInt();
an array has only one public instance variable, called what?
-variable length, which contains number of elements in the array, and cannot be changed
what is the index of the first array element?
zero
what is the last valid index of an array?
arrayName.length-1;
Is it okay to "waste" element 0?
yes, program is easier to manage and understand
when initializing arrays is it possible to initialize at declaration time?
Yes,
double[] reading = {3.3, 15.8, 9.7};
when initializing arrays you may use normal assignment statements...
int [] count = new int[100];
for(int i = 0; i < 100; i++)
count[i] = 0;
each java class definition is usually in a file by itself
- file begins with name of the class
- ends with .java
Does the use of public, have no restrictions on how variables are used
yes
There are two kinds of java methods
1. return a single item
2. perform some other action - a void method
is the main method a void method?
yes! its invoked by the system, and not by the application program
When defining a void method..
think of method as defining an action to be taken
EX: setters, main methods
When referring to instance variables outside the class -- must use...
name of an object of the class, followed by a dot, then name of instance variable
the keyword
~ this ~ stands for?
the receiving object
what are variables declared inside a method?
local variables
Type specified as public
any other class can directly access that object by name
Whats the only way objects of a class can be altered outside of a class?
By using the set method
When instance variables are private must provide methods to...
-access values with: getters (accessors)
-change the values:
setters (mutator)
what contains more than interface, less than full implementation AND written before class is defined?
UML Class Diagrams
(true/ false) all variables are not implemented as a memory location
FALSE, all variables are implemented as a memory location
Data of primitive type stored in the memory location is assigned where?
the variable
variable of class type contains what?
memory address of object named by the variable
(True/ False) A reference type variable holds references (memory addresses)
True
Can you use == to compare two objects?
NO, must use equals method ( .equals() )
whats is a special method called when an instance of an object is created? (it creates, initializes, object of a class)
A constructor
Can a constructor have parameters?
Yes, to specify initial values if desired
What is a constructor without parameters called?
a default constructor
(true/false) If you do define a constructor, Java will NOT automatically define a default constructor
True
What are static variables?
static variables are shared by all objects of a class; shared across all instances of a class
(true/false) variables declared static final are considered constants?
true, the value cannot be changed
(true/false) both static variables and instance variables are sometimes called fields or data members
true
RANDOM NUMBERS: the following simulates rolling a six sided die
int die = (int) (6.0 * Math.random() ) + 1;
(true/false) You can overload a method where the only difference is the type of value returned
FALSE, you must not overload a method with different types
what is a collection of classes grouped together into a folder?
a package
what tells complier path name for directory containing classes of package?
the package name
(true/false) a primitive type has a wrapper class to allow treatment as an object?
true
what class can have instance variables, constructors, methods?
an enumeration class
ternary operator syntax
(condition) ? expression1 : expression2;
what does selection sort do?
It orders an array into ascending or descending order
Algorithm: how to swap to numbers in array
int[]array = {4, 2, 1, 5, 3};
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
System.out.print("\n\n");
int temp;
for (int ind = 0; ind < array.length; ind++){
int minNum = ind;
for(int x = ind + 1; x < array.length; x++){
if(array[x] < array[minNum])
minNum = x;
}
if (minNum != ind) {
temp = array[ind];
array[ind] = array[minNum];
array[minNum] = temp;
System.out.print("\n");
}
for(int i = 0; i < array.length; i ++)
System.out.print(array[i] + " ");
System.out.print("\n\n");
}
}
can you pass an entire array to a method?
Yes, You can pass an entire array to a method. The method can change the values of an array of primitive values or the states of objects in the array.
in order to run a Java program in a terminal, what command lines do you need to input?
first type _ javac _ to compile, and then type _java_ to execute.
does binary search work better when the array is sorted?
yes, if array is unsorted, the best way to search an element is linear search
what is the index of the first item in the first row and second column
array[0][1]
what is the index of the first item in the first row and first column
array[0][0]
What is method overloading?
When you have two methods in the same class that have the same name but different parameters.