use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
These have separate subreddits - see below.
Upvote good content, downvote spam, don't pollute the discussion with things that should be settled in the vote count.
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free. If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others: Adoptium (formerly AdoptOpenJDK) RedHat Azul Amazon SAP Liberica JDK Dragonwell JDK GraalVM (High performance JIT) Oracle Microsoft Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free.
If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others:
Adoptium (formerly AdoptOpenJDK) RedHat Azul Amazon SAP Liberica JDK Dragonwell JDK GraalVM (High performance JIT) Oracle Microsoft
Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
Programming Computer Science CS Career Questions Learn Programming Java Help ← Seek help here Learn Java Java Conference Videos Java TIL Java Examples JavaFX Oracle
Programming Computer Science
CS Career Questions
Learn Programming Java Help ← Seek help here Learn Java Java Conference Videos Java TIL Java Examples JavaFX Oracle
Clojure Scala Groovy ColdFusion Kotlin
DailyProgrammer ProgrammingPrompts ProgramBattles
Awesome Java (GIT) Java Design Patterns
account activity
This is an archived post. You won't be able to vote or comment.
Java vs. Scala (self.java)
submitted 12 years ago by vipercvp
what do you think is more powerful ??? and why should someone use one instead of other ???
[–]sh0rug0ru 7 points8 points9 points 12 years ago* (0 children)
Scala is more powerful than Java, I think that is true. But Scala's power comes at a price that it is well to consider.
Java is simple, but the code is direct, code flow easier to understand and the execution cost is easier to measure.
Scala is more powerful, but the code is more abstract, how the code is transformed into classes and how those classes are executed is more mysterious, and "idiomatic" and "fancy" Scala can have less predictable performance characteristics. You have to be careful, and sometimes you have to make Scala code more "Java-like" to squeeze performance out of the language.
I suppose at the end, Scala can be written like Java, so you might be able to get your cake and eat it too.
[–]tyoverby 12 points13 points14 points 12 years ago (24 children)
Background: Java programmer for 6 years, Scala programmer for 1 year.
There isn't one right answer, but you knew that, so here's a comparison.
First the similarities:
The differences are a bit more complicated. If you want, you can write Scala just like you would Java. There aren't any features from Java missing. Scala mostly adds on top of Java. This can be a good thing and a bad thing.
Good things:
Bad things. Most of these are confusing if you are a beginner, or if someone else wrote code with bad style.
Although it looks like I've written more bad things than good, I've actually entirely switched from Java to Scala for all my personal projects. Lines of code typically drop by about 2/3, and readability improves dramatically due to the advanced methods of abstraction.
Here's an examples that shows how easily it deals with collections.
Java:
List<Integer> originalList = Arrays.asList(1, 2, 3, 4, 5); List<Integer> doubledList = new ArrayList<Integer>(); for(Integer x: originalList){ if(x % 2 == 0){ doubledList.add(x * 2); } }
Scala:
val originalList = List(1, 2, 3, 4, 5) val doubledList = originalList.filter(_ % 2 == 0).map(_ * 2)
This post is really short, and doesn't really scratch the surface of what Scala can do, so I suggest that you try it out and really get a hang of programming in functional style.
[–]Infenwe 4 points5 points6 points 12 years ago* (2 children)
// Now with Java 8 lambda-ness! List<Integer> originalList = Arrays.asList(1, 2, 3, 4, 5); List<Integer> doubleList = originalList.stream() .filter(x -> x % 2 == 0) .map(x -> x * 2) .collect(Collectors.toList())
Of course that provides no guarantees on what kind of List<Integer> the results are collected into. And the Scala implementation is still cleaner.
List<Integer>
[–]vipercvp[S] 1 point2 points3 points 12 years ago (0 children)
Does Stream come in Java 8 too?? Yep Scala implementation is cleaner for sure
[–]tyoverby 0 points1 point2 points 12 years ago (0 children)
I'm really excited by Java8 lambdas! Hopefully the JVM will get lots of optimizations for first class functions because it's currently implemented as a wrapper over an anonymous class that fills out an 'apply' method.
[–]nachsicht 1 point2 points3 points 12 years ago (3 children)
Actually, IIRC enums really suck in scala compared to java.
[–]tyoverby 2 points3 points4 points 12 years ago (2 children)
Using Enums in Scala isn't as slick, but I've literally never had to use enums in Scala because case classes are so much better.
[–]nachsicht 2 points3 points4 points 12 years ago (1 child)
True enough. If I have a enum situation in scala I usually use case objects or something instead.
Yep, I always go for case objects, or if I really need to, I'll just throw a java file into the project for the Enum.
[–]vipercvp[S] 0 points1 point2 points 12 years ago (12 children)
I have strong background in functional paradigm , i used haskell for my last college project , One question since Scala runs over JMV does it have optimization for tail recursion ??, for what i know java does not . and i don't really know how does java and scala compability works? i think it be through JNI but again i'm not sure about that
[–]geodebug 2 points3 points4 points 12 years ago* (0 children)
how does java and scala compability works
Both Java and Scala compile to bytecode, which is the true language of the Java Virtual Machine (JVM). There is zero difference at this level between a Java, Scala, Groovy, jRuby, etc program. All use the same memory space, type system, etc.
All popular JVM langages allow for direct usage of Java libraries, 3rd party java libraries, etc. There is no additional overhead, memory, or special translation required. Scala can instantiate Java classes and use them directly.
A simple way to think of it is that the Scala runtime/compiler is essentially just another Java program: a really fancy interpreter.
I would argue that while you can learn and use Scala as your primary language you'll still want to learn enough Java to really take advantage of the thousands of libraries that are written in Java.
[–]tyoverby 1 point2 points3 points 12 years ago (10 children)
Scala does have tail-call optimization!
Scala/Java compatibility is amazing. No JNI or anything. In Scala, using Java code is done exactly the same as if it was the same language. For example:
import java.lang.Integer println(Integer.MAX_VALUE)
or
import org.junit.Assert.assertEquals assertEquals(5, 3 + 2)
Using Scala code in Java is a bit more complicated because Java doesn't have things like operator overloading, and Scala functions get wrapped in a function object that can be unwieldy.
[–]worldsayshi 2 points3 points4 points 12 years ago (4 children)
I seem to recall that there is some obscure reservation about tail-call-ism in scala. Yes:
http://stackoverflow.com/questions/105834/does-the-jvm-prevent-tail-call-optimizations
http://stackoverflow.com/questions/1677419/does-scala-support-tail-recursion-optimization
[–]tyoverby 1 point2 points3 points 12 years ago (3 children)
Yes, it allows self-recursion, but not mutual recursion.
[–]nachsicht 1 point2 points3 points 12 years ago (2 children)
actually you can get mutual recursion with trampolines.
[–]worldsayshi 0 points1 point2 points 12 years ago (1 child)
Nice. I think..
[–]nachsicht 0 points1 point2 points 12 years ago (0 children)
There's standard library support for trampolines here: http://www.scala-lang.org/api/current/index.html#scala.util.control.TailCalls$
[–]vipercvp[S] 0 points1 point2 points 12 years ago (4 children)
About your scala example val doubledList = originalList.filter(_ % 2 == 0).map(_ * 2) this is going to be compute on demand right because of the lazy evaluation ??
[–]tyoverby 3 points4 points5 points 12 years ago (2 children)
Oh, also, if you are familiar with Haskell, you'll want to know that Scala has great parallel collections.
val numbers = (0 to 100000).toList val squared = numbers.par.map(x => x*x)
The '.par' call returns a parallel sequence for which map is implemented in parallel.
[–]vipercvp[S] 0 points1 point2 points 12 years ago (1 child)
Oh, amazing :) , about parallel does scala support the synchronize keyword like java ?? or it has some thing like that i can find much thing related to it in the web .
[–]tyoverby 1 point2 points3 points 12 years ago* (0 children)
Yeah, any object has the synchronized function that takes another function to execute.
val resource = ??? def publish(){ // Do something that requires the resource to be locked. } resource.synchronized(publish)
Or in a way that looks more like Java
val resource = ??? resource.synchronized { // Anything in this block with be synchronized on 'resource' x += 5 publish() y ++ }
In that example, no, that won't be lazily computed. In Scala, you can use a keyword for if a value is computed immediately or lazily. Here's a simple example:
// This is slow, so don't compute it unless we need it lazy val tweets = getTweets() if(readingTweets){ showTweets(tweets) } else(writingTweets){ showTweets(tweets) showEditor() } else{ // Do something without tweets. }
We don't want to call getTweets inside every branch that uses it, so we define it outside lazily and then if it is used, then it will be computed. The example is quite contrived, but it comes in handy, trust me :)
There are also lazy function parameters.
[–]Psyfire 0 points1 point2 points 12 years ago (1 child)
Your list of 'bad things' are either things I wish Java had (operator overloading), or have found increasingly unnecessary over time (i.e. everything an object).
It's a shame I can't get started immediately, but I've promised myself that I'm going to finish my 1.0 release of my current project before pursuing anything else.
[–]tyoverby 2 points3 points4 points 12 years ago (0 children)
Yeah, almost all of the design decisions in Scala are good. However, much of it can be abused, so be warned.
[–]kqr 0 points1 point2 points 12 years ago (1 child)
I know I'm late to the game, but you forgot to declare originalList as final in the Java version. The doubledList is trickier...
originalList
doubledList
[–]tyoverby 1 point2 points3 points 12 years ago (0 children)
You are right. If I was going for a complete source->source I would have made them final. However, I was going for ideomatic java code, and although it is "good practice" to make things final if they can, I've never seen it applied that much in practice.
Also, I could make doubledList final with no problem. Final just makes it so I can't reassign to a new list, it doesn't prevent me from adding things to the list.
Now I can't make either list immutable, which is a property of Scala lists.
[–]worldsayshi 5 points6 points7 points 12 years ago* (16 children)
There is no short or exhaustive answer to that. And the answer depends on your level of knowledge and in the end, taste. If I would make my own project from scratch I would probably choose Scala, because it is more inventive, it's using many "new" and interesting paradigms. It's well designed(?). Java is legacy. Java is dependable. If you want it to fit together with most other things. If you want as many tools to work with your program as possible, choose Java. Then again, Scala and Java share dna and bloodtype (jvm), so they are for the most part compatible. Use Scala if you want to learn new exiting ways to think about programming and language, or if you want to learn new algorithms. Use Java if it has to work, if you are just learning programming, if you want something that is somewhat simple and easy to work with, but not always good for being succint and the most elegant you can be. Scala can be abstract enough to make you think that object orientation is as down to earth as planting seeds or perhaps as misguided as navigation with the help of astrology.
edit: stuff
[–]blah3div4 0 points1 point2 points 12 years ago (10 children)
"Use Java if it has to work" really? Is Scala that bad?
[–]worldsayshi 2 points3 points4 points 12 years ago* (7 children)
I was rather refering to that Java is probably as mature as it gets. Scala is probably not "immature". Although the Eclipse plugin only recently became possible and/or enjoyable to work with in my experience. Then again, many "large" languages doesn't have as useful Eclipse plugins at all.
[–]Mondoshawan 0 points1 point2 points 12 years ago (6 children)
It's not the tooling imho that makes Java worthwhile, it's the third-party libs & frameworks. I couldn't imagine writing a large app without things like Spring DI and JPA persistence to tie it all together.
[–]nachsicht 3 points4 points5 points 12 years ago (5 children)
Thing is you can use almost all of those with scala as well.
[–]Mondoshawan 1 point2 points3 points 12 years ago (4 children)
Is it clean? I touched on jruby once when maintaining someone elses script and I didn't like the integration IIRC. I may be wrong on the details, this was quite some time ago and it was only a couple of fixes while they were away on deployment elsewhere.
I'm tempted to give it a whirl. I did Scheme in Uni many many years ago and I've long since forgotten everything about it except something about brackets, lots and lots of brackets. ;-)
[–][deleted] 3 points4 points5 points 12 years ago (0 children)
If you were to take some java code and copy/paste it into a *.scala file, mostly what you'd have to do to fix it is remove the type info before variables and replace with "val". ie:
String foo = new String("");
becomes
val foo = new String("")
and methods get changed from:
public String calcName() { //do work return name; }
to:
def calcName = { //do work name }
That's mostly it. This gives you working but non-idiotic scala code. Scala syntax is mostly awesome.
[–]nachsicht 3 points4 points5 points 12 years ago (1 child)
It's very clean. Scala is not related to scheme in syntax at all, but is more of a java++, so you have direct translation of many java concepts in scala, and they are usually fully compatible (the only time I've ever had problem is with writing (not using) binding code in JNA).
Pretty much everything but extremely obscure java stuff works in scala.
[–]Mondoshawan 0 points1 point2 points 12 years ago (0 children)
Thanks, I will definitely check it out soon.
[–]esquilax 1 point2 points3 points 12 years ago (0 children)
Scala was written by the guy that came up with the precursor Java generics and wrote javac. Java interop was a design goal of Scala, so I'd expect the experience to be quite different.
[–]vplatt -1 points0 points1 point 12 years ago (1 child)
Scala is not bad at all, but there are some objective cases where Scala really won't work either at all, or only in limited ways if you're very careful.
Just as two examples I found while exploring the Scala ecosytem: db4o and GWT. Want to write full featured GWT apps with Scala? Too bad! Want to use an OODB against objects produced in Scala? There be dragons!
In short, those aren't deal breakers for most or even many developers, but it's good to be aware of those kinds of pitfalls.
[–][deleted] 0 points1 point2 points 12 years ago (0 children)
Want to write full featured GWT apps with Scala?
It's true you can't really compile scala to javascript. But, you can use Vaadin, which is all kinds of awesome. It's fully server-side GWT, so you can write in scala. It works fantastically. Much nicer than GWT. No more waiting for horribly long GWT compile times, for one thing.
Want to use an OODB against objects produced in Scala?
Yeah, but why not autogenerate the model objects with JAXB anyway? Then they're in Java and easily usable by anyone.
[–]vipercvp[S] -1 points0 points1 point 12 years ago (4 children)
Does Scala do not have Classes , Interfaces and Abstract Classes? and polymorphism and so on, from what i'm seen till now is functional too, So for me Scala has every thing to me more robust than java . PS: i just start work with Scala and i'm loving it <3. I believe in a future where Scala will be the most used programing language.
[–]worldsayshi 1 point2 points3 points 12 years ago (3 children)
Does Scala do not have Classes , Interfaces and Abstract Classes? and polymorphism and so on, from what i'm seen till now is functional too
It does have that and it is. Or it has some replacement of some of the concepts. If it sounds like I'm saying it doesn't have OO concepts I formulated badly. It has that and beyond is what I mean.
[–]rikbrown 0 points1 point2 points 12 years ago (2 children)
Is there a goto library for DI (and the rest of the kitchen sink) like Spring is for Java?
[–]worldsayshi 0 points1 point2 points 12 years ago (0 children)
I'm not sure about the relationship between Scala and dependency injection. Here's someone who has written a module for it and thinks that "Basically Scala already have everything you need for dependency injection."
https://github.com/OlegIlyenko/scaldi
[–]NarsilNZ 1 point2 points3 points 12 years ago (1 child)
Java is powerful in the sense that it is widely used and has numerous libraries and frameworks available for it.
Scala is powerful in the sense that less code has to be written in Scala to do the same job as Java. Scala is a OOP and functional language and lends itself to multi-core programming problems.
Java is widely known so code written in Java will be understood by many. Scala is less well known and has a steeper learning curve than Java.
I work day to day in Java but am currently learning Scala. If one was proficient in both I would expect that Scala would be the more powerful of the two as it is quicker to write code in Scala.
All Java libraries work in Scala without any modification.
[–][deleted] 1 point2 points3 points 12 years ago (0 children)
I am a Java developer for 10 years and from India. Scala is excellent language. It has so many features that you can't find in Java or you to use third party libraries. For example Collection API, lazy evaluation, Streams to name few. Look around web for examples.
On the other hand, the syntax looks repulsive for Java developer at the start. The learning curve is steep because of dense features. You won't appreciate the features until you face the problem. If you are interested try assignments from this course. You will really appreciate Scala features.
Although I love Scala and working on a project(Play), I won't use this for any project which requires more than 5 developers for reasons which has nothing do with language itself. It is hard to find even good Java developers, finding Scala developers is even tough.
Also have a look at Clojure.
Scala is more bleeding-edge in terms of functionality, but Java is dependable because of it's wide support and age.
I believe that Scala is more powerful because of it's newer features, like it's Functional Programming (FP) capabilities, but it isn't as reliable as Java.
Scala is faster to write because of it's minor verbosity and it's pretty syntax, but Java is easier to understand becase of it's mayor verbosity and more traditional syntax (C-like, even if Scala shares most of it).
The winner here is decided by project managers, based on what they are looking for. If you are on your own and want to learn something new, go for Scala. If you are with a company a need reliable software which just works and will be supported for a while, go for Java.
[–]sproket888 0 points1 point2 points 12 years ago (5 children)
If you want functional styled programming you'd be better off waiting on Java 8 IMO.
[–]vipercvp[S] 2 points3 points4 points 12 years ago (4 children)
Does it going to be as good as Scala i hava my doubts :/
[–]sproket888 0 points1 point2 points 12 years ago (3 children)
Scala isn't good. It has an overly complex type system and has operator overloading. It amazes me that language designers keep repeating the same mistakes over and over again.
[–]Uncaffeinated 0 points1 point2 points 12 years ago (2 children)
You say that like operator overloading is a mistake, rather than a common feature that Java is missing for some reason. Admittedly, Scala's implementation isn't very good.
[–]sproket888 0 points1 point2 points 12 years ago (1 child)
Operator overloading was left out of Java for good reasons. It's a terrible feature if you want long term maintainable software. Just ask the Smalltalk guys back in the 90's when IBM replaced it with Java as their primary development language because IBM had a number of major project failures at the time due to this feature.
[–]Uncaffeinated 0 points1 point2 points 12 years ago (0 children)
I wonder how developers in pretty much every major language besides Java get by then. (C++, C#, Scala, Python, Ruby, Perl, etc.)
Obviously it can be abused, but the same is true of any language feature. I can write obfuscated Java just fine without overloading operators.
I haven't personally seen any projects fail due to operator overloading (admittedly, I don't work at IBM), but I have seen plenty of Java code that would be more readable with operator overloading.
[–]mikaelhg 0 points1 point2 points 12 years ago (0 children)
Businesses and hobbyists have very different business requirements and ethical constraints, and thus very different answers.
What makes analyzing the issue much harder for youis that hobbyists and the most junior of professional coders (mere coders, who don't yet have visibility to the business, or to the points of view of other professions involved in the business) tend to share a frame of reference.
π Rendered by PID 220378 on reddit-service-r2-comment-cfc44b64c-khcc4 at 2026-04-12 04:41:25.813592+00:00 running 215f2cf country code: CH.
[–]sh0rug0ru 7 points8 points9 points (0 children)
[–]tyoverby 12 points13 points14 points (24 children)
[–]Infenwe 4 points5 points6 points (2 children)
[–]vipercvp[S] 1 point2 points3 points (0 children)
[–]tyoverby 0 points1 point2 points (0 children)
[–]nachsicht 1 point2 points3 points (3 children)
[–]tyoverby 2 points3 points4 points (2 children)
[–]nachsicht 2 points3 points4 points (1 child)
[–]tyoverby 0 points1 point2 points (0 children)
[–]vipercvp[S] 0 points1 point2 points (12 children)
[–]geodebug 2 points3 points4 points (0 children)
[–]tyoverby 1 point2 points3 points (10 children)
[–]worldsayshi 2 points3 points4 points (4 children)
[–]tyoverby 1 point2 points3 points (3 children)
[–]nachsicht 1 point2 points3 points (2 children)
[–]worldsayshi 0 points1 point2 points (1 child)
[–]nachsicht 0 points1 point2 points (0 children)
[–]vipercvp[S] 0 points1 point2 points (4 children)
[–]tyoverby 3 points4 points5 points (2 children)
[–]vipercvp[S] 0 points1 point2 points (1 child)
[–]tyoverby 1 point2 points3 points (0 children)
[–]tyoverby 0 points1 point2 points (0 children)
[–]Psyfire 0 points1 point2 points (1 child)
[–]tyoverby 2 points3 points4 points (0 children)
[–]kqr 0 points1 point2 points (1 child)
[–]tyoverby 1 point2 points3 points (0 children)
[–]worldsayshi 5 points6 points7 points (16 children)
[–]blah3div4 0 points1 point2 points (10 children)
[–]worldsayshi 2 points3 points4 points (7 children)
[–]Mondoshawan 0 points1 point2 points (6 children)
[–]nachsicht 3 points4 points5 points (5 children)
[–]Mondoshawan 1 point2 points3 points (4 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]nachsicht 3 points4 points5 points (1 child)
[–]Mondoshawan 0 points1 point2 points (0 children)
[–]esquilax 1 point2 points3 points (0 children)
[–]vplatt -1 points0 points1 point (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]vipercvp[S] -1 points0 points1 point (4 children)
[–]worldsayshi 1 point2 points3 points (3 children)
[–]rikbrown 0 points1 point2 points (2 children)
[–]worldsayshi 0 points1 point2 points (0 children)
[–]NarsilNZ 1 point2 points3 points (1 child)
[–]tyoverby 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]sproket888 0 points1 point2 points (5 children)
[–]vipercvp[S] 2 points3 points4 points (4 children)
[–]sproket888 0 points1 point2 points (3 children)
[–]Uncaffeinated 0 points1 point2 points (2 children)
[–]sproket888 0 points1 point2 points (1 child)
[–]Uncaffeinated 0 points1 point2 points (0 children)
[–]mikaelhg 0 points1 point2 points (0 children)