r/java • u/AgilNaoEhTI • May 07 '24
Are you still using JSF for frontend?
I’m curious about what you guys use as tech stack for creating frontends. Java offers alternatives such as JSF but it has a lot of problems (ex: http session) so I was thinking if is something better in the Java world or if you use another tech, based on javascript, for example. I also see a lot of java courses that cover JSF, but I question if this subject is still relevant or might be misleading for begginers.
15
Upvotes
View all comments
Show parent comment
5
u/davidalayachew May 09 '24 edited May 10 '24
JavaFX was definitely advertised to be the big new thing. In reality, I would say that it ended up being a really good complement to Java Swing.
Here are MY pros and cons, in MY opinion.
PROS
It's old!
It has THOUSANDS of libraries from loyal fans working on it for DECADES.
It's EXTREMELY customizable, but also EXTREMELY easy to customize!
If you don't like the default behaviour, just type
extends, and then modify!It has great performance...as long as you don't break the rules.
Scales BEAUTIFULLY with no effort from you!
JListwith the default options. Loaded INSTANTLY on a very weak laptop. And these were not small elements either, they had text, images, and interactive elements.It can interact with JavaFX!
CONS
If you need heavy duty performance, you have to do it the Swing way, or your performance will suffer.
The Java team optimized Swing so much. It flies like an eagle as long as you follow the rules. But if you ever need to break the contracts, Swing slows to a crawl when under load.
JButton- TheJButtonis a classic example of a super-customizable class that gets its customizability at the expense of performance. And to be clear,JButtonis REALLY fast. But it scales exponentially. So, if you try and make a game like Minesweeper using an instance ofJButtonfor each cell, you will notice significant lag and frame drops on really big boards (100x100).Generics are not always a first class citizen in Swing.
Java Swing was made BEFORE Java got generics. And because of the way some components were originally designed, they CANNOT be FULLY reworked to use generics, because that would not be backwards compatible.
It's old.
Swing made a couple of guesses on how the world would work back in 1999. A lot of those guesses hold up really well today. A handful of them REALLY DO NOT.
JTable-- 99% of the time, when you are working with a table, you are thinking in terms of rows. So, if you have a table ofUser, who hasname,age, andheight, then 1 row represents 1 user, column 1 representsname, column 2 isage, and column 3 isheight. Lol, well,JTableworks in columns LOL. So, row 1 is age, and so on. Either you have to think in columns instead, or you need to makeJTablethink in rows, and it's not that easy to do. Now I want to emphasize -- this was not that bad a guess to make back in the day. Most computer screens were 4:3 ratio, so the idea of thinking in rows was not much different than thinking in columns. But we live in a 16:9 world now lol. And that's ignoring our super-wide monitor friends lol. So, this idea does not hold up well AT ALL. HOWEVER, this problem has been thoroughly mitigated by the community. I would like to give a shout out to the almighty, illustrious, uncontested champion of Java Swing -- Rob Camick (also known as camickr on StackOverflow). He has an excellent solution -- RowTableModel -- https://tips4java.wordpress.com/2008/11/21/row-table-model/ -- that eliminates this problem entirely, and it uses generics too! Just....don't try and understand how he did it lol. It's not THAT complex, but it uses a healthy dose of reflection, and that is usually what it takes to undo some of the Swing conventions that were baked in to the contract.New features are rare.
Multithreading and GPU is WAY harder than it needs to be.
PROS
Performance is one of the highest priorities!
Properties are POWERFUL!
Built with Modern Java in mind!
Supports styling with CSS!
They are adding new features regularly!
3D Support!
It can interact with Swing!
CONS
If you need heavy duty customization, you have to do it the JavaFX way...period.
extendsand then be on my way.Whereas JavaFX is far more opinionated, and doesn't really give you that option very often.
finalin JavaFX. It's actually surprising how many. Take a look yourself lol. https://openjfx.io/javadoc/22/javafx.controls/javafx/scene/control/TableView.htmlBuilding your own components in JavaFX is shockingly difficult.