CSCI 1301 Final

0.0(0)
studied byStudied by 1 person
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/80

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 10:25 PM on 12/4/24
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

81 Terms

1
New cards

Which can be used as INPUT devices ?
a. joystick
b. classroom projector
c. webcam
d. touchpad

d. touchpad

2
New cards

Which type of memory does not "preserve data any more when the power is off"
a. RAM
b. ROM
c. Neither

a. RAM

3
New cards

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

4
New cards

(true/ false) 1 GB is 1,000,000,000 bits

False, 1 GB has a billion BYTES, but 8,589,934,592 bits

5
New cards

what kind of code can a computer programmer typically understand?

source code

6
New cards

Eclipse is...
a. a java program
b. the sourse code of certain programs
c. an IDE
d. a Java compiler

c. An IDE

7
New cards

File name extension of a java COMPILED file:_____

.class

8
New cards

which variable naming is allowed?
a. 123abcde
b. usa.com
c. e_mc2
d. class

c.e_mc2

9
New cards

Which variable name reflects a good programming practice?
a. AppleCompany
b. googleInc
c. m
d. project

b. googleInc

10
New cards

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;

11
New cards

How to write a condition : a is less than 10 and is greater or equal to 0?

if (a< 10 && a >= 0)

12
New cards

the double equals sign (==) works well if two ___ have the same value

integers (int data type)

13
New cards

(true/ false) you can write nothing in the area of update functions on the for loop. (i.e for(something; something; nothing)

true

14
New cards

What is the correct way to create a class instance?

ClassName instance = new ClassName();

15
New cards

A local variable is set as "private" type in one class so that...

such a variable cannot be accessed by any class outside

16
New cards

Which of the following statements is true about "void"?

a method with "void" can optionally have no statement of "return"

17
New cards

What is the correct way of writing a mutator[set] method?

public void set(int num) {number =num; }

18
New cards

What is the correct way of writing a accessor {get} method?

public int get() {return num;}

19
New cards

What statement is true about java constructor?

a constructor must not have a return type

20
New cards

(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

21
New cards

(True/false) The constructors name must be the same as the classes first objects name?

False

22
New cards

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

23
New cards

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)

24
New cards

To create a 2D array, which line of statement works without causing a compiling error?

int [][] arr1 = new int[0][0];

25
New cards

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

26
New cards

For a 2D array defined as int[4][5], how many elements are there in this array?

20

27
New cards

What does the element of array[4][5] read?

row 5, column 6

28
New cards

(true/false) A class method may return an empty array.

true

29
New cards

Creating an array with 7 variables of type double

double[] temperature = new double [7];

30
New cards

Array Indices begin at?

zero

31
New cards

To access an element in an array use:

the name of the array, and an index number enclosed in braces

32
New cards

the number of elements in an array is the?

length

33
New cards

the type of the array elements is the?

arrays base type

34
New cards

Are square brackets used with arrays with a data type when declaring an array?

yes,
int [] pressure;

35
New cards

Are square brackets are used with arrays to enclose an integer expression to declare the length of the array ?

yes,
pressure = new int [100];

36
New cards

Are square brackets used with arrays to name an indexed value of the array?

yes,
pressure[3] = keyboard.nextInt();

37
New cards

an array has only one public instance variable, called what?

-variable length, which contains number of elements in the array, and cannot be changed

38
New cards

what is the index of the first array element?

zero

39
New cards

what is the last valid index of an array?

arrayName.length-1;

40
New cards

Is it okay to "waste" element 0?

yes, program is easier to manage and understand

41
New cards

when initializing arrays is it possible to initialize at declaration time?

Yes,
double[] reading = {3.3, 15.8, 9.7};

42
New cards

when initializing arrays you may use normal assignment statements...

int [] count = new int[100];
for(int i = 0; i < 100; i++)
count[i] = 0;

43
New cards

each java class definition is usually in a file by itself

- file begins with name of the class
- ends with .java

44
New cards

Does the use of public, have no restrictions on how variables are used

yes

45
New cards

There are two kinds of java methods

1. return a single item
2. perform some other action - a void method

46
New cards

is the main method a void method?

yes! its invoked by the system, and not by the application program

47
New cards

When defining a void method..

think of method as defining an action to be taken
EX: setters, main methods

48
New cards

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

49
New cards

the keyword
~ this ~ stands for?

the receiving object

50
New cards

what are variables declared inside a method?

local variables

51
New cards

Type specified as public

any other class can directly access that object by name

52
New cards

Whats the only way objects of a class can be altered outside of a class?

By using the set method

53
New cards

When instance variables are private must provide methods to...

-access values with: getters (accessors)
-change the values:
setters (mutator)

54
New cards

what contains more than interface, less than full implementation AND written before class is defined?

UML Class Diagrams

55
New cards

(true/ false) all variables are not implemented as a memory location

FALSE, all variables are implemented as a memory location

56
New cards

Data of primitive type stored in the memory location is assigned where?

the variable

57
New cards

variable of class type contains what?

memory address of object named by the variable

58
New cards

(True/ False) A reference type variable holds references (memory addresses)

True

59
New cards

Can you use == to compare two objects?

NO, must use equals method ( .equals() )

60
New cards

whats is a special method called when an instance of an object is created? (it creates, initializes, object of a class)

A constructor

61
New cards

Can a constructor have parameters?

Yes, to specify initial values if desired

62
New cards

What is a constructor without parameters called?

a default constructor

63
New cards

(true/false) If you do define a constructor, Java will NOT automatically define a default constructor

True

64
New cards

What are static variables?

static variables are shared by all objects of a class; shared across all instances of a class

65
New cards

(true/false) variables declared static final are considered constants?

true, the value cannot be changed

66
New cards

(true/false) both static variables and instance variables are sometimes called fields or data members

true

67
New cards

RANDOM NUMBERS: the following simulates rolling a six sided die

int die = (int) (6.0 * Math.random() ) + 1;

68
New cards

(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

69
New cards

what is a collection of classes grouped together into a folder?

a package

70
New cards

what tells complier path name for directory containing classes of package?

the package name

71
New cards

(true/false) a primitive type has a wrapper class to allow treatment as an object?

true

72
New cards

what class can have instance variables, constructors, methods?

an enumeration class

73
New cards

ternary operator syntax

(condition) ? expression1 : expression2;

74
New cards

what does selection sort do?

It orders an array into ascending or descending order

75
New cards

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");
}
}

76
New cards

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.

77
New cards

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.

78
New cards

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

79
New cards

what is the index of the first item in the first row and second column

array[0][1]

80
New cards

what is the index of the first item in the first row and first column

array[0][0]

81
New cards

What is method overloading?

When you have two methods in the same class that have the same name but different parameters.