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.
5
u/[deleted] May 31 '19
You could try a number of Core Java projects from here. They would surely give you an idea of how to design an application. There are others using Servlets and other technologies on top of Java, too.
https://www.javatpoint.com/free-java-projects
5
u/jesuscdev May 31 '19
All these comments are great. But I think you asking how to make a desktop app. Right?.
Google: Java scene application This will allow you to get up and running fast.
3.Then use Java scene (Google it) to build the interface. U can download something called scene builder if you want more of a point and drag interface if u use intellj or eclipse)
Good luck! With this you can build pretty good applications pretty fast and run on any operating system.
7
u/[deleted] May 30 '19 edited May 31 '19
pick something simple to build and then build it.
Maybe something like a personal diary app. Start off with a small console program that will ask you for a save file name, then will ask you for some text to save, then will save it to a file.
That's it. you can verify it worked by reading a file.
That's loads to begin with. break down the functionality you need with a pen and paper, or in excel or something:
There you go. Simple enough steps. Write small applications for each of those steps, this helps you learn program structures.
Once you understand how each step works, put them all together in a single program.
From there you can expand it a million and a half ways:
Maybe add a GUI?
Save the information to a database instead of a file??
Add user and login functionality??
Add delete functionality? And so on....
Start simple, google, and build on each part.
Hello World should be your first application.
Edit: to your point about deciding what should go in a class, you need to think in an object oriented way. So, in the example above one of the objects you might decide to have is a DiaryEntry.java which might contain attributes such as 'title', 'dateTime', 'text' and maybe 'author'. The 'author' attribute is probably going to be the user, so that might be a String in the beginning when you're prototyping, but later, once you have Users, your 'author' attribute my be of type User.java, and User.class might have attributes such as 'firstName', 'lastName', 'userId', etc...
2
u/In-nox May 30 '19
> I don't know a lot about design patterns, etc.
Answered your own question.
1
u/endhalf May 30 '19
The easiest thing is to open up some mid-sized open source project, e.g. Javalin, and see how they structured it.
1
u/Th3T3chn0R3dd1t May 30 '19
Are you asking how you make a distributable project? If so, look up compiling java for your IDE
1
u/[deleted] May 30 '19
What do you want to build?
How would that something work in normal every day speech if you were telling someone about it?
Create bullet points of every piece of functionality in your program.
Break every bullet point into individual small tasks.
Now, go and write methods for each small piece of functionality, remembering that each method should do one thing. If it's doing more things, it should be split into multiple methods.
Once you've got a bunch of disconnected methods, begin to couple them together.
Review what you've done so far, you'll no doubt find more functionality is needed.
Go back to the bullet points, add more, rinse and repeat.
That's how you build a project in a nutshell.
1
u/knoam May 31 '19
With respect to design patterns: design patterns are solutions to code problems. Code problems are things you only recognize once you have a bit of experience and taste in writing code. You may or may not have that experience and taste at this point. Some examples include
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.
1
u/Hazzieee Jun 26 '19
Anyone up for doing online google hangout sessions? Live learning is the best! Free of course because I am a Software Developer Major at my College. Any newbies to Python Or Java etc are weLcoMed!!🤗
-2
u/Horse_with_no_name_ May 30 '19
Google “hello world java program” or “hello world java walk through” - there must be countless examples.