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
this format flag adds grouping separators to numeric values.
How does the format flag “,” affect numeric values in printf()?
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.
define and note the role of the
Java Virtual Machine (JVM)
The console output methods belong to the PrintStream class.
Which class do the console output methods belong to?
How does the format flag “-“ affect the output in printf()?
This format flag left-justifies the value within the specified width
How can
console output
be performed in Java?
this can be performed using the out field of the System class (System.out). which is an instance of the PrintStream class
This format flag left-justifies the value within the specified width
How does the format flag “-“ affect the output in printf()?
In what order should elements of the format specifiers be used in printf()?
The order for these is
%[flags][width][precision][specifier]
This determines the number of digits after the decimal point for floating-point numbers.
Note:
rounding upwards will occur
What is the purpose of precision in printf()?
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
What is a requirement for creating an executable java application
What is the purpose of the width specifier in printf()?
this specifies the minimum number of characters to be printed for the corresponding value.
define the
Java Runtime Environment (JRE)
and note some of its components
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.
the syntax / usage of this is using a period (.) followed by a positive integer after the width specifier.
What is the syntax for specifying precision in printf()?
How can you specify the width of the output in printf()?
The width is specified as a positive integer between the % symbol and the format specifier.
The printf() method is used to create formatted strings by replacing format specifiers with values.
What is the purpose of the printf() method?
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.
define the
Java Development Kit (JDK)
and note some of its components
Step: Compile the source code using the Java compiler (javac).
Command: javac YourClass.java
Output: Creates a .class file containing the bytecode.
what is the
- first step
- command
- output
of Running a Java Program from the Command Line
What are some common format specifiers in printf()?
Common format specifiers include:
* %s (string),
* %d (integer),
* %f (floating-point),
* %c (character),
* and %b (boolean).
What is the purpose of the printf() method?
The printf() method is used to create formatted strings by replacing format specifiers with values.
Format flags change the behavior of the format specifier and are set using a single character preceded by the % symbol
What is a format flag in printf()?
what is the output of
System.out.printf("%.3f", 1.23456789);
Output: 1.235
what is the
header of the main method
the header for this is:
public static void main(String[] args)
What does the format flag “(“ do in printf()?
This format flag encloses negative numbers within parentheses.
what is the output of
System.out.printf("|%-10s|", "Hello");
Output: |Hello |
what is the output of
System.out.printf("%(.2f", -3.14);
Output: (3.14)
The order for these is
%[flags][width][precision][specifier]
In what order should elements of the format specifiers be used in printf()?
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
What is the purpose of the format flag “0” in printf()?
what is the
- second step
- command
- output
of Running a Java Program from the Command Line
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
This format flag encloses negative numbers within parentheses.
What does the format flag “(“ do in printf()?
What is the difference between the println() and print() methods?
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.
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.
What is the difference between the println() and print() methods?
Common format specifiers include:
* %s (string),
* %d (integer),
* %f (floating-point),
* %c (character),
* and %b (boolean).
What are some common format specifiers in printf()?
What is the purpose of the format flag “0” in printf()?
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
what is the
- first step
- command
- output
of Running a Java Program from the Command Line
Step: Compile the source code using the Java compiler (javac).
Command: javac YourClass.java
Output: Creates a .class file containing the bytecode.
What does precision refer to in printf()?
Precision applies to floating-point numbers and determines the number of digits after the decimal point.
what is the output of System.out.printf("%+d", 42);
Output: +42
what is the output of
System.out.printf("%,d", 1000000);
Output: 1,000,000
The width is specified as a positive integer between the % symbol and the format specifier.
How can you specify the width of the output in printf()?
What does the format flag “+” do in printf()?
This format flag includes a sign (+ or -) for numeric values.
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.
define the
Java Runtime Environment (JRE)
and note some of its components
this can be performed using the out field of the System class (System.out). which is an instance of the PrintStream class
How can
console output
be performed in Java?
define the
Java Development Kit (JDK)
and note some of its components
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.
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
what is the
- second step
- command
- output
of Running a Java Program from the Command Line
This format flag includes a sign (+ or -) for numeric values.
What does the format flag “+” do in printf()?
define and note the role of the
Java Virtual Machine (JVM)
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.
What is the syntax for specifying precision in printf()?
the syntax / usage of this is using a period (.) followed by a positive integer after the width specifier.
What is the purpose of precision in printf()?
This determines the number of digits after the decimal point for floating-point numbers.
Note:
rounding upwards will occur
How does the format flag “,” affect numeric values in printf()?
this format flag adds grouping separators to numeric values.
What is a format flag in printf()?
Format flags change the behavior of the format specifier and are set using a single character preceded by the % symbol
what is the output ofSystem.out.printf("%08d", 42);
Output: 00000042
Precision applies to floating-point numbers and determines the number of digits after the decimal point.
What does precision refer to in printf()?
the header for this is:
public static void main(String[] args)
what is the
header of the main method
What is a requirement for creating an executable java application
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
this specifies the minimum number of characters to be printed for the corresponding value.
What is the purpose of the width specifier in printf()?
Which class do the console output methods belong to?
The console output methods belong to the PrintStream class.