Unit 2: Java Fundamentals Flashcards

1
Q

True or False: Java is an object-oriented language

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Objects can not be created without creating a blue-print associated to that object. This blue-print is known as…

A

Class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In Java, all codes are written inside…

A

Classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True or False: class is not a keyword (reserved word)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What would the line of code “System.out.println(“Hello Everyone!”);” display and where would it display?

A

The code would display Hello Everyone! on the standard output (monitor)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True or False: System is a class

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

True or False: By convention, the first letter of each word in the class name is not capitalized

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Define: Class

A

A class is a template, blueprint or contract that defines the attribute (data field) and methods (functionalities/behavior) associated with certain entities (the instances of that class)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Define: Object

A

An object is an instance of class. An instantiated object is given a name, and it is created/placed in the memory using the structure described within a class declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Computer can execute code in _________

A

Machine language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The extension of a java virtual object file is:

A

.class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The extension of a java source code file is:

A

.java

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

True or False: The source code in java is compiled into bytecode

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True or False: Bytecode is machine dependent

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

True or False: In java, the main() method has to be declared as a static method of a class

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In the following java statement, what does “System” represent:

System.out.println(“Welcome to Java!”);

A

A class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

The name of a variable or object is used to:

A

Distinguish one variable from another

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

The type of a variable or object is used to:

A

Tell the memory how much this variable needs and what can be assigned to it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What type of statement is this:

float w_lb, w_kg

A

A declaration statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What type of statement is this:

w_kg = w_lb * 0.454

A

An assignment statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

True or False: a+b/c+d is the same as a+(b/c)+d in java language

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What value will be left over in this math statement:

3-8%5

A

Zero

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the value of newNum after these statements:

int i = 10;
int newNum = 10 * i++;

A

100

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

True or False: The following two java statements perform the same operation:

regWages = regPay + overTime;
regPay + overTime = regWages;

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

True or False: The following two java statements will result in the same value for y:

y = a + b * c;
y = b * c + a;
A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

True or False: The following statement doubles the value stored in answer:

answer *= 2;

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

True or False: The following statement will evaluate to true if x is between 1 and 100 or the number is negative:

((x<100) && (x>1)) || x<0

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What will the value of c be after the following statements:

int a = 3, b = 2;
double c;
c = (a+b)/2;

A

2.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What will the value of c be after the following statements:

float a = 3, b = 2;
int c;
c = (a+b)/2;

A

The code will not compile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What will be the output of the following code:

int a = 2, b = 4;
a = ++b;
System.out.println(a+”, “+b);

A

5, 5

31
Q

What will be the output of the following code:

boolean a = false;
a = 5 == 5;
System.out.println(a);

A

true

32
Q

What will be the output of the following code:

int a;
System.out.println(a);

A

Compilation error will be generated

33
Q

What will be the output of the following code:

int a = 2, b = a + 2; double b = 4;
System.out.println(a/b);

A

Compilation error will be generated

34
Q

What will be the output of the following code:

int a = 2, float b = 4.0;
System.out.println(a/b);

A

Compilation error will be generated

35
Q

Define: println() method

A

Displays a message or data to the standard output and moves the cursor to the next line

36
Q

Define: print() method

A

Displays a message or data to the standard output

37
Q

What do these backslash codes/escape sequences do, respectively:

\n, \t, ", ', \, \b

A

Creates a new line (like the enter key), tabs the argument, creates double quotations without interrupting the string, creates single quotations without interrupting the argument, creates a backslash, backspaces (identical to keyboard)

38
Q

Describe the steps it takes to convert java into machine code

A
  1. Text editor
  2. Compiler
  3. Bytecode (virtual machine code)
  4. Java Virtual Machine (JVM)
39
Q

Define: Compilation error (syntax error)

A

When the machine cannot execute the code because there is a grammatical error in the source code the machine cannot understand

40
Q

Define: Runtime error (known as exception in java)

A

When the program environment detects an operation that is impossible to carry out when the program is running (e.g. integer divided by integer zero)

41
Q

Define: Logical error (program bugs)

A

When a program does not perform the way it was expected to perform

42
Q

Define: Identifier

A

Programmer defined names for variables, constants, classes, methods, namespaces, with specific characteristics

43
Q

What are the characteristics an identifier is able to have?

A

Any letter (upper or lower case), any digits, and two special characters (_ and $)

44
Q

What characteristics can an identifier not have?

A

It cannot start with a digit, cannot be a reserved word, and cannot include spaces

45
Q

Define: float/double

A

Datatypes that store both fractional and whole numbers in the memory

46
Q

Define: char

A

Datatype that stores single characters in the memory

47
Q

Define: int

A

Datatype that stores only whole numbers in the memory

48
Q

Define: boolean

A

Datatype that stores only true or false in the memory

49
Q

What are the 8 primitive data types?

A

byte, short, int, long, float, double, boolean, char

50
Q

What must be done first in a code in order to allow for data to be input from the keyboard and what is the code?

A

You must import the Scanner class from the java.util package

input java.util.Scanner;
or you could put… input java.util.*; for all classes in java.util package

51
Q

What are the methods in the Scanner class?

A

nextByte();, nextShort();, nextInt();, nextLong();, nextFloat();, nextDouble();, next();, nextLine();, next().charAt(0);, nextLine().charAt(0);

52
Q

Define: final

A

Assigns a value to a variable that cannot be changed later in the code. This is a modifier and it appears before the declaration of a datatype

53
Q

What is the naming convention for constants?

A

All capital letters with underscores to act as spaces (e.g. final int MINIMUM_DRIVING_AGE = 16;)

54
Q

Define: Java operator

A

Take one or more input values (known as operands) and produce one output value

55
Q

List some java operators

A

+, -, *, /, =, ==, !=, ||, &&, >, =

56
Q

Define: Unary, binary, and ternary operators respectively

A

Uses one operand, uses two operands, uses three operands

57
Q

What would the following code display?

int j = 4, u = 11, m = u/j;
System.out.println(m);

A

2

58
Q

Define: Modulo operator (%)

A

Displays the remainder of when one value is divided into another (e.g. 11%4.5 would display 2)

59
Q

Describe what the output of the code below is and what happens to the variable:

int a = 9;
System.out.println(-a);

A
Displays: -9
The variable (a) is still 9
60
Q

Describe what the output of the code below is and what happens to the variable:

boolean k = true;
System.out.println(!k);

A
Displays: false
The variable (k) is still true
61
Q

Describe what the output of the code below is and what happens to the variable:

int m = 9;
System.out.println(++m);

A
Displays: 10
The variable (m) is no longer 9 and becomes 10
62
Q

Describe what the output of the code below is and what happens to the variable:

int n = 9;
System.out.println(–n);

A
Displays: 8
The variable (m) is no longer 9 and becomes 8
63
Q

True or False: a += b; is the same as a = a + b;

A

True

64
Q

What does this expression mean:

U and only U Are the best CLAss in the Univers

A

It is an easy way to remember operator precedence (Unary [pre-increments], Unary [negate, invert], Arithmetic, Comparison, Logical, Assignments, Unary [post-increments]

65
Q

Assigning a value, of one data type to another, requires only one of two possible operations. What are the two possible operations?

A

Widening/implicit conversion, and narrowing/casting/explicit conversion

66
Q

Define: Widening conversion (implicit conversion)

A

In an arithmetic expression involving two different datatypes, the final result of the expression will be stored using the operand with the highest data range in memory. It is automatic (e.g. int a, float b; (a+b); will be float type where int a gets promoted/widened to float a)

67
Q

Define: Narrowing/explicit conversion (casting)

A

“Casts a spell” on a datatype to make it take up less data and converts it to a smaller datatype. It only works for whatever line the cast operator is on

68
Q

What would the following code display:

int i = 4, j = 5, k = 9;
System.out.printf(“The addition of %d and %d is %d”,i,j,k);

A

The addition of 4 and 5 is 9

69
Q

Define: Format specifiers

A

Used in the printf(); method to specify what datatype a variable is

70
Q

What are some examples of format specifiers?

A

%b (boolean value), %c (character), %d (integer), %f (floating point number), %e (number in scientific notation), %s (string), %o (octal number), %x (hexadecimal number)

71
Q

What are the 5 most frequent errors amongst all programmers?

A
  1. Undeclared/non-initialized variables
  2. Integer overflow (assign a variable a value outside of datatype’s range)
  3. Round-off errors (0.1 + 0.7 = 0.799999999999)
  4. Unintended integer division
  5. Redundant input objects
72
Q

How do you write comments in 1036?

A

Write a summary at the top of the code to explain what the program does, key features, supporting data structures, and unique techniques it uses. Include name, class section, instructor, date, and a brief description at the beginning of the program. Include your own comments that may cause yourself confusion when self-reviewing later

73
Q

What are the naming conventions for customizable names in java?

A

Variables or method names: Meaningful and descriptive names, all lowercase, concatenate the words if there are multiple word using camelcase

Class: Capitalize the first letter of the word, use camelcase

Constants: Capitalize all letters, use snakecase