r/javahelp • 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.

28 Upvotes

18 comments sorted by

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.

  1. Well use Java mainly to build the app functionality. Like you would normally and use javafx to test it works.

  2. If it's an app with data I recommend using an open source project or something to b able to parse and use XML as a way to store data. Probably the simplest. (Google Java XML parser)

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:

  1. print text to the screen

  2. read user input into the program

  3. create a text file in the application (first as a fixed name, then with a name given by the user)

  4. save the information input by the user in the file.

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.

8

u/iPissVelvet May 30 '19

This is bad advice. OP should actually try to program something simple, like an own personal app, and problem solve from there.

Will their first project be a mess of spaghetti? Yeah probably. But then it’s time to learn design patterns. How can someone understand design patterns if they have no experience with actual app code (not school assignment code)?

To be fair, this advice is good for the second or third+ go around to coding an app.

0

u/[deleted] May 30 '19

[deleted]

2

u/In-nox May 31 '19

oooo I'm an expert android developer. Start simple, design the UI using an activity. Worry about fragments and more advance UI paradigms later. Look up MVC design pattern which is pretty standard for mobile.

1

u/iPissVelvet May 30 '19

Can you expand? What do you mean by aesthetic part... code aesthetic or app?

0

u/[deleted] May 30 '19

[deleted]

2

u/iPissVelvet May 30 '19

Ah, yeah design is hard.

Btw don’t be worried. I’m probably worse than you at design aesthetic — found plenty of jobs with no problem.

2

u/morhp Professional Developer May 31 '19

Don't expect that you can create a full app with good design as a beginner in a few days. That stuff can take months to years for a whole team of experienced designers and coders.

Start small, very small. For example crate an app that displays the current time. Nothing more. If that works and looks reasonable, maybe add application setting where you toggle the display of seconds or switch between am/pm and 24 hour time. Or something like that. It sounds easy but you will definitely run into problems and after you solved them you've got experience and the next ui won't be so difficult anymore.

0

u/[deleted] May 31 '19

[deleted]

1

u/morhp Professional Developer May 31 '19

Please decide what you want to do. Unity development will be completely different to Javafx and android.

If you want to write an android app use android studio. For Javafx (java desktop apps, pretty nobody writes/uses these except businesses) use Intellij or eclipse. Unity is for making games I guess.

Don't do everything at the same time, you will confuse things.

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

  • duplication of code

  • one change in functionality requires multiple similar code changes in different places

  • adding new functionality requires more work than it "feels like" should be necessary I recommend that if you have trouble learning design patterns just skip them for a while and just get more experience under your belt. But also keep in mind that some design patterns are more widely applicable or easier to grok than others.

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.