Computer Science I: Java

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

1/87

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

88 Terms

1
New cards
What are the basic components of a computer system?
Hardware, software, programs, and operating systems.
2
New cards
How is Java related to the World Wide Web?

Java was used for developing web applications and applets that run in web browsers.

3
New cards
What does JDK stand for?
Java Development Kit; it includes tools for developing Java applications.
4
New cards
What is an IDE?
Integrated Development Environment; a software application that provides comprehensive facilities to programmers for software development.
5
New cards
How do you display output on the console in Java?
Using System.out.println().
6
New cards
What is the basic syntax of a Java program?
A Java program consists of classes, methods, and statements, with a main method as the entry point.
7
New cards
How do you compile and run a Java program?
Use javac to compile and java to run the program.
8
New cards
What is camelCase?
A naming convention where the first letter of each word is capitalized except for the first word (e.g., myVariableName).
9
New cards
What is a syntax error in Java?
A syntax error occurs when the code violates Java's grammatical rules, preventing the program from compiling.
10
New cards
How do you perform simple computations in Java?
Using arithmetic operators like +, -, *, /, and %.
11
New cards
How do you obtain input from the console in Java?
Using the Scanner class.
12
New cards
What are identifiers in Java?
Names used to identify variables, constants, methods, and classes.
13
New cards
How do you store data in variables?
By declaring a variable and assigning a value to it.
14
New cards
What is an assignment statement?
A statement that assigns a value to a variable (e.g., x = 5;).
15
New cards
What are constants in Java?
Variables whose values cannot be changed once assigned, typically declared using the final keyword.
16
New cards
What are Java numeric primitive data types?
byte, short, int, long, float, and double.
17
New cards
How do you read a numeric value from the keyboard?
Using the Scanner class methods like nextInt(), nextDouble(), etc.
18
New cards
What operators are used for arithmetic operations in Java?
+, -, *, /, and %.
19
New cards
How do you perform exponentiation in Java?
Using Math.pow(a, b).
20
New cards
What are literals in Java?
Fixed values that are directly written in the code, such as integer literals, floating-point literals, and string literals.
21
New cards
How do you obtain the current system time in milliseconds?
Using System.currentTimeMillis().
22
New cards
What are augmented assignment operators?
Operators that combine an arithmetic operation with assignment (e.g., +=, -=, *=, /=).
23
New cards
What are relational operators?
Operators used to compare two values (e.g., ==, !=,
24
New cards
What is the difference between postincrement and preincrement?
Postincrement (i++) increments after the current value is used; preincrement (++i) increments before the current value is used.
25
New cards
How do you cast one data type to another in Java?
By using the cast operator (e.g., (int)variable).
26
New cards
How do you declare boolean variables?
By using the boolean keyword (e.g., boolean isTrue = true;).
27
New cards
What is a one-way if statement?
A conditional statement that executes a block of code if the condition is true.
28
New cards
What is a two-way if-else statement?
A conditional statement that executes one block of code if the condition is true and another block if it is false.
29
New cards
What is a nested if statement?
An if statement inside another if statement.
30
New cards
What is a switch statement?
A control statement that allows multi-way branching based on the value of a variable.
31
New cards
How do you generate random numbers in Java?
Using the Math.random() method.
32
New cards
What are logical operators?
Operators used to combine multiple boolean expressions (e.g., &&, ||, !).
33
New cards
What is the purpose of the break statement?
To exit a loop or switch statement prematurely.
34
New cards
What is a method in Java?
A block of code that performs a specific task and can be called when needed.
35
New cards
What is the difference between a method call and a method definition?
A method call executes the method, while a method definition specifies what the method does.
36
New cards
What is the difference between an argument and a parameter?
A parameter is a variable in the method definition, while an argument is the actual value passed to the method.
37
New cards
What are access modifiers in Java?
Keywords that set the accessibility of classes, methods, and variables (e.g., private, public, protected).
38
New cards
What is the method signature?
The combination of the method's name and its parameter list.
39
New cards
What is method overloading?
Defining multiple methods with the same name but different parameter lists.
40
New cards
What is the difference between a void method and a return method?
A void method does not return a value, while a return method returns a value of a specified type.
41
New cards
What is variable scope?
The context in which a variable is accessible, determined by where it is declared.
42
New cards
What is an API in Java?
An API (Application Programming Interface) is a set of classes and interfaces that provide functionality for Java applications.
43
New cards
How do you write a simple Java program?
Define a class, include a main method, and write statements inside it.
44
New cards
What are Java style conventions?
Rules for naming variables, classes, and methods, using camelCase and proper indentation.
45
New cards
What is the difference between style and syntax in Java?
Syntax refers to the rules of the language, while style involves best practices for readability and maintainability.
46
New cards
What is scientific notation in Java?
A way to represent very large or very small numbers using E or e (e.g., 1.23E4 for 12300).
47
New cards
What is operator precedence?
The order in which operators are evaluated in an expression.
48
New cards
What is operator associativity?
The direction in which an expression is evaluated when operators have the same precedence (left-to-right or right-to-left).
49
New cards
How do you represent characters in Java?
Using the char data type, which holds a single character.
50
New cards
What is ASCII?
A character encoding standard that represents characters using numbers.
51
New cards
What is Unicode?
A character encoding system that includes ASCII and additional characters for multiple languages.
52
New cards
What are escape sequences in Java?

Consists of a backslash (\) followed by a character or a combination of digits

53
New cards
How do you convert a numeric value to a character?
By casting an int to char (e.g., (char)65 gives A).
54
New cards
How do you compare characters in Java?
Using relational operators (==, !=,
55
New cards
What is an object in Java?
An instance of a class that contains data (fields) and methods.
56
New cards
What is an instance method?
A method that belongs to an instance of a class and requires an object to be invoked.
57
New cards
How do you represent strings in Java?
Using the String class.
58
New cards
How do you concatenate strings in Java?
Using the + operator or concat() method.
59
New cards
How do you convert a string to uppercase or lowercase?
Using toUpperCase() and toLowerCase() methods.
60
New cards
How do you remove leading and trailing spaces from a string?
Using the trim() method.
61
New cards
How do you read a string from the console?
Using Scanner and nextLine().
62
New cards
How do you compare strings in Java?
Using .equals() for content comparison and compareTo() for lexicographical comparison.
63
New cards
How do you find a character or substring in a string?
Using indexOf().
64
New cards
How do you obtain a substring from a string?
Using substring(startIndex, endIndex).
65
New cards
How do you format output in Java?

Using System.out.printf()

66
New cards
What is a while loop?
A loop that runs as long as its condition evaluates to true.
67
New cards
What is a do-while loop?
A loop that executes at least once before checking the condition.
68
New cards
What is a for loop?
A loop that consists of an initialization, condition, and update statement.
69
New cards
What is a nested loop?
A loop inside another loop.
70
New cards
What is a loop control variable?
A variable that controls the number of loop iterations.
71
New cards
What is a sentinel value?
A special value that signals the end of input.
72
New cards
What is a flag variable?
A boolean variable used to control the flow of a loop.
73
New cards
How do you exit a loop prematurely?
Using the break statement.
74
New cards
How do you skip an iteration of a loop?
Using the continue statement.
75
New cards
How can you remove a break statement from a loop?
By using a flag variable to control the loop's termination.
76
New cards
How do you pass data to a method?
By using parameters in the method definition.
77
New cards
What is method overloading?
Defining multiple methods with the same name but different parameter lists.
78
New cards
What is the private access modifier in Java?
The private modifier restricts access to the member within the same class only. It cannot be accessed from outside the class.
79
New cards
What is the public access modifier in Java?
The public access modifier in Java will allow you access to the data anywhere in the program.
80
New cards
What is the protected access modifier in Java?
The protected modifier allows a class member to be accessed within the same package and by subclasses, even if they are in different packages.
81
New cards

Draw an If Statement Flowchart

Done!

<p>Done!</p>
82
New cards

Draw an If Else Statement Flowchart

Done!

<p>Done!</p>
83
New cards

Draw a Switch Statement Diagram

Done!

<p>Done!</p>
84
New cards

Draw a While Statement Flowchart

Done!

<p>Done!</p>
85
New cards

Draw a Do-While Statement Flowchart

Done!

<p>Done!</p>
86
New cards
What is a runtime error in Java?

A runtime error occurs while running if the environment detects an operation that is impossible to carry out.

87
New cards
What is a logic error in Java?

A logic error occurs when a program does not perform the way it was intended to.

88
New cards
What is the difference between postdecrement and predecrement in Java?

Postdecrement (i--): The current value of i is used first, then i is decremented.
Predecrement (--i): i is decremented first, then the updated value is used.