WEEK 7 2005

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/48

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 6:22 AM on 4/16/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

49 Terms

1
New cards

What is a namespace in programming?

A container for a set of unique identifiers/names.

2
New cards

What is the purpose of packages in Java?

Packages allow us to bundle together groups of related classes.

3
New cards

How do you declare a package in a Java file?

By placing 'package pkgname;' at the top of the .java file.

4
New cards

What happens if the package declaration is forgotten?

An error occurs at runtime.

5
New cards

What is the relationship between directory names and package names?

The directory name and package name must match.

6
New cards

How can nested packages be accessed in Java?

By chaining the dot operator, e.g., pkgb.subpackage1.MyClass.

7
New cards

What is the default package in Java?

The package that is automatically imported from the directory where the program is run.

8
New cards

How can all classes in a package be imported at once?

Using the import statement 'import pkg.*;'.

9
New cards

What is a static import statement?

It allows access to static fields or methods from a class without needing to call the class name.

10
New cards

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.

11
New cards

How can you add directories to the Classpath?

By using the --class-path flag or its shorthand -cp.

12
New cards

What does JAR stand for?

Java Archive.

13
New cards

What are access modifiers in Java?

Keywords that set the accessibility of classes, methods, and variables.

14
New cards

What does the public access modifier allow?

Access from any class in any package.

15
New cards

What is the default access modifier?

It allows access to classes in the same package only.

16
New cards

What is the protected access modifier used for?

It allows access to subclasses and classes in the same package.

17
New cards

What is a typical structure of a Java project?

It includes directories like README, lib, src, and may have main and test directories.

18
New cards

What is the significance of the 'src' directory in a Java project?

It contains the project code and resources.

19
New cards

What should be done to avoid confusion when running Java programs?

Always run programs from the top-level directory of the project.

20
New cards

What happens if you try to access a default member from a different package?

Access will be denied.

21
New cards

Can a subclass access protected members from a different package?

Yes, protected members can be accessed by subclasses even in different packages.

22
New cards

What is an example of a package structure in Java?

A package named 'vehicles' containing classes like Car and Bicycle.

23
New cards

How does Java find packages when an import statement is used?

Java searches for corresponding subdirectories starting from the active directory.

24
New cards

What is the purpose of the lib directory in a Java project?

To store any JAR files that the project relies on.

25
New cards

What is the command to compile a Java class in a package?

javac pkgname/ClassName.java.

26
New cards

What is the command to run a Java class in a package?

java pkgname.ClassName.

27
New cards

What are exceptions in Java?

Exceptions are runtime errors that occur during the execution of a program.

28
New cards

What is a common runtime error related to arrays in Java?

java.lang.ArrayIndexOutOfBoundsException

29
New cards

What is the purpose of a try-catch block?

To catch exceptions and handle errors without crashing the program.

30
New cards

What happens if an exception is not caught?

The method terminates immediately and the exception propagates up to the parent method.

31
New cards

What is the role of the 'catch' block?

To execute code that handles the exception if it matches the thrown exception type.

32
New cards

Can a try block have multiple catch blocks?

Yes, a try block can have multiple catch blocks to handle different types of exceptions.

33
New cards

What is the throwable hierarchy in Java?

Throwable is the superclass for all errors and exceptions in Java.

34
New cards

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.

35
New cards

What is a RuntimeException?

A type of exception that indicates a logical error in the program and does not require checked handling.

36
New cards

What is a checked exception?

An exception that must be either caught or declared in the method signature using the throws keyword.

37
New cards

What is the purpose of the throws keyword?

To declare that a method can throw certain exceptions, allowing the caller to handle them.

38
New cards

How can you create a custom exception in Java?

By extending the Exception class or one of its subclasses.

39
New cards

What is the StackFull class used for?

To represent a situation where a stack is full, extending the Exception class.

40
New cards

What happens when you try to push onto a full stack?

An exception is thrown indicating that the stack is full.

41
New cards

What is the StringStack class?

A class that implements a stack data structure specifically for strings.

42
New cards

What does the pop() method do in a stack?

It removes and returns the top element of the stack.

43
New cards

What is the significance of exception inheritance?

It allows catch blocks to handle multiple types of exceptions that share a common superclass.

44
New cards

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.

45
New cards

What is an example of a situation that might cause an exception?

Inputting a non-integer value when an integer is expected.

46
New cards

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.

47
New cards

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.

48
New cards

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.

49
New cards

What does the term 'unchecked exceptions' refer to?

Exceptions that do not need to be declared or caught, such as RuntimeException.