Topic 1.3: Java Basics - Create executable Java applications with a main method; run a Java program from the command line; produce console output Flashcards

1
Q

this format flag adds grouping separators to numeric values.

A

How does the format flag “,” affect numeric values in printf()?

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

This is part of Java Runtime Environment (JRE) and is Responsible for executing Java bytecode.

it achieves this by interpreting and translating bytcode into machine-specific instructions.

A

define and note the role of the
Java Virtual Machine (JVM)

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

The console output methods belong to the PrintStream class.

A

Which class do the console output methods belong to?

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

How does the format flag “-“ affect the output in printf()?

A

This format flag left-justifies the value within the specified width

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

How can
console output
be performed in Java?

A

this can be performed using the out field of the System class (System.out). which is an instance of the PrintStream class

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

This format flag left-justifies the value within the specified width

A

How does the format flag “-“ affect the output in printf()?

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

In what order should elements of the format specifiers be used in printf()?

A

The order for these is

%[flags][width][precision][specifier]

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

This determines the number of digits after the decimal point for floating-point numbers.

Note:
rounding upwards will occur

A

What is the purpose of precision in printf()?

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

An executable Java application is a program that can be executed independently.

A requirement for this is that we define a class with a special method called the main method. the main method will then act as the entry point for the program execution

A

What is a requirement for creating an executable java application

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

What is the purpose of the width specifier in printf()?

A

this specifies the minimum number of characters to be printed for the corresponding value.

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

define the
Java Runtime Environment (JRE)
and note some of its components

A

This Consists of files and components necessary for running Java applications at runtime.

Notable components include:
* Java Virtual Machine (JVM): Executes Java bytecode.
* Standard Java class libraries: Collection of pre-defined classes and APIs.
* Runtime components: Additional tools and resources required for execution.

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

the syntax / usage of this is using a period (.) followed by a positive integer after the width specifier.

A

What is the syntax for specifying precision in printf()?

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

How can you specify the width of the output in printf()?

A

The width is specified as a positive integer between the % symbol and the format specifier.

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

The printf() method is used to create formatted strings by replacing format specifiers with values.

A

What is the purpose of the printf() method?

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

This is a software development kit provided by Oracle Corporation for developing, compiling, and running Java applications.

Notable components include:
* Java Compiler (javac): Used to compile Java source code into bytecode.
* Java Runtime Environment (JRE): Includes the JVM (java) and necessary runtime components for running Java applications.
* Development Tools: Various tools for Java development, such as debugger, profiler, and documentation generator.

A

define the
Java Development Kit (JDK)
and note some of its components

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

Step: Compile the source code using the Java compiler (javac).

Command: javac YourClass.java

Output: Creates a .class file containing the bytecode.

A

what is the

  • first step
  • command
  • output

of Running a Java Program from the Command Line

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

What are some common format specifiers in printf()?

A

Common format specifiers include:
* %s (string),
* %d (integer),
* %f (floating-point),
* %c (character),
* and %b (boolean).

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

What is the purpose of the printf() method?

A

The printf() method is used to create formatted strings by replacing format specifiers with values.

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

Format flags change the behavior of the format specifier and are set using a single character preceded by the % symbol

A

What is a format flag in printf()?

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

what is the output of

System.out.printf("%.3f", 1.23456789);

A

Output: 1.235

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

what is the
header of the main method

A

the header for this is:

public static void main(String[] args)

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

What does the format flag “(“ do in printf()?

A

This format flag encloses negative numbers within parentheses.

23
Q

what is the output of

System.out.printf("|%-10s|", "Hello");

A

Output: |Hello |

24
Q

what is the output of

System.out.printf("%(.2f", -3.14);

A

Output: (3.14)

25
Q

The order for these is

%[flags][width][precision][specifier]

A

In what order should elements of the format specifiers be used in printf()?

26
Q

This format flag pads numeric values with leading zeros instead of spaces. note that a length must be given and the “-“ flag may not be used

A

What is the purpose of the format flag “0” in printf()?

27
Q

what is the

  • second step
  • command
  • output

of Running a Java Program from the Command Line

A

Step: Execute the bytecode using the Java Virtual Machine (JVM) and runtime environment.
Command: java YourClass (extension is not required)
Output: JVM starts the execution and searches for the main method in YourClass. The main method in YourClass is executed, and the program starts running

28
Q

This format flag encloses negative numbers within parentheses.

A

What does the format flag “(“ do in printf()?

29
Q

What is the difference between the println() and print() methods?

A

The println() method adds a new line character at the end of the text, while the print() method does not automatically add a new line character.

30
Q

The println() method adds a new line character at the end of the text, while the print() method does not automatically add a new line character.

A

What is the difference between the println() and print() methods?

31
Q

Common format specifiers include:
* %s (string),
* %d (integer),
* %f (floating-point),
* %c (character),
* and %b (boolean).

A

What are some common format specifiers in printf()?

32
Q

What is the purpose of the format flag “0” in printf()?

A

This format flag pads numeric values with leading zeros instead of spaces. note that a length must be given and the “-“ flag may not be used

33
Q

what is the

  • first step
  • command
  • output

of Running a Java Program from the Command Line

A

Step: Compile the source code using the Java compiler (javac).

Command: javac YourClass.java

Output: Creates a .class file containing the bytecode.

34
Q

What does precision refer to in printf()?

A

Precision applies to floating-point numbers and determines the number of digits after the decimal point.

35
Q

what is the output of
System.out.printf("%+d", 42);

A

Output: +42

36
Q

what is the output of

System.out.printf("%,d", 1000000);

A

Output: 1,000,000

37
Q

The width is specified as a positive integer between the % symbol and the format specifier.

A

How can you specify the width of the output in printf()?

38
Q

What does the format flag “+” do in printf()?

A

This format flag includes a sign (+ or -) for numeric values.

39
Q

This Consists of files and components necessary for running Java applications at runtime.

Notable components include:
* Java Virtual Machine (JVM): Executes Java bytecode.
* Standard Java class libraries: Collection of pre-defined classes and APIs.
* Runtime components: Additional tools and resources required for execution.

A

define the
Java Runtime Environment (JRE)
and note some of its components

40
Q

this can be performed using the out field of the System class (System.out). which is an instance of the PrintStream class

A

How can
console output
be performed in Java?

41
Q

define the
Java Development Kit (JDK)
and note some of its components

A

This is a software development kit provided by Oracle Corporation for developing, compiling, and running Java applications.

Notable components include:
* Java Compiler (javac): Used to compile Java source code into bytecode.
* Java Runtime Environment (JRE): Includes the JVM (java) and necessary runtime components for running Java applications.
* Development Tools: Various tools for Java development, such as debugger, profiler, and documentation generator.

42
Q

Step: Execute the bytecode using the Java Virtual Machine (JVM) and runtime environment.
Command: java YourClass (extension is not required)
Output: JVM starts the execution and searches for the main method in YourClass. The main method in YourClass is executed, and the program starts running

A

what is the

  • second step
  • command
  • output

of Running a Java Program from the Command Line

43
Q

This format flag includes a sign (+ or -) for numeric values.

A

What does the format flag “+” do in printf()?

44
Q

define and note the role of the
Java Virtual Machine (JVM)

A

This is part of Java Runtime Environment (JRE) and is Responsible for executing Java bytecode.

it achieves this by interpreting and translating bytcode into machine-specific instructions.

45
Q

What is the syntax for specifying precision in printf()?

A

the syntax / usage of this is using a period (.) followed by a positive integer after the width specifier.

46
Q

What is the purpose of precision in printf()?

A

This determines the number of digits after the decimal point for floating-point numbers.

Note:
rounding upwards will occur

47
Q

How does the format flag “,” affect numeric values in printf()?

A

this format flag adds grouping separators to numeric values.

48
Q

What is a format flag in printf()?

A

Format flags change the behavior of the format specifier and are set using a single character preceded by the % symbol

49
Q

what is the output of
System.out.printf("%08d", 42);

A

Output: 00000042

50
Q

Precision applies to floating-point numbers and determines the number of digits after the decimal point.

A

What does precision refer to in printf()?

51
Q

the header for this is:

public static void main(String[] args)

A

what is the
header of the main method

52
Q

What is a requirement for creating an executable java application

A

An executable Java application is a program that can be executed independently.

A requirement for this is that we define a class with a special method called the main method. the main method will then act as the entry point for the program execution

53
Q

this specifies the minimum number of characters to be printed for the corresponding value.

A

What is the purpose of the width specifier in printf()?

54
Q

Which class do the console output methods belong to?

A

The console output methods belong to the PrintStream class.