You can get the current working directory as
File cwd = new File("./");
If you then need to make this into an absolute path there is
cwd.getAbsolutePath();
You can create a new directory there with
File newDir = new File(cwd, "newDirectory"); newDir.mkdir();
But my code is somewhere else: /home/root/...../project/class.java
The current working directory is (usually) the directory where you start Java from. This is completely unrelated to where the jar files are, and this in turn is completely unrelated to where the source code is.
You need to set the current working directory properly when you start the Java program (not the compiler).
If you start from a shell, cd to where you need it to be. If you start from an IDE, there should be a setting.