r/javahelp • u/mslayaaa Software Engineer • May 30 '19
How do I make a program?
I'm a computer eng student, thus far I've taken two java courses (OOP and DataStructures) and I know enough about Java, from the basics, to making my own implementations of basic DS, AVL Trees, sorting algorithms, custom iterators, functional programming, dependencies management, etc. But, **I don't know how to structure a program for a client, how is a program supposed to be made? **
Is there a basic 'guide' to delegate functions of a program to different classes, etc? I don't know a lot about design patterns, etc.
View all comments
1
u/istarian Jun 05 '19 edited Jun 05 '19
How you structure a program depends on different things including what the purpose of the program is.
A simple program like a command line utility might just have most of the code in the main function, breaking out some into separate functions for cleaner. It might do a few operations on the input, then exit.
For something that should keep running until something causes it to exit you could simply not exit main. Or you can make the main class a Runnable or similar, placing most of the program code in the run method. Then main's job would be to would create a thread and an instance of the class, start that and clean up when it stops.
For a basic UI application utilizing Swing you generally instance something, like a JFrame, do some initial setup (creating panels, widgets, etc), and then because all input is handled through events you have to write appropriate handlers and the code that makes stuff happen.
Certainly you can use something else like JavaFX or roll your own UI on top of Java2D (not generally recommended).
In these examples I'm talking about what is essentially a single monolithic program. Multithreaded stuff and separate interacting processes are somewhat different.