Java SE 17 Fundamentals

¡Supera tus tareas y exámenes ahora con Quizwiz!

What are the four basic logical operators in Java?

& (AND), | (OR), ^ (XOR), and ! (NOT)

What is the difference between & and &&?

& always evaluates both sides, && only evaluates right side if necessary (short-circuit)

What must every Java application have as its entry point?

A method named "main" that is public static void and contains specific parameters (String[] args).

What is a variable in Java?

A named area of storage that can hold data values of a specific type

What is a for-each loop?

A simplified loop for iterating through array elements without using index

What are the basic arithmetic operators in Java?

Addition (+), subtraction (-), multiplication (*), division (/), and modulus (%)

What is the 'var' keyword used for?

Allows compiler to infer variable type based on the assigned value

What is the static keyword used for with methods?

Allows method to be called without creating an instance of the class

How are primitive types stored in Java?

By value - each variable gets its own independent copy of the value

How are parameters passed in Java?

By value - meaning a copy of the original value is passed to the method

How are command-line arguments separated?

By whitespace, unless enclosed in quotes

What is the modulus operator (%) used for?

Calculates the remainder after division

What happens when you modify a parameter inside a method?

Changes only affect the copy within the method, not the original value

How do you prevent division by zero in conditional logic?

Check if denominator != 0 before performing division

How do package names affect source code organization?

Each part of the package name becomes a subfolder within the source code folder (e.g., com/pluralsight/project).

What's the difference between float and double?

Float is 32-bit with less precision, double is 64-bit with more precision. Float literals need 'f' suffix

What is the advantage of using a for loop over a while loop?

For loop provides simplified notation for initialization, condition, and update in one line

How does the IDE interact with JDK and JRE?

IDE coordinates with JDK for building code and JRE for running the application.

What's the difference between running Java in IDE vs. command line?

IDE handles build and run processes automatically, while command line requires manual java command and correct package path specification.

What is the purpose of the void keyword?

Indicates a method doesn't return any value

What are the three parts of a for loop control?

Initialization, condition check, and update statement

What is conditional assignment syntax in Java?

condition ? value_if_true : value_if_false

What is switch case fall-through?

When a case lacks a break statement, execution continues into the next case

When should you use a switch instead of if-else?

When testing a single variable against multiple specific values

When should you use a do-while instead of while loop?

When you need the loop body to execute at least once regardless of the condition

When should you use a for-each loop instead of regular for loop?

When you need to process all elements sequentially and don't need the index

What is the key difference between while and do-while loops?

While checks condition before first iteration, do-while checks after - ensuring at least one execution

How does Java handle whitespace in statements?

Whitespace (spaces, tabs, newlines) serves only as visual separators and doesn't affect program behavior.

How do Java statements end?

With a semicolon (;).

How are array indices structured in Java?

Zero-based indexing, meaning first element is at index 0

What's the difference between = and == in conditions?

= is assignment operator, == is equality comparison operator

What are the three ways a method can exit?

1. Reaching the end 2. Executing a return statement 3. Throwing an exception

What is the standard entry point file structure in Java?

A class containing a public static void main(String[] args) method.

What is a method in Java?

A code block that can be reused throughout an application, with a name, parameters, and optional return value

What is a block statement in Java?

A group of statements enclosed in curly braces {} that are treated as a single unit

What is a while loop in Java?

A loop that executes as long as a condition is true, checking the condition before each iteration

What are two main purposes of comments in Java?

1. To add human-readable notes in source code 2. To hide code temporarily without deleting it.

What is a String in Java?

An immutable sequence of Unicode characters stored in UTF-16 format

What is an array in Java?

An ordered collection of elements of the same type with fixed size

What types can methods return?

Any primitive or object type, including arrays

What are implicit type conversions?

Automatic conversions done by compiler for widening conversions (smaller to larger type)

What is the default case in a switch statement?

Code that executes when no case matches the switch value

What is method overloading?

Creating multiple methods with same name but different parameter lists

How does integer division differ from floating point division?

Integer division discards any fractional portion, while floating point division keeps decimals

What primitive data types can be used with switch?

Integer types (byte, short, int, long) and char

What are the four categories of primitive data types in Java?

Integer types, floating point types, character type, and boolean type

What is an IDE?

Integrated Development Environment - The tool developers interact with to edit, build, run, and debug applications (e.g., IntelliJ).

Why is package naming convention important?

It ensures global uniqueness of package names and provides consistent organization of source code.

What does a package declaration do to a class name?

It fully qualifies the class name with the package name (e.g., com.pluralsight.project.Main).

What is the JDK?

Java Development Kit - Provides the tools required to create Java applications, available in Oracle's version or OpenJDK (open-source version).

What is the JRE and what does it do?

Java Runtime Environment - Enables Java code to execute by translating bytecode into native code that can run in a host environment.

How do you pass an array to a method?

Like any other parameter, using the array type: methodName(int[] arrayParam)

How are line comments different from block comments?

Line comments (//) ignore everything until the end of the line, while block comments (/ */) can span multiple lines.

What are the three types of comments in Java?

Line comments (//), block comments (/* /), and Javadoc comments (/* /).

What does the 'final' modifier do?

Makes a variable immutable - once its value is set, it cannot be changed

What are explicit type conversions?

Manual conversions using cast operator, can do both widening and narrowing conversions

What happens when no return statement is used in a void method?

Method automatically returns at end of method body

What are parallel arrays?

Multiple arrays where elements at same index are related and used together

What are the limitations of 'var'?

Must be initialized when declared, and type remains fixed once inferred

What is method parameter scoping?

Variables declared as parameters or inside a method are only visible within that method

How does variable scope work in block statements?

Variables declared inside a block are only visible within that block

Can array size be changed after creation?

No, arrays in Java are fixed size once created

Can you nest block comments in Java?

No, you cannot nest one block comment inside another block comment.

What do users need to run a Java application?

Only the JRE (Java Runtime Environment) and the application files (.class files).

What are prefix and postfix operators?

Operators (++ or --) that increment/decrement by 1, placement affects when the operation occurs

What are compound assignment operators?

Operators that combine arithmetic with assignment (+=, -=, =, /=, %=)

What is positional parameter passing?

Parameters are matched by position - first argument to first parameter, etc.

What does it mean that Java is strongly typed?

Variables must be declared with a specific data type and can only store values compatible with that type

What is the difference between void and non-void methods?

Void methods don't return a value, non-void methods must return a value of declared type

What is the order of operator precedence (highest to lowest)?

Postfix, prefix, multiplicative (, /, %), additive (+, -)

What's the difference between prefix and postfix increment?

Prefix (++x) increments then returns value, postfix (x++) returns value then increments

What is the purpose of the break statement in switch cases?

Prevents fall-through to the next case by exiting the switch

What is the length property of an array used for?

Returns the number of elements in the array

What is the XOR (^) operator used for?

Returns true if exactly one of two conditions is true, but not both

What naming convention is used for Java packages?

Reverse domain name notation, all lowercase (e.g., com.pluralsight.project).

What are relational operators used for in Java?

Test relationships between two values using symbols like >, <, >=, <=, ==, and !=

What is the purpose of the switch statement?

Tests a single variable against multiple possible matching values

What is operator precedence in Java?

The order in which operators are evaluated in an expression

What is a parameter list?

The parentheses after method name containing zero or more parameters with their types

What happens if you declare a variable inside an if block?

The variable is only accessible within that if block's scope

Why are Java applications platform-independent?

They contain bytecode instead of native code, allowing them to run on any platform with a JRE installed.

What happens to uninitialized array elements?

They get default values (0 for numbers, false for boolean, null for objects)

How are command-line arguments accessed?

Through the String[] args parameter in the main method

What happens if you try to access an array index out of bounds?

Throws ArrayIndexOutOfBoundsException at runtime

Why use logical operators instead of multiple if statements?

To combine multiple conditions into a single test and improve code readability

How do you initialize an array with values in Java?

Using curly braces: int[] array = {1, 2, 3, 4, 5}

How do you chain multiple if-else statements in Java?

Using else if: if (condition1) {...} else if (condition2) {...} else {...}

How can you override operator precedence?

Using parentheses to explicitly specify the order of operations

How do you run a Java application from the command line?

Using the 'java' command followed by the fully qualified class name (including package name).

How do you determine the size of an array?

Using the array's length property: array.length

How do you return a value from a method?

Using the return keyword followed by the value to return

How do you exit a method early?

Using the return statement (with or without value depending on return type)

What are command-line arguments?

Values passed to program at startup, received as String array in main method

What is the camelCase naming convention in Java?

Variable names start with lowercase, and each subsequent word starts with uppercase (e.g., bankAccountBalance)

How do you declare an array in Java?

dataType[] arrayName = new dataType[size] or dataType[] arrayName = {values}

What is the syntax for a for-each loop?

for (dataType element : array) { statements }

What is the basic structure of a for loop?

for (initialization; condition; update) { statements }

What is the structure of a basic if-else statement?

if (condition) { statement } else { statement }

How do you declare a method in Java?

returnType methodName(parameterType paramName) { // method body }

What is the difference between | and ||?

| always evaluates both sides, || only evaluates right side if necessary (short-circuit)


Conjuntos de estudio relacionados

RE174 Ch 3 Duties & Responsibilities of Licensees

View Set

IB Biology Topic 6 Human Physiology

View Set

Homeowners: Section II Liability Coverage

View Set

Chapter 08: Nervous System Feedback Quiz

View Set