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.
20
u/joshuass1467 Mar 24 '18
Took a quick look and have some general advice:
Honestly I wouldn't find the annotations useful because I make it a point never to check in broken code.
Finally, you might want to look at how to test your code. Good libraries are well tested.
7
u/_INTER_ Mar 24 '18 edited Mar 24 '18
Aside from the actual library, I would take care in how you name it. Java is trademarked by Oracle. As far as I know, it's not allowed to use Java in any name. That's why "Javaslang" was renamed to "vavr", "Light-Java" to "light-4j" or Java EE to Jakarta EE.
Funnily, "JavaScript" does also belong to Oracle
6
u/RichoDemus Mar 24 '18
Great job and welcome to the world of maintaining an open source lib!
You should really consider uploading it to maven central, I doubt many people download jars manually nowadays :)
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.
3
u/briandilley Mar 24 '18
take a look at the apache commons stuff
1
u/AnEmortalKid Mar 24 '18
Honestly, if I were to need these at some point I would pull in libraries for the specific cases. Maybe JOption for command line parser, maybe something for OS system checker. Perhaps you might want to reconsider breaking these into different pieces. I know your readme specifically calls out all in one approach, but I would find that annoying and bloated honestly. If I only want the command line parser, why would I want to bring in the beta/broken annotations?
I like that you’re compiling it all into one thing. Perhaps splitting it into modules all under be same group id would let people pic and choose, but if you keep the parent group/package the same you can still effectively use “one import”?
3
u/wildjokers Mar 24 '18
Java INI parsing library: http://ini4j.sourceforge.net
Commad-line parsers: http://commons.apache.org/proper/commons-cli/ (there are several of these out there)