Is there a java convention for packaging enums? [closed] - java

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...

Related

Where I define wrapper function and functional interface for exception handling on stream [closed]

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 months ago.
Improve this question
While using streams, I learned how to handle exceptions using functional interfaces and wrapper functions.
If so, what is the best way to structure the package?
Is it defined together in the class where stream is used? Or should I create a separate common class and define the wrapper function in it?
Thanks!
I think it depends. If you have one instance of using this technique, then it probably makes sense to simply use an functional interface and a wrap function that are part of the class which utilizes it. If you are using this same pattern in several places (and they all have the same function interface signature) then you can define the functional interface at the package level and put the wrap function in a utility class.

Getters and Setters positions [closed]

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.

Naming issue: what name would you give to this interface? [closed]

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'm struggling with a naming issue. What name would you give to an interface that have just one method with this signature:
public interface ?
{
boolean isAvailable();
}
Many classes in my application can implement this interface.
Not that it really matters, you can rename it any time afterwards, and with current IDEs, it is really easy to type any name using autocomplete...
That said, if you want it short, use Available, if you want it more self-explanatory, use CanBeAvailable.
Given that the word "available" already ends with "-able", I think it's okay to break with the Java interface naming convention and call it Availability. Another approach, suggested in Programmers, is to use the prefix "Can-", in which case you can call your interface CanBeAvailable.
The below are the standards defined for Naming conventions.
Class - Always be a Noun
Interface - Always be an Adjective
Method - should be a verb
So, think of some adjective which describes the purpose of your interface.

Questions regarding package names and Interfaces [closed]

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...

what do you mean by utility functions in java?how it is related to Static? [closed]

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
hi what is the actual meaning of utility function in java?
The term utility function was used by Joshua Bloch in the book Effective Java to describe the methods on classes such as Arrays, Objects and Math.
The approach predates Java, and is defined by Wikipedia - Utility Class as a set of methods that perform common, often reused functions. I would go on to also point out that the functions tend to require no Object level state, that is they tend to be global functions. And that is why, in Java they tend to become implemented as static methods on a container class. As that way there is no need to instantiate the class first, and it implies through convention that the method should not have any side effects. Of course counter examples of this probably exist, but not to my knowledge within the Java Core libraries.

Categories