r/learnjava • u/chimchim102 • May 27 '21
How to start building desktop applications in Java?
Hey everyone! So I'm in a bit of a tough spot right now and I need help. I have always just build web applications so I have no idea on how I should start learning about building Java applications on desktop. If someone can guide me on this please that would be alot of help. I need to build a desktop application with Java and javafx but I'm not sure where to start learning. I do know Java but just as a programming language and not really sure how to build desktop applications with it. Where do I start? I need to use Java fx that I know. Are there any good books that guide you in building a desktop application with java fx? Or a good udemy course? Thanks!
13
u/RebbitUzer May 27 '21
When I just started learning programming (Java) I thought that "writing a real program" is creating desktop gui app with buttons and all that stuff. How wrong I was. So, regarding your question, I do remember some good playlists on youtube about learning JavaFX. I don't have them saved, but try to search it on youtube
1
u/Shmirgla May 27 '21
Do you mean that you were wrong in the sense that you made webapps and android apps, or something completely different? A beginner asking here, since I'm not sure how to find a niche in which to specialize so I'm currently learning many things but only on the surface level. Do you have any advice for the direcgion in the future? My guess would be android development
4
u/RebbitUzer May 27 '21
I was wrong, because nowadays Java is rarely used for developing desktop apps with gui, indeed it's mostly used for backend development. Developing android apps is completely different than developing backend services. If you do like mobile app development - then probably android development and java/kotlin is good to learn. If you more like developing some server-side stuff (web servises, rest api, databases, etc), then learn java & spring.
5
u/berry120 May 27 '21
You don't *have* to use JavaFX, but it is probably the most logical choice these days as far as desktop UI toolkits go, for Java at least. (The only other normal choice would be Swing, which predates JavaFX but is far clunkier to use IMHO.)
There's a bunch of tutorials around (https://www.youtube.com/watch?v=t4ehYIynI34 for instance, though I haven't watched it so no idea how good it is.) JavaFX is pretty easy to pick up as far as these things go; the "biggest" new thing to learn is FXML, the markup language for defining scenes - though if you prefer, you can avoid this entirely and just define your scenes programmatically.
As others have, the only thing I'd add is that desktop Java apps are a bit of a dying / dead breed. That's not to say there's none out there, but they're rare these days - commercially at least, Java is by far primarily a server side language these days. If you're just doing it for fun then go for it, but it wouldn't be a sensible move doing it for career progression.
4
u/Skootr4538 May 27 '21
I would say avoid desktop Java. It is waste of resources learning javafx. Build a web app and package it up with Electron. You can use your app to talk to your Java spring backend
2
u/Cmgeodude May 27 '21
I'd recommend starting here: https://www.youtube.com/watch?v=FLkOX4Eez6o&list=PL6gx4Cwl9DGBzfXLWLSYVy8EbTdpGbUIG
Here's the thing, though: if you have a modern JDK, JavaFX is not automatically included. You'll need to download the SDK from Gluon: https://gluonhq.com/products/javafx/
And be sure to include it in the build path of your project. This step is going to depend on your IDE. I'm guessing you use either IntelliJ IDEA or Eclipse, so I'll provide some documentation for each:
https://www.jetbrains.com/help/idea/javafx.html (NB: I use Eclipse, so I can't verify these instructions, but they seem logical enough)
I can provide some basic Eclipse instructions. I'm assuming that you're using a 2021 version of Eclipse. I'm on 2021-03:
The easiest approach is to get the e(fx)clipse plugin from the marketplace (Help -> Eclipse Marketplace), download e(fx)clipse, restart Eclipse, and then use ctrl + n to create a new project.
Choose JavaFX -> JavaFX project.
When you get to the Java Build Settings, click on "Libraries" and add a new User Library. Select the jars in the lib subdirectory of the JavaFX SDK that you downloaded.
You can now create a new JavaFX class -- Eclipse will take care of the start() method and the Application import for you. Eclipse will also include the SDK jars in the VM automatically most of the time.
This video seems to walk through the process: https://www.youtube.com/watch?v=bk28ytggz7E
I honestly really like building things with JavaFX (and I tend not to be a huge UI person). I used to make simple desktop apps to automate some of my data with Python/tkinter, which was torture compared to JavaFX.
Unlike the naysayers here, I think desktop apps still have something of a future (certainly with web app counterparts -- think Microsoft Office which exists both on o365 and on your desktop). Enjoy making a nice GUI!
If you want to get a little fancier, use SceneBuilder and make sure it connects to the FXML in your project.
1
u/your_mom_lied May 27 '21
Java FX is the best choice in my opinion. Layouts with xml and styling with css. It’s a good choice if you understand web layouts.
1
May 28 '21
Like a lot of people said, building a java desktop application is probably not good for making your own money. However, its great for resume projects! I worked on a Java desktop application for the past year, but I ditched it because I've decided to switch to Javascript. If developing apps is something you enjoy (I enjoy it a lot!) then its totally worth trying out! If its for career reasons, not worth sweating over.
As with having to start, I suggest learning the basic principles of java (i like w3schools), start building small apps and learn along the way! (Swing is the easiest UI to work with IMO, although its outdated)
1
u/ldlama May 28 '21
You can find lots of tutorial for the development of java desktop application. You can use Java Swing or JavaFx according to your preference. You can start first learning java then java swing or javafx for development.
1
u/MrMain007 May 28 '21
I have used java fx , it's a pretty good framework to build desktop application. Java fx combined with scenebuilder application which is a drag and drop framework for ui and with the help of css you can build any modern app. It was good to learn Java fx and it was a pretty data intensive application too. But I preferred using electron js and making RPC calls to the java application running on a local server. Using that you can use react or angular to build ui and electron will package it as a desktop application and you can use it as a web app as well. So less code duplication if making webapp and desktop app.
1
u/johnmc325 May 28 '21
Take a look at my website where I have several blogs and videos that cover SWING and JavaFX, although mainly JavaFX these days. These are generally step-by-step instructions for building simple get-you-started GUI applications. Hopefully something there will give you enough to get you started or at least move you forward. Hope it helps and if you have any questions based on what you see feel free to ask. https://softwarepulse.co.uk/.
30
u/stramash May 27 '21
Is this for professional reasons?
The reason I ask is because desktop apps are incredibly rare nowadays, I’d only bother learning if it’s paying the bills.
Check out Swing though, if you must.