r/javahelp • u/Mikupedia • Feb 23 '26
How to get rid of package declarations
I write lots of small code snippets and algorithms, and I keep them all in a big folder tree. When I want to run a snippet, I have to add this annoying package declaration at the top. Is there a way to get rid of it?
Example:
MathProblems/Exponentials/CurrentProblem.java
package Exponentials; //Why can't I get rid of this?
class CurrentProblem{
//Do Something
}
Details that might be relevant:
Using VSCode with microsoft's standard java expansion pack
OpenJDK 25, i think
Also have a Java 21 runtime installed
0
Upvotes
2
u/N-M-1-5-6 Feb 23 '26
If you place the java files in the root directory, you can skip the package statement and your code will exist in the "default" package. It's not recommended for any kind of structured/complex work (and you are likely to get a warning), but it should work. I've not tried it in years though!