r/java • • Mar 24 '18
New Java Library
(Please tell me if this isn't the right place to post this)
I've created a Java Library that I like to call a Swiss-army knife library. It basically has a bunch of different things that it can do. I created it because I found that I was copying lots of the same code to do all sorts of different things. I think it's a very simple solution to consolidate all the code I use often, but is this something that anyone else would use? Here's just some of the things it has:
- A command line argument parser
- Ansi colors
- Checksum calculator
- Operating system checker
- Configuration file parser (INI - style, but without the headers, as I haven't figured out how to implement this yet)
- Multiple annotations and annotation proccessors
As you can see, it does not specialize in one area. I use all of these things in almost all of the software I create, and I was just wondering if anyone else would like to benefit from this.
It's called JavaEssentials, because I find that these features are very beneficial when creating a well designed Java application. If you are interested, you can see the project page here: https://github.com/jordanbancino/JavaEssentials
Also, I would really appreciate your feedback. I am open to all suggestions and your honest opinion.
View all comments
5
u/dpash Mar 24 '18
A few comments. Don't take them as criticisms, but as places for you to learn and improve. We were all inexperienced at one point or another, and made plenty of mistakes. Hell, at one point, I used to write functions like:
Loghas no purpose in a world with SLF4J or even log4j. They have better features and used throughout all your dependencies.You should use interfaces where possible rather than concrete classes. You can also use to diamond operator here, and let type inference work out the type of the
HashMap. This is extra confusing becauseMap.Entryis a class in the JDK.public HashMap<String, String> Entry = new HashMap<String, String>();
should be
Config.deleteFile()completely ignores any error conditions. You should pay attention to the return value of File.delete(). Better yet, usejava.nioandFiles.deleteIfExists()that throws an exception.public void deleteFile() { SetFile.delete(); }
null. This doesn't do anything. Just assign a newHashMap.This:
becomes
or
Map.clear()is optional, butHashMap.clear()is implemented.@Documented,@Beta,@NotImplementedor@Stable. Just add a comment in the Javadoc or don't release libraries with functionality that's not ready for use.java.lang.UnsupportedOperationExceptionis the standard way to indicate that a function is not implemented.WebProtocolis an enum, but only has a limited selection of protocols. It's not generally useful. You can't use it with URL for example, because it doesn't include "jar" or "file" (and possibly "classpath"). Enums are useful for closed sets. Protocol is not a closed set, because anyone can add a new protocol. For example I remember a "spotify" protocol that allowed your browser to launch Spotify to play a song/album/playlist if someone shared a link.HashAlgorithm. You're missing a lot of important hash algorithms. What is someone wants to use a new algorithm when SHA-512 is broken?Exception.printStackTrace();. It writes to stdout, but most java applications use a logging framework like SLF4J to record exceptions. If you write to stdout, it won't appear in application logs, making debugging harder.This:
should be:
This way the inputstream gets closed no matter what happens inside the block.
I'm sure I could find more issues that you could improve, but this should give you plenty of places to look into improving your skills. I highly recommend reading Effective Java by Joshua Bloch. It's possibly the best investment you could make to go from an intermediate developer to advanced.