PPJ Flashcards

Java Programming Basics

1
Q

Physical components like processors, memory, storage, and input/output devices.

A

Hardware

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

Software that manages hardware and provides services to applications.

A

Operating System

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

Tools used to create software instructions.

A

Programming Language

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

The smallest unit of data (0 or 1).

A

Bits

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

A sequence of 8 bits.

A

Bytes

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

A base-16 numbering system used for representing binary data.

A

Hexadecimal

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

The central processing unit that executes instructions.

A

Processor

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

Basic operations performed by the processor.

A

Instructions

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

A sequence of instructions that performs a task.

A

Program

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

Translates human-readable code into machine code.

A

Compiler

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

Close to machine code (e.g., assembly language).

A

Low-level

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

More human-readable (e.g., Python, Java, C++).

A

High-level

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

values in the range [−128,127];

A

byte (1)

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

values in the range [−32 768,32 767];

A

short (2)

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

values in range[0,65 535] interpreted as Unicode code
points of characters (always non-negative);

A

char(2)

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

values in the range [−2 147 483 648,2 147 483 647];

A

int (4)

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

values in an astronomical range [−9 223 372 036 854 775 808, 9 223 372 036 854 775 807].

A

long (8)

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

values in the range [≈1.4·10−45,≈ 3.4·10+38] positive or negative, with roughly 7 significant decimal digits – rarely used;

A

float (4)

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

values in the range [≈4.9·10−324 ≈ 1.8·10+308] positive or negative, with roughly 16 significant decimal digits.

A

double (8)

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

has only two possible values: true and false.

A

boolean

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

Built-in data types for basic values like numbers or characters

A

Primitive types

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

User-defined or pre-defined complex data structures.

A

Object types

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

are named storage locations in memory that hold specific data types. Only primitive types can be directly assigned names. Object types are accessed through references.
Literals are the actual data values assigned to variables.

A

Variables

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

Primitive types are stored on the ___, while objects reside on the ___

A

stack, heap

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

automatically manages memory allocation and deallocation for objects

A

garbage collector

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

0 1 1 0 1 1 0 0
0 1 0 1 0 1 0 1
6
—————
& 0 1 0 0 0 1 0 0

A

AND

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

0 1 1 0 1 1 0 0
0 1 0 1 0 1 0 1
—————
| 0 1 1 1 1 1 0 1

0 1 1 1 1 1 0 1

A

OR

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

0 1 1 0 1 1 0 0
0 1 0 1 0 1 0 1
—————
^ 0 0 1 1 1 0 0 1

A

XOR

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

~ 0 1 1 0 1 1 0 0 -> 1 0 0 1 0 0 1 1

A

Negation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q
  • A region of memory used for storing local variables and function call information.
  • Follows LIFO (Last-In-First-Out) principle: values are added and removed from the top.
  • Automatically managed by the JVM.
  • Efficient for accessing and storing data.
  • Variables declared within blocks are typically stored on the stack.
A

Stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q
  • A region of memory used for dynamically allocated objects.
  • Requires manual memory management (allocation and deallocation).
  • Slower to access than the stack due to pointer indirection.
  • Objects created using new are stored on the heap.
  • The garbage collector automatically reclaims unused heap memory.
A

Heap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q
  • \a – (BEL) alert;
  • \b – (BS) backspace;
  • \f – (FF) form-feed (new page);
  • \n – (LF) new line (linefeed);
  • \r – (CR) carriage return;
  • \t – (HT) horizontal tab;
  • \v – (VT) vertical tab;
  • \’ – apostrophe;
  • " – quotation mark;
  • \– backslash;
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

double x = 7.7;
int a = (int)x;

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

Symbols that represent actions to be performed on values (operands).

A

Operators

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

operate on two operands (e.g., +, -, *, /).

A

Binary operators

36
Q

operate on one operand (e.g., ++, –).

A

Unary operators

37
Q

is the only operator with three operands.

A

Ternary operator (?:)

38
Q

Work with int, long, float, and double.

A

Arithmetic types

39
Q

Operands may be converted to match the same type

A

Implicit conversion

40
Q

Truncates the fractional part towards zero.

A

Integer division:

41
Q

Remainder follows the sign of the first operand.

A

Negative operands

42
Q

System.out.println(“ 7 / 2 = “ + ( 7 / 2 ));

A
43
Q

Determines the order of operations when multiple
operators are present.

A

Operator Precedence:

44
Q
  • Defines the grouping of operands with the same
    precedence.
  • Most operators are left-to-right associative.
A

Associativity

45
Q

are single orders for the computer to perform.
* They often correspond to multiple low-level machine instructions.

A

Instructions

46
Q

are instructions that have a value (expressions) or don’t (e.g., variable declarations).

A

Statements

47
Q

Used to control program flow based on conditions.

A

Conditional Statements

48
Q

if statement: executes a block of code if a condition is true.
else if statements: optional checks for additional conditions if the first fails.
else statement: optional block to execute if none of the previous conditions are true.

A
49
Q

are expressions that evaluate to true or false.

A

Conditions

50
Q

Similar to if statements but with multiple conditions.
Evaluates a selector expression against case values.
Executes code associated with the matching case.
break statement: exits the switch after a case is matched (optional).
default clause: executes if no case matches (optional).

A

Switch Statements

51
Q

Used to repeat a block of code multiple times.

A

Loops

52
Q

Executes the body as long as a condition is true.
Checks the condition before each iteration.

A

while loop

53
Q

Similar to while but executes the body at least once.
Checks the condition after each iteration.

A

do-while loop

54
Q

Concise loop construct with initialization, condition, and increment/decrement.
Executes the body as long as the condition is true, updating the expression after each iteration.

A

for loop

55
Q

are the simplest data structure.
* They store a fixed-size collection of elements of the same type.
* Elements are ordered and accessed using their index (starting from 0).

A

Arrays

56
Q

are created using the new keyword followed by the type and size in square brackets ([]).
* The size cannot be changed after creation.
* Example: int[] arr = new int[10]; creates an array of 10 integers.

A

Arrays

57
Q
  • Elements are accessed using their index within square brackets (arr[i]).
  • Example: arr[3] = 25; assigns the value 25 to the fourth element (index 3).
A
58
Q
  • The for loop is commonly used to iterate through each element.
    o for (int i = 0; i < arr.length; i++) { … }
  • Alternatively, the for-each loop can be used for concise iteration.
    o for (int element : arr) { … }
A
59
Q

don’t exist directly in Java.
* Instead, you create arrays of references to objects.
* Example: String[] names = new String[5];

A
  • Arrays of objects
60
Q
  • Java doesn’t have true multi-dimensional arrays.
  • Arrays can hold references to other arrays, simulating multiple dimensions.
  • Example: int[][] matrix = new int[3][4]; creates a 3x4 matrix of integers.
A
61
Q
  • Definition: Functions declared with the static keyword belong to the class itself, not to instances of the class.
  • Access: Invoked using the class name followed by a dot (.) and the function name (ClassName.functionName()).
A

Static Functions

62
Q

Static Functions

  • Components:
    o static keyword
    o Return type …
    o Function name …
    o Parameter list …
    o Function body …
A

(or void if no return value)
(starts with a lowercase letter)
(optional, enclosed in parentheses)
(enclosed in curly braces)

63
Q

o Arguments passed are copies of values, pushed onto the program stack.
o Function operates on these copies, originals remain unchanged.
o Arrays are passed by reference (address of the array), but modifications affect the original array.

A

Static Functions

64
Q

o Can call themselves within their definition.
o Important to have a base case to prevent infinite recursion.

A
  • Recursive Functions:
65
Q

o Defining multiple functions with the same name but different parameter lists.
o Compiler chooses the appropriate function based on argument types.
o Useful for functions with similar functionality but different input types.

A
  • Function Overloading:
66
Q

Represent real-world entities with data (fields) and actions (methods).

A
  • Objects
67
Q

Define blueprints for creating objects with specific characteristics.

A
  • Classes
68
Q

Fields and methods that belong to a class.

A
  • Members
69
Q

Accessed through object references.

A

o Non-static members

70
Q

Belong to the class itself, accessed without object references

A

o Static members

71
Q
  • The new operator is used to create objects from a class definition.
  • The object gets its own copy of non-static fields.
  • Static fields are shared among all objects of the class.
A

Creating Objects

72
Q
  • Non-static methods are invoked on object references using dot notation (.).
  • Static methods are accessed using the class name followed by the dot notation.
A

Member Access:

73
Q
  • Access control keywords (public, private, protected, default) determine how members can be accessed from other classes.
A

Member Visibility

74
Q
  • Special methods with the same name as the class.
  • Used to initialize object fields during creation.
  • Can be overloaded (have different parameter lists).
A

Constructors

75
Q
  • Methods used to access and modify private fields.
A

Getters and Setters:

76
Q
  • Used for data or functions common to all objects of the class.
  • Accessible even before creating any objects.
A

Static Members

77
Q
  • Immutable: Once created, their content cannot be changed.
  • Better for security and thread safety: Modifications require creating new objects, which makes them less prone to errors and safer in multi-threaded environments.
  • Used for constant data: Ideal for storing data that won’t be modified, like configuration values or text displayed on the screen.
  • Slower for frequent modifications: String concatenation with the + operator creates new String objects each time.
A

Strings

78
Q
  • Mutable: Their content can be modified after creation.
  • More efficient for frequent changes: Operations like append, insert, and delete directly modify the internal character array, avoiding unnecessary object creation.
  • Can be less secure and thread-unsafe: Modifications happening concurrently can lead to unexpected results. Use with caution in multi-threaded environments.
  • Used for building strings dynamically: Great for scenarios where you need to construct a string by combining different parts.
A

StringBuilders

79
Q
  • Ordered sequence of elements.
  • Each element (node) holds data and a reference to the next node.
  • Efficient for adding/removing elements at the beginning or end.
  • Less efficient for random access or modifying elements in the middle.
  • Good for implementing stacks and queues.
A

Singly Linked Lists

80
Q
  • Elements are added (pushed) and removed (popped) from the top.
  • Think of a stack of plates - you remove the top plate first.
  • Implemented using singly linked lists (adding/removing from the front) or arrays.
  • Used for function calls, undo/redo functionality, and expression evaluation.
A

Stacks (LIFO - Last In, First Out)

81
Q
  • Elements are added (enqueued) at the back and removed (dequeued) from the front.
  • Think of a line at a store - the first person in line gets served first.
  • Implemented using singly linked lists (adding/removing from the beginning and end).
  • Used for task scheduling, printer queues, and breadth-first search algorithms
A

Queues (FIFO - First In, First Out):

82
Q

is a fundamental concept in object-oriented programming (OOP) that allows you to create new classes based on existing ones.

A

Inheritance

83
Q
  • Inheritance creates a relationship between classes, where a new class (subclass or derived class) inherits properties and behaviors from an existing class (superclass or base class).
A
84
Q
  • Think of it as “is-a” relationship. For example, a Dog is-a Animal.
A
85
Q

Benefits of Inheritance:
* Code Reusability: You don’t need to rewrite code for common functionalities present in the superclass. The subclass inherits these functionalities and can add its own specific behavior.
* Maintainability: Changes made to the superclass automatically propagate to subclasses that inherit from it, making code updates easier.
* Polymorphism: Inheritance enables polymorphism, where objects of different subclasses can be treated as objects of the superclass. This allows for flexible and dynamic behavior in your programs.

A