How do you incorporate Java's main function into your design?

cesar :

You can actually just skip this first part cause it gets confusing, but I'll keep it here cause I want to know if anyone else feels the same way. I am a CS undergrad who has have been using Java for 3 years, and I still find it difficult to comprehend how to include the Main function into my design. It feels wrong to place it in a class all on its own, but it also feels wrong to insert it into another class file. I see the latter as such because it doesn't fit in with the rest of the class making it incohesive. I can't just stick a main function on my DocumentReader object, for example. It would have nothing to do with the object. On the other hand, I can't just make a Main class that only has a main function inside it because in object-oriented programming, you're supposed to think in terms of objects effectively creating a miniature world in your head. For that miniature world to revolve around a single object that does nothing but exist just seems off. It doesn't act as a narrator and character in a story because it does nothing, at the same time. I prefer C's style of having a Main function that is separate from everything. It keeps the narrative of the story separate from the characters that are interacting with one another.

I want to know how the professionals mix the main method into the rest of their code. How do you make it fit in with the rest of the design. Also, are they generally long or short?

Colin Hebert :

I keep the main() function in a class named as my project. With this when you launch the application with the command line you type :

java com.domain.project.ApplicationName

It seems to me logic to have a simple Launcher name rather than :

java com.domain.project.AClassWhichDoesntLookLikeAMainClass

or the (too) classic

java com.domain.project.Launcher

But don't bother too much for this class, it will probably never be executed by the end user like this. A script or another executable will launch it most of the time.

Another thing, your main() method can get heavy, especially if you really use main args for more CLI options. Maybe it deserves its own class.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do you automate Javascript minification for your Java web applications?

Do you obfuscate your commercial Java code?

How do you make your Java application memory efficient?

Using PowerMock or How much do you let your tests affect your design?

How and where do you define your own Exception hierarchy in Java?

How do you determine your permissions in AWS S3 through the Java SDK?

How do you write zero copy in java? What are the main differences

How do you write unit tests for your java servlets?

How do you scale your ActiveMQ vertically?

How do you use your interface's private methods?

How do you incorporate per pixel lighting in shaders with LIBGDX?

How do you reset/normalize your css using google material design (angular4)?

How do you design your classes in Qt with a lot of widgets?

How do you use the require function on your website?

How to incorporate weights into a likelihood function?

How Do you access function props in your class component?

How do I incorporate one function into another?

How do you change your screen's color temperature?

How do you protect your computer from Live CD's?

POSIX: How do you determine your own process's file image so you can exec yourself?

How do you return object from "__main__" python function?

Do you have to extend JApplet in your main class?

How do you incorporate node.js into java tests?

How do you incorporate a variable in a NSLayoutConstraint string?

How do you organize your file downloads?

In Node.js, how do you store callback data from a module's function in the main app?

How do you incorporate/access pod files (MMWormhole) in an extension?

How do you check if your function returns nothing?

How do you call a function in Renderer View from the Main Process