Recall & Review
beginner
What is a package in Java?
A package in Java is a way to group related classes and interfaces together. It helps organize code and avoid name conflicts.
touch_appClick to reveal answer
beginner
How do you declare a package in a Java source file?
You declare a package at the very top of the Java file using the keyword
package followed by the package name, for example: package com.example.myapp;touch_appClick to reveal answer
beginner
Why should you use packages in Java?
Packages help keep your code organized, make it easier to find classes, and prevent naming conflicts by grouping classes with the same name into different packages.
touch_appClick to reveal answer
intermediate
What is the folder structure rule for Java packages?
The folder structure on your computer must match the package name. For example,
package com.example.myapp; means your file should be inside folders com/example/myapp/.touch_appClick to reveal answer
intermediate
How do you compile a Java file that uses packages from the command line?
You run
javac from the root folder above the package folders. For example, if your file is in com/example/myapp/, run javac com/example/myapp/MyClass.java.touch_appClick to reveal answer
Where should the
package statement appear in a Java file?What folder structure matches the package
org.school.project?What is the main benefit of using packages in Java?
If your Java file is in
com/example/app/, how do you compile it from the root folder?Can two classes with the same name exist in a Java project?
Explain how to create and use a package in Java from writing the code to compiling it.
Why is it important to match the folder structure with the package name in Java?
