5 ms·
I don't know Java gets such a bad rap from the current generation. If I had my way (which I rarely do) I'd start any new server-side project on Java with Spring
by tootie 9y ago
I don't know Java gets such a bad rap from the current generation. If I had my way (which I rarely do) I'd start any new server-side project on Java with Spring Boot. Everything about the stack is so fine-tuned and battle-tested. There's libs for everything under the sun. I can follow every stack trace even in a multi-threaded environment. Debuggers are extremely dependable. The IDEs are top notch. I know it's verbose and I prefer it that way. You spend more time reading code than writing and I'd rather see it all spelled out than encoded in punctuation marks. Otherwise, I'd go back to Perl.
- striking 9y agoIs there a tutorial one could follow to try this out? You've got me interested but I don't know where to go next.
- fma 9y agoSpring Boot project has an intro project right on their homepage. https://projects.spring.io/spring-boot/ https://projects.spring.io/spring-boot/ You can get a running webapp within minutes. The caution is, you would have limited information on what's going on in the background. Great for those who already know Spring and its inner workings because it's convenient - but could be detrimental on a beginner if you don't take the effort later to learn the inner workings.
- striking 9y agoThis is super helpful. Shows an example of the framework right up front, and has detailed explanations linked. Thanks.
- happy-go-lucky 9y agoJava Programming Basics: https://www.udacity.com/course/java-programming-basics--ud282 https://www.udacity.com/course/java-programming-basics--ud28...
- arethuza 9y agoI was very enthusiastic about Java from 1995 to about 2000 or so - then it seemed to become dominated by an "enterprise" outlook and rampant over-abstractionism. Java is permanently associated in my mind with hammer factories: http://discuss.joelonsoftware.com/default.asp?joel.3.219431.12 http://discuss.joelonsoftware.com/default.asp?joel.3.219431....
- djhworld 9y agoI used to work on this treadmill, it sucked I agree. Nowadays I still write Java, but it's much more pleasant, all deployed to the cloud, no messing around with application containers and all the Java EE stuff. It's nice, it works, it's simple. Granted, I'm fortunate enough to not have to maintain legacy Java applications so my perspective has been skewed somewhat, but I think it's worth mentioning that "modern Java" has moved a long way from what it used to be.
- thehardsphere 9y agoSee, you got off the train at peak abstraction crazy. I don't blame you for the association given what you saw then, but there's no reason that you have to write Java that way, and most people don't anymore.
- sk5t 9y agoJust forget that EJB, Websphere, Weblogic, JTA, CORBA, and a few other things ever existed, and having a positive feeling about Java should cause little cognitive dissonance.
- thehardsphere 9y agoI was too young to see the EJB fad and when people made all of these decisions to use things like WebSphere. Did they make any sense in their own time? Today they seem remarkably silly. Especially WebSphere, which is so horribly slow and broken I don't understand why anyone would have chosen to use it besides "nobody got fired for choosing IBM."
- 9y ago
- thehardsphere 9y agoI don't think I'd start "any" server-side project with Java; I think it's a question of whether you really want the JVM or not. The JVM is awesome but smaller projects might find it too heavy for their use/deployment case. But yeah, Java is great. Definitely seems underrated in the popularity department.
- djhworld 9y agoA lighter weight alternative to Spring Boot for small projects is Spark Java. http://sparkjava.com/ http://sparkjava.com/ It just works, if a little unfortunately named, but you can get a nice little application up and running quite quickly.
- vthallam 9y agoIt looks cool. But I don't see any information about database connectivity or ORM. can you like use JPA or Hibernate along with Spark?
- thehardsphere 9y agoOh, that looks nice, but I was speaking less about the language and more about the JVM itself. I mean, if you're in that small scale range where you're running project off of a small server or VPS that may not have that much RAM to play with, the JVM I think starts to make less sense. You don't need the super-scaling performance of the JVM because you won’t have the load, and the RAM that would be spent on the JVM heap is better spent in that case on other things (e.g. database caching, if you are so small and cheap that your DB runs on the same machine as the http/app server).
- slackingoff2017 9y agoJava using a large amount of ram is a myth. Let me explain the difference between JVM and other GC'ed languages that makes this appear to be the case. So almost all "web" languages use garbage collection. This reason Java appears to use more ram is, paradoxically because it has a better garbage collector. The best time to do garbage collection is never. Even if you do it concurrently it uses CPU time. Java is very good about avoiding collecting garbage until the heap is huge. Other languages (by default) use less ram because they run garbage collection a lot more often. So why do they run GC so much more other than Java? Because their garbage collectors are slower and not as concurrent. Almost all garbage collectors pause execution and even the ones that don't still affect performance. You don't want pauses more than some tens of milliseconds really ever. Garbage collection time depends on how much garbage you have, so languages with inferior collectors need to keep the heap small to avoid long collection times. Since Java's GC is so fast the heap can be allowed to build to many gigabytes before garbage collection times are an issue. Turning down the heap size will make Java GC more often and behave more like other languages. Compared to dynamic languages Java itself is very memory efficient. It's just the longer GC interval that makes this appear otherwise.
- org3432 9y agoIt's all the magic and the cost to run it which is why I think languages like golang are gaining popularity.
- deleted 9y ago[deleted]
- LanceH 9y agoI'm working with both right now getting some API's up and running. Even if Java has moved away from the crazy levels of abstraction years ago, golang is still years ahead. In my brief recent return to Java, it still doesn't seem to reach out to the programmer to make the common case easy.
- pjmlp 9y ago> golang is still years ahead. You mean like using go generate instead of proper generics?
- cholantesh 9y ago>The IDEs are top notch IDEA is phenomenal. Netbeans is just OK, and Eclipse was awful all the times I tried it. Bloated UI, slow startup, and difficult to configure. Maybe things have changed since I've used it, but at the time, it was agonizing.
- nradov 9y agoThe current version of Eclipse is quite fast even when dealing with large code bases. Configuration is easy; there are a zillion options under preferences but the search filter makes it easy to find what you need. Startup times are irrelevant. Start the IDE once when you boot the OS and leave it running. It consumes minimal system resources just sitting there until you need it.
- ganonm 9y ago100% agree. I don't buy the verbosity argument one bit. Yes it's more verbose than a dynamically typed language but it's not like you get nothing in return for that verbosity. When working with serious, mission-critical code, the verbosity (and accompanying clarity) is a godsend. The only part of writing/maintaining code that I've found easier/more pleasant with dynamically typed languages is writing unit tests (due to the fact that mocking an object is as simple as just declaring a hash literal or JSON object). On the other hand, I find that I need to write extra unit tests to verify integrity that would be be verified at compile time in a strongly typed language like Java. I would strongly recommend people check out DropWizard. It's an opinionated framework for writing Java servers that comes with a handpicked stack. It has many of the convention driven advantages of e.g. Rails but fundamentally you're still writing code in Java (or another JVM language like Kotlin).
- ryandvm 9y ago> I find that I need to write extra unit tests to verify integrity that would be be verified at compile time in a strongly typed language like Java. This is so true and I'm surprised I don't see it mentioned more often. Sure, mocking stuff is way easier in JavaScript, but you end up writing tons of tests to prevent the kind of regressions a smart IDE would be screaming about in a strongly typed language.
- bradleyjg 9y agoI'd go further and say the techniques that trade-off clarity for making unit tests easier to write (e.g. dependency injection) are often a bad idea. We shouldn't let the tail wag the dog.
- pvg 9y agoFor beginners (who this micro-guide is aimed at), a big part of it is that the activation energy is pretty high - there are lots of things to know and there are many ways to do things. Finding recent and accurate information is harder - there's 20-odd years worth of it out there. Even in this write-up, there's some questionable advice - the beginner answer to 'writing a clientside UI in Java' is 'don't use Java'. This is normal for any mature, widely used technology - Rails comes to mind as a smaller variant of the same problem. It's a lot easier to try out go or node - there's less stuff.
- slackingoff2017 9y agoI've used maybe a dozen languages over the years and Java is my favorite for all the reasons you mentioned plus performance. Im convinced that most of the people who dislike Java are either riding the hype train or inexperienced with the pitfalls of various languages. The whole startup culture is biased against Java which is ironic because many tech titans use it as their main language.
- nailer 9y agoJava's design is far from the Antoine De Saint Exupery definition of perfect: https://www.brainyquote.com/quotes/quotes/a/antoinedes121910.html https://www.brainyquote.com/quotes/quotes/a/antoinedes121910...: For example: https://www.zeroequalsfalse.press/2017/06/22/java/output.png https://www.zeroequalsfalse.press/2017/06/22/java/output.png - The author and date are redundant, these are typically stored in source control - The program itself should already be a class, specifying a containing class and function shouldn't be necessary. - Public (or private) should be default. - Make returning void a default, and stop asking developers to unnecessarily define it. - 'System' is a vague word with many possibilities. It can man: OS kernel, services, OS, VM, stdlib, and many others. The entire example except 'print("hello")' is wasted tokens and noise.
- currysausage 9y agoThe example also shows how ridiculous many syntax highlighting schemes are. So much emphasis is put on boilerplate; the identifiers (which I'm usually looking for in code) almost fade into background.
- nradov 9y agoThere is no requirement to include comments with the author and date. Package private is a reasonable choice for the default access modifier. Changing the default to be public or private wouldn't improve the language.
- nailer 9y ago> There is no requirement to include comments with the author and date. Ack, but it's a strange culture that does so. So you can omit 'public' or 'private' as keywords and the function / method will be package-private?
- nradov 9y agoYes that's clearly stated in the Java Language Specification.
- GlennS 9y agoPersonally, I quite like Java. Or, I'd put it somewhere in the category of 'good/proper languages'. Although I view C# as a straightforward upgrade. But hey, it's pretty often I have to work in PHP or R or JavaScript. A few months of that and I'll beg for a chance to work in Java with its sensible collections, its mostly-not-broken type system, and its integers. However, I do think a lot of the library ecosystem that goes with Java it pretty poor, and I don't think I could ever work with Spring again. This gist of Java frameworks for me is that they miss the essential problems and important uses and instead construct a massive tower of nonsense around the trivialities. (I am, however, quite happy with Guava and Joda Time, and if I thought that dependency injection frameworks were useful then Guice is certainly superior to Spring.) So here's my anecdote illustrating the dark side of Java. Once upon a time, I needed to parse a CSV with a header row. The project I was working in used Spring, so I decided to try the Spring library. Configuring it to fetch the bean, put it in the right place, and set the header row switch to true took slightly more lines of XML than the lines of code you'd need to write a CSV parser from scratch, but hey at least I didn't need to think about quoting. After a year or so, we are updating to a newer version of Spring. They have removed the header-row switch from their CSV parser, and replaced it with some sort of general parser extension abstraction. To parse a CSV with a header, I now have to write a class implementing their parser interface, register it with Spring, then write another 10 lines or so of hideous XML to slot it into the right place. Just...what the hell? Bean Validation can piss off too.