Introduction to Java

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

1/82

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

83 Terms

1
New cards
<p>What’s missing</p>

What’s missing

static void 

2
New cards
<p>What’s missing</p>

What’s missing

.println

3
New cards
<p>What’s missing?</p>

What’s missing?

System.out

4
New cards
<p>What’s missing?</p>

What’s missing?

String[] args

5
New cards

How can you make the integer literal 1000000 more readable in Java code without changing its value?

Use underscores to separate blocks. Example: int num = 1_000_000;

6
New cards

Identify the data type of 'A'

char

7
New cards

Identify the data type of  “A”

String

8
New cards

Identify the data type of  123

int

9
New cards

What is the difference between these two literals? 1 vs '1'

  • 1 is an Integer (used for math/counting).

  • '1' is a Character (just a symbol, like a letter).

10
New cards

Spot the error in this code: char letter = "B";

Type Mismatch.

11
New cards

What is the relationship between a Method and a Block?

A Method is a named operation that contains a Block as its body

  • Method = Name + Block

  • Block = Just the code inside {}

12
New cards

I look like this: ; What am I in Java, and what do I signify?

I am a Semicolon. I mark the end of a Statement

13
New cards

I look like this: { ... } What is the name for the group of statements inside me?

A Block.

14
New cards

I look like this: // or /* What comes after me?

Comments.

15
New cards

If you write a variable name like public or class, Java will stop you. Why?

Because they are Keywords. (These are reserved words

16
New cards

In "Sequential Flow," in what order does the computer read your code?

Top to Bottom.

17
New cards

What do we call the strict set of grammar rules

Syntax

18
New cards

I am a specific word chosen by you to name a variable or a function. What am I?

An Identifier. (Example: In int apples = 5;, the word apples is the identifier.)

19
New cards

I am a sequence of statements grouped together to perform a "high-level operation" (a subprogram). What am I?

A Method.

20
New cards

I include spaces, tabs, and newlines. You cannot see me on the screen, but I help organize the code. What am I?

Whitespace.

21
New cards

Why is the main method essential?

It makes the program runnable. (Without it, the program has no "Entry Point" and cannot start.)

22
New cards

Is the word main considered a Java keyword?

No. (It is a predefined method name

23
New cards

If you name the method Main (capital M) instead of main (lowercase m), will it work?

No. (Java is case-sensitive. It must be exactly main.)

24
New cards

What does String[] args represent in the main method?

It represents arguments

25
New cards

What specific character must be used to end every statement in Java?

A semicolon ;

26
New cards

What does the println method do that a normal print command might not?

It displays the string followed by a new line

27
New cards

In the code System.out.println("Hello");, is the text "Hello" a keyword or identifier?

Neither. (It is just a String literal(

28
New cards
<p>Spot the Error</p>

Spot the Error

  • Class Name: Starts with a digit (1MyProgram).

  • Method Name: Capitalized (Main should be main).

  • Missing Semicolon: After the print statement.

29
New cards

If I want to print the result of math (like 5 + 5 = 10), which format must I use?

System.out.println(5 + 5)

30
New cards

What is the main difference between System.out.println() and System.out.print()?

  • println prints text and moves the cursor to the next line.

  • print prints text and keeps the cursor on the same line.

31
New cards

What happens if you run System.out.println(); with nothing inside the parentheses?

It prints an empty line.

32
New cards

When the program prints a String (like "Hello") or a Char (like 'A'), do the quote marks appear on the screen?

No. The quotes are just containers for the code; only the text inside is displayed.

33
New cards

What is the "Escape Character" used to insert a new line inside a single string?

\n

34
New cards

What will this code output? System.out.print("A\n\nB");

A

B

35
New cards

Can System.out.print handle numbers (like 108) without quotes?

Yes

36
New cards

What is the output of this code? System.out.println(3 + 3 + " is the result")

6 is the result

37
New cards

What is the output of this code? System.out.println("Result: " + 3 + 3);

Result: 33

38
New cards

In the code String message = "Hi";, is message the variable or the identifier?

message is the Identifier (the name).

39
New cards

Is 1stPlayer a valid variable name? Why or why not?

No. Variable names (identifiers) cannot start with a digit.

40
New cards

Does Java treat score and Score as the same variable?

No. Java is case-sensitive.

41
New cards

How do you declare multiple variables of the same type on a single line?

Separate them with a comma. Example: String name = "John", lastName = "Doe";

42
New cards

Since Java 10, which keyword allows the computer to automatically guess the variable type based on the value?

var (Type Inference). Example: var age = 10; (Java treats this as an int).

43
New cards
int price = 100;
price = "Free";

Type Mismatch

44
New cards
var data;
data = 10;

Missing Initialization. When using var, you must assign a value immediately so Java can guess the type. You cannot split declaration and initialization with var.

45
New cards
int a;
a = 50;

Yes. It is valid to declare a variable first (int a;) and initialize it later (a = 50;), though doing it on one line is preferred.

46
New cards

What is the famous 4-word phrase that describes Java's platform independence?

Write once, run anywhere

47
New cards

To run a program, the java tool opens a file with which specific extension?

.class

48
New cards

Does the JVM understand high-level languages like Java or Kotlin directly?

No. The JVM only understands Java Bytecode.

49
New cards

Is the code that goes into the JVM platform-independent or platform-dependent?

Platform-Independent

50
New cards

Name three "JVM Languages" (languages that compile to bytecode).

  • Java

  • Kotlin

  • Scala (Also: Groovy, Clojure)

51
New cards

If a user enters "150" using sc.next(), what Java Data Type does the program store this value as?

A String

52
New cards

What is the advantage of using a method like sc.nextInt() instead of just sc.next()?

sc.nextInt() reads the input directly as an integer type, making it easier to perform mathematical operations immediately.

53
New cards

To get the 3 digit of a three-digit in 320?

(320 %1000)/100

54
New cards

To get the 2 digit of a three-digit in 320?

(320 % 100) /10

55
New cards

To get the 0 digit of a three-digit in 320?

320 % 10

56
New cards

Simplify a = a + b.

a+=b

57
New cards

Simplify a = a / b.

a /=b

58
New cards

int x = 10;

int y = ++x; y=?

11

59
New cards
What is the final value of y in this postfix example?
int x = 10; 
int y = x++;

10

60
New cards

If you want text to print on the same line but appear in separate, aligned columns, which escape sequence should you use?

\t (Tab)

61
New cards

What is the core reason why you must type \\ to get a single backslash in your output?

Because the single backslash (\) is the escape character—it must be escaped itself to lose its special meaning

62
New cards

You are defining a String: "He said, "Yes"". Which escape sequence is missing to make this valid?

\" (The code should be: "He said, \"Yes\"")

63
New cards

What is the primary visual difference between the behavior of \r (Carriage Return) and \n (Newline)?

r moves the cursor back to the start of the same line (causes overwriting), while \n moves the cursor to the start of the next line.

64
New cards
String name = "Java";
char charA = name.charAt(4);

StringIndexOutOfBoundException

65
New cards
String nothing = null;
boolean check = nothing.startsWith("J");

nullPointerException

66
New cards
String empty = "";
boolean check2 = empty.isEmpty();

true

67
New cards
String data = "  Java Program  ";
data.trim().toUpperCase()

JAVA PROGRAM

68
New cards
String code = "123ABCD";
code.substring(3, 6)

ABC

69
New cards
String data = "  Java Program  ";
data.contains("P") && data.endsWith(" ")

true

70
New cards

What does the expression 1.5e3 represent mathematically?

$1.5 \times 10^3 = \mathbf{1500.0}$

71
New cards

Between float and double, which type does Java programmers typically recommend and use due to its higher precision?

double (14-16 significant digits).

72
New cards
double x = 10;
System.out.println(x / 4);

2.5

73
New cards

System.out.println(10 / 4);

2

74
New cards

boolean value = 0. what the result

Error cant convert 0 to logic

75
New cards

In a single sentence, describe the condition under which the XOR (^) operator returns true.

t returns true only if the two operands have different values (one true and one false

76
New cards

What logical operator has the highest precedence, meaning it is always evaluated first unless overridden by parentheses?

The NOT operator (!)

77
New cards

In the expression (false && [Complex Expression]), does the JVM bother to evaluate the right side? Why or why not?

No. This is short-circuit evaluation. Since the first operand of && is false, the entire result must be false, so the right side is skipped to save computation time.

78
New cards

you have (true || [Expression]), what will the overall result be, and why

The result will be true. The JVM stops (short-circuits) because one true is enough to satisfy the || operator.

79
New cards
boolean isCold = false; 
boolean isRainy = true;
boolean isSummer = false;
!isRainy || isCold

False

80
New cards
boolean isCold = false;
boolean isRainy = true;
boolean isSummer = false;

isRainy && (isCold ^ isSummer)

false

81
New cards
boolean isCold = false;
boolean isRainy = true;
boolean isSummer = false;

(isSummer || isRainy) && !isCold

true

82
New cards

What is the final value of b based on the operator precedence rules?

boolean x = true;
boolean y = false;

boolean b = x || !y && y;

true

83
New cards
boolean checkStatus() { 
    System.out.println("Checking Status..."); 
    return true; 
}

public static void main(String[] args) {
    if (false && checkStatus()) {
        System.out.println("Go");
    } else {
        System.out.println("Stop");
    }
}

false