+ 7

[Java] Tools package

Hi ! I'm a java beginner. I was wondering if it was a good idea to create a Tools Package. for example I could create a method say instead of System.out.println (). A method too to display the contents of an Array ... so I could import this toolbox into each of my projects. Thank you in advance for your opinions and good codes to all!

9th Jun 2018, 6:28 AM
Frédéric PARENT
Frédéric PARENT - avatar
3 Respostas
+ 8
Depends on the scale of your project and the benefit modularization would bring you. For printing arrays, two lines of: for (ArrayType i : yourArray) System.out.print(i + " "); doesn't seem like too much hassle to re-type each time you need it. However, I can totally see why you would need one when you want a method to handle generic datatypes, or when you have to print the array in a formatted way, e.g. in a table, with proper labels, units. Just make sure that modularizing stuff will actually save your time instead of adding complexity to your project.
9th Jun 2018, 6:45 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Hi Frédéric PARENT Yes, it's a very good idea always to create a tools(also called util, short for utility) package. I usually like to have a util package for every project I'm working on, where I put my parsers, date functionalities, etc.
9th Jun 2018, 8:55 PM
Minnie Mouse
Minnie Mouse - avatar
+ 1
I tried that method of printing. Due to my limited knowledge, I had to create the method multiple times to account for printing strings, integers, doubles, arrays etc. I'm sure there is a better way to be able to pass any data type into a function without making multiple datatypes for each, but that's just a limitation to my toolbox.
9th Jun 2018, 12:22 PM
Andre Daniel
Andre Daniel - avatar