1/48
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is a namespace in programming?
A container for a set of unique identifiers/names.
What is the purpose of packages in Java?
Packages allow us to bundle together groups of related classes.
How do you declare a package in a Java file?
By placing 'package pkgname;' at the top of the .java file.
What happens if the package declaration is forgotten?
An error occurs at runtime.
What is the relationship between directory names and package names?
The directory name and package name must match.
How can nested packages be accessed in Java?
By chaining the dot operator, e.g., pkgb.subpackage1.MyClass.
What is the default package in Java?
The package that is automatically imported from the directory where the program is run.
How can all classes in a package be imported at once?
Using the import statement 'import pkg.*;'.
What is a static import statement?
It allows access to static fields or methods from a class without needing to call the class name.
What is the Classpath in Java?
The Classpath is a parameter that tells the Java Virtual Machine where to look for user-defined classes and packages.
How can you add directories to the Classpath?
By using the --class-path flag or its shorthand -cp.
What does JAR stand for?
Java Archive.
What are access modifiers in Java?
Keywords that set the accessibility of classes, methods, and variables.
What does the public access modifier allow?
Access from any class in any package.
What is the default access modifier?
It allows access to classes in the same package only.
What is the protected access modifier used for?
It allows access to subclasses and classes in the same package.
What is a typical structure of a Java project?
It includes directories like README, lib, src, and may have main and test directories.
What is the significance of the 'src' directory in a Java project?
It contains the project code and resources.
What should be done to avoid confusion when running Java programs?
Always run programs from the top-level directory of the project.
What happens if you try to access a default member from a different package?
Access will be denied.
Can a subclass access protected members from a different package?
Yes, protected members can be accessed by subclasses even in different packages.
What is an example of a package structure in Java?
A package named 'vehicles' containing classes like Car and Bicycle.
How does Java find packages when an import statement is used?
Java searches for corresponding subdirectories starting from the active directory.
What is the purpose of the lib directory in a Java project?
To store any JAR files that the project relies on.
What is the command to compile a Java class in a package?
javac pkgname/ClassName.java.
What is the command to run a Java class in a package?
java pkgname.ClassName.
What are exceptions in Java?
Exceptions are runtime errors that occur during the execution of a program.
What is a common runtime error related to arrays in Java?
java.lang.ArrayIndexOutOfBoundsException
What is the purpose of a try-catch block?
To catch exceptions and handle errors without crashing the program.
What happens if an exception is not caught?
The method terminates immediately and the exception propagates up to the parent method.
What is the role of the 'catch' block?
To execute code that handles the exception if it matches the thrown exception type.
Can a try block have multiple catch blocks?
Yes, a try block can have multiple catch blocks to handle different types of exceptions.
What is the throwable hierarchy in Java?
Throwable is the superclass for all errors and exceptions in Java.
What is the difference between Error and Exception in Java?
Error represents serious problems that a reasonable application should not catch, while Exception represents conditions that a program might want to catch.
What is a RuntimeException?
A type of exception that indicates a logical error in the program and does not require checked handling.
What is a checked exception?
An exception that must be either caught or declared in the method signature using the throws keyword.
What is the purpose of the throws keyword?
To declare that a method can throw certain exceptions, allowing the caller to handle them.
How can you create a custom exception in Java?
By extending the Exception class or one of its subclasses.
What is the StackFull class used for?
To represent a situation where a stack is full, extending the Exception class.
What happens when you try to push onto a full stack?
An exception is thrown indicating that the stack is full.
What is the StringStack class?
A class that implements a stack data structure specifically for strings.
What does the pop() method do in a stack?
It removes and returns the top element of the stack.
What is the significance of exception inheritance?
It allows catch blocks to handle multiple types of exceptions that share a common superclass.
What is the purpose of JUnit in relation to exceptions?
JUnit is used for testing Java code, including verifying that exceptions are thrown as expected.
What is an example of a situation that might cause an exception?
Inputting a non-integer value when an integer is expected.
What should you do when catching an exception?
Decide how to handle the error, such as printing an error message or prompting for new input.
What is the role of the top field in the StringStack class?
It serves as an index to track the exclusive top of the stack.
What is the difference between recoverable and unrecoverable exceptions?
Recoverable exceptions can be handled and the program can continue, while unrecoverable exceptions usually indicate a fatal error.
What does the term 'unchecked exceptions' refer to?
Exceptions that do not need to be declared or caught, such as RuntimeException.