1/49
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What is Java?
Java is a popular high-level, object-oriented programming language originally developed by Sun Microsystems (now owned by Oracle). It is a programming language and a platform, known for being robust and secure.
List the key features of Java.
Name some applications or uses of Java.
Java is used for:
What is JVM and its purpose?
JVM (Java Virtual Machine) is an abstract machine that provides a runtime environment for executing Java bytecode. It does not physically exist but is a specification.
What does JRE stand for and what is its function?
JRE (Java Runtime Environment) is a set of software tools that provides the runtime environment for Java applications to execute. It does not include development tools.
What is JDK and what does it include?
JDK (Java Development Kit) includes all the tools, executables, and binaries required to compile, debug, and execute a Java program. It is platform dependent.
Explain the role of the main() method in a Java program.
The main() method represents the starting point of a Java program. The JVM executes it. It is declared as public static void main(String args[]).
What is the purpose of System.out.println()?
System.out.println() is used to print a statement or value to the console. Here, System is a class, out is an object of the PrintStream class, and println() is a method of the PrintStream class.
What are Java keywords?
Java keywords are predefined words with specific meanings that act as keys to code. They cannot be used as variable, object, or class names (e.g., class, if, for, static).
How do you write a single-line comment in Java?
Single-line comments start with two forward slashes (//). Any text after // to the end of the line is ignored by Java.
Example: // This is a comment
How do you write a multi-line comment in Java?
Multi-line comments start with /* and end with */. Any text between these delimiters is ignored by Java.
Example: /* This is a multi-line comment. */
What is a variable in Java?
A variable in Java is a named memory location that acts as a container for storing data values. It is assigned a data type and holds a value during program execution.
List the three types of variables in Java.
What is a 'local variable'?
A local variable is declared inside the body of a method. It can only be used within that method.
What is an 'instance variable'?
An instance variable is declared inside a class but outside the body of any method. It is not declared as static.
What is a 'static variable'?
A static variable is declared using the static keyword. It cannot be local and is associated with the class, not an instance.
What are Java operators?
Java operators are symbols used to perform various operations on variables and values, such as addition, subtraction, comparison, and logical operations.
List some types of operators in Java.
What are Arithmetic Operators used for? Provide examples.
Arithmetic operators perform common mathematical operations.
+: Addition (e.g., x + y)-: Subtraction (e.g., x - y)*: Multiplication (e.g., x * y)/: Division (e.g., x / y)%: Modulus (division remainder, e.g., x % y)++: Increment (e.g., ++x)--: Decrement (e.g., --x)What is the purpose of Relational Operators and what do they return?
Relational (or conditional) operators check the relationship between two operands (e.g., less than, greater than, equal to). They return Boolean values (true or false).
Give examples of Java Relational Operators.
<: Less Than>: Greater Than<=: Less Than or Equal to>=: Greater Than or Equal to==: Equal to!=: Not Equal toWhat are Logical Operators used for in Java?
Logical operators perform logical operations on boolean values, commonly used in decision-making statements like if conditions and loops to control program flow.
Describe the Java Logical Operators (&&, ||, !).
&& (Logical AND): Returns true if both operands are non-zero (or true).|| (Logical OR): Returns true if at least one operand is non-zero (or true).! (Logical NOT): Reverses the logical state of its operand (makes true into false, and false into true).What do data types define in Java?
Data types define the type and value range of the data for variables, constants, method parameters, and return types. They inform the compiler about the type of data to be stored and the required memory.
What are the two main types of data types in Java?
List the eight primitive data types in Java and their general purpose.
Primitive data types are predefined by Java language:
byte: Stores small whole numbers (-128 to 127)short: Stores whole numbers (-32,768 to 32,767)int: Stores whole numbers (approx. \pm 2 \text{ billion} )long: Stores large whole numbers (approx. \pm 9 \text{ quintillion} )float: Stores fractional numbers (6-7 decimal digits)double: Stores fractional numbers (15-16 decimal digits)boolean: Stores true or false valueschar: Stores a single character/letter or ASCII valuesWhat are Non-Primitive Data Types, and why are they also called reference types?
Non-primitive data types are called reference types because they refer to objects. They are typically created by the programmer (except for String) and can call methods to perform operations.
What is a String in Java?
A String in Java is a class that represents sequences of characters, used for storing text. String variables hold collections of characters enclosed in double quotes (e.g., "Hello").
How do you find the length of a String in Java?
You can find the length of a string using the length() method.
Example: String txt = "Hello"; System.out.println(txt.length()); // Outputs 5
Name two common String methods for case conversion.
toUpperCase(): Converts a string to uppercase letters.toLowerCase(): Converts a string to lowercase letters.What are Arrays in Java?
Arrays are used to store multiple values of the same type in a single variable, effectively acting as containers for collections of values.
How do you declare and initialize an array of strings in Java?
Declaration: String[] cars;
Initialization: String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
How do you access an element of an array in Java?
You access an array element by referring to its index number, which starts from 0.
Example: String[] cars = {"Volvo", "BMW"}; System.out.println(cars[0]); // Outputs "Volvo"
What are Classes and Interfaces in Java?
What are control flow statements in Java?
Control flow statements determine the order in which statements in a Java program are executed, allowing for conditional execution and repetition of code blocks.
List the three types of control flow statements in Java.
if, switch)for, while, do-while)break, continue)What is the purpose of an if statement?
An if statement allows you to control the flow of your program by executing a block of code only if a specified condition evaluates to true.
Explain the use of if, else if, and else in Java.
if: Executes a block of code if the condition is true.else if: Specifies a new condition to test if the preceding if condition (and any else if conditions) were false.else: Executes a block of code if all preceding if and else if conditions are false.What is a switch statement used for?
A switch statement selects one of many code blocks (called cases) to be executed based on the value of an expression. It's an alternative to writing many if..else if statements.
How does a switch statement work?
switch expression is evaluated once.case value.break) stops the execution after a match.default) runs if no case matches the expression's value.What are loop statements in Java used for?
Loop statements allow a statement or group of statements to be executed multiple times, controlling the repetition of code blocks.
List the types of loops available in Java.
while loopfor loopdo...while loopfor loop (as of Java 5, for traversing collections/arrays)When is a for loop typically used?
A for loop is used when the number of times a block of code needs to be executed is known in advance. It combines initialization, condition checking, and increment/decrement into a single line.
What is the syntax of a for loop?
for (initialization; condition; increment/decrement) {
// block of statements
}
Explain the while loop in Java.
The while loop repeatedly executes a block of code as long as a specified condition remains true. It tests the condition before executing the loop body.
What is the syntax of a while loop?
while (condition) {
// code block to be executed
}
What is unique about the do-while loop compared to the while loop?
The do-while loop is a variant of the while loop that guarantees the code block will execute at least once, even if the condition is false, because the condition is tested after the initial execution of the loop body.
What is the syntax of a do-while loop?
do {
// code block to be executed
}
while (condition);
What are sorting and searching operations in the context of arrays?
What inbuilt Java Arrays class methods can be used for sorting and searching?
Arrays.sort(nameOfArray): Sorts the array in ascending order.Arrays.binarySearch(nameOfArray, element): Searches for a specified element in a sorted array and