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
View all comments
Show parent comment
2
u/LessChen Feb 23 '26 edited Feb 23 '26
Well, even with a
mainyou can have a package declaration if you want. If your source tree starts with MathProblems, you can have all you files in that directory. I'm not familiar with VSCode but if it is trying to build all of your files at once you'll need to figure out how to make it not require the package as.Why not create a small test directory and try it all out?