Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Hello everyone I would like to know your preference regarding naming java packages. As in do you prefer com.example.controllers (since it contains a group of controllers) or com.example.controller ?
Also if you have an interface named Shape do you prefer to name it IShape or just Shape?
Based on standard package names, it should be singular :
java.util.function contains multiple functional interfaces.
java.util.stream contains multiple Stream interfaces and classes.
Etc...
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
It is alright to use constructors,getters,functions,methods and setters after the main function,to me this way is more confortable?
You should create another class and put there main method. Class representing anime should be in different class. Also class should start with upper case.
There is no "hard rule" for how methods are ordered, but generally the variables are declared first, then constructors, then object methods with the getters and setters at the bottom. This is part convention and part personal preference as I've seen it done many ways. You should see java conventions: https://www.oracle.com/technetwork/java/codeconventions-135099.html and generally try to stick to those. You have quite a few naming convention Faux pas in your example... class name should be capitalized, method names should be camelCase, new lines between methods, etc.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
What is the best way to implement a set interface in Java? Or more specifically, what is the best abstract data type to use when implementing a set interface? I need to create a set class in Java that implements a given set interface, but I'm wondering what the simplest way to do this is.
An interface example is java.util.Set, which is implemented by HashSet and TreeSet.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Is there a Java convention for packaging enums? if not is there a best practice?
Should I put them all in one package "myapp.enum" or should I put each enum in its related package?
enums in Java should be treated like any other class, and should probably be placed in the package that's most related to them. There's no advantage in having a separate "enums" package.
enum is a reserved keyword so you cannot put your enums into the enum package. Packages could be named after the layers of the application (Model, View, Controller, ..) You are free to choose. The only recommendation is to use unique package names like the reverse domain name of your company: mycompany.com -> com.mycompany.myapp...
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have common methods written in different classes, making code duplicate and now to avoid this duplicacy, I am thinking of 2 approaches:
Make static methods in some util class and call them, or
Make a super class and write all these methods in super class and extend each class with this super class.
Definitely, with approach 2, I will loose the ability to extend my class further. So I am thinking to go with approach 1.
Can you please help me in identifying which approach is good and also in suggesting better approach, if you have any?
Creating Utility packages and/or class is a common solution to this problem. Apache Commons is a prime example. I would favour approach 1
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
For example if I was making an image API in Java would it be more beneficial to have multiple exception classes such as ImageSizeException, ImageFormatException or have a single exception class such as ImageException which has a string, enum ect for what kind of exception it is.
As a secondary question if you use multiple exception classes would it be more acceptable to group them in an exceptions package or with the classes that would throw them
You should certainly have a base exception, ImageException, which is the superclass of any others. Like Java has IOException.
Personally I would prefer one Exception with an Enum or int to subtype, but typical Java style is to have a lot of Exception subclasses. Your should probably follow convention.
It's Better to have many exceptions.it will be easier debugging when your code is huge,and you could have ImageException as the superclassfor all these exceptions.