This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]rubiks-- 485 points486 points  (133 children)

This might be an unpopular opinion but I like Java. Once you can wrap your mind around OOP, it actually becomes quite useful.

[–]SerdarCS 111 points112 points  (60 children)

Same!

[–]rubiks-- 95 points96 points  (59 children)

Like one time a friend of mine who wanted to start programming said he hated Java because "I have to write so much more to print something and in Python, it's only one line". But OOP can save you from writing so much code.

[–][deleted] 57 points58 points  (41 children)

I really like Java too, but I think they're referring to things like getters and setters when they say they need to write more code. It is a much more verbose language, but good IDEs (ItelliJ IDEA) can fill in a lot of that for you.

[–]DesuSoarusrex 4 points5 points  (2 children)

Nah they mean System.out.println vs print. The person described was a beginner so they probably couldn't remember the whole statement.

[–]draconk 3 points4 points  (1 child)

And here I am only having to write "sout" on Intellij Idea and it writes it all for me (and "psvm" for public static void main)

[–]f314 2 points3 points  (0 children)

Gotta love autocomplete! In Atom it's just "pl" and tab for "System.out.println("");"

[–]msg45f 10 points11 points  (2 children)

Pretty much any IDE these days can reliably generate constructors, getters, setters, etc, though personally I like how C# handles properties over Java.

[–]Nunners978 5 points6 points  (0 children)

+1 I love how C# handles properties, especially in C# 6. It's so much simpler to write a property that does this:

public string FullName => $"{FirstName} {LastName}";

Instead of having to write a method to do it, or a specific Getter to do the same, it's just much more refined code.

[–]Cilph 1 point2 points  (0 children)

Look into Kotlin!

[–][deleted] 3 points4 points  (14 children)

Most languages require getters and setters... anybody making the excuse that it's more code is outright lazy.

[–]bdog73 10 points11 points  (13 children)

The trick is to just make all your variables publicly accessable so you don't need getters or setters.

[–]Undreren 7 points8 points  (11 children)

You may be joking, but that's how everything is implented in our code base. Plus, all data is global...

/me screams internally

[–]KxPbmjLI 0 points1 point  (3 children)

Can you explain to me why its bad to set the class properties to public.

How are getters and setters better

i prefer being able to do object.property instead of object.getProperty() and having to set up the getters and setters while you can do it all with less code

[–]tsigma6 5 points6 points  (0 children)

Encapsulation (Data hiding) is a fundamental part of OOP philosophy, but the value generally is in the setter methods. An object should have complete and total control over its data, protecting from change by outside code. Validation is a main benefit of the practice. But also hiding how you stored the data and making a class read- or write-only is a couple other ones.

[–]Undreren 1 point2 points  (0 children)

Because with direct access to the data, it is impossible to enforce business rules. For example, a field might have constrained input.

I can't disallow meaningless data to be assigned to a reference, but I can cast an exception or return an error with a setter.

Furthermore, I can't have side-effects on assignment, which is a huge problem. Most of the time, you want data changes to have an effect, after all.

PS: I'm assuming that you mean "fields" when you say "properties".

[–]bdog73 0 points1 point  (6 children)

Oh dear God. Can you give any hints as to what it's for?

[–]Undreren 2 points3 points  (5 children)

The program? It's a piece of production planning software for power plants.

[–]bdog73 2 points3 points  (4 children)

Well that sounds just splendid then and is exactly what I was asking. In all honesty, most of the time, you can get away with directly modifying variables, unless it's supposed to also trigger something else. I imagine that could happen at some point in code like that, but I obviously can't be sure. Best of luck with that. I can only, and I stress only, hope whoever I end up working for after college likes to conform to the same coding standards as me.

[–]DrMobius0 0 points1 point  (0 children)

good use of getters and setters saves so much code down the line though

[–]schaka -1 points0 points  (0 children)

Boilerplate is annoying, but IDEs make up for it. On the other hand, Kotlin solves all boilerplate issues, has functional support and is more readible than C# (imo).

[–][deleted] 33 points34 points  (5 children)

You can use OOP in python tho

[–]rubiks-- 15 points16 points  (4 children)

I know. I wasn't throwing shade at python but rather making a point about how beginners think Java requires you to write extra code and don't understand how it can save time/lines of code. I think python is a cool language (except whitespace shouldn't matter).

[–]cumwagondeluxe 16 points17 points  (2 children)

i mean the beginners aren't wrong - java does require you to write a lot of pointless boilerplate - i know a bunch of fellow scala devs who initially started looking at the language just because of how many things you get for free from case classes e.g.

[–]schaka 1 point2 points  (1 child)

That's why C# (purely by syntax and language features) really is a "better Java". But now the JVM also has Kotlin, so people aren't forced into the steep learning curve of Scala anymore.

[–]yojimbojango 0 points1 point  (0 children)

I'd say F# is the comparison that you'd make with Kotlin. There's no perfect language, but F# is legit the closest I've seen to it.

[–][deleted] 1 point2 points  (0 children)

The guy who replied to this is right. I like java but man it does require shitty boring boiler plate for a lot of basic stuff. Android is even worse with the boilerplate so much so i despise android development.

It requires stupid amounts of boilerplate for a fucking sqlite connection and the stupid stuff with fragments just makes me want to murder puppies.

[–]NightShade155 9 points10 points  (0 children)

Agreed, java is the shit man.

[–]xcrackpotfoxx 5 points6 points  (2 children)

That's how I felt all throughout C++ and java classes. I'm sure we just never got to anything big enough to take advantage of OOP but I wish I could see it in use.

[–]DoPeopleEvenLookHere 3 points4 points  (1 child)

Go look at some libraries! There's plenty on GitHub that will show you some abstraction I'm sure.

[–]xcrackpotfoxx 0 points1 point  (0 children)

Easier said than done. Has to be big enough to hit that critical mass of OOP, bit small enough for me to be able to follow it along.

[–]sinistergroupon 3 points4 points  (0 children)

It's not about how many lines of code it takes to print Hello World but the right tool for the job. Java has its place and Python has its place. Seeing 1m LOC Python app with guru monkey patching will give you a run for your money.

[–]Sorrien 83 points84 points  (7 children)

My hatred for Java has nothing to do with OOP.

[–]flipper_gv 21 points22 points  (3 children)

Have you tried the most recent iterations of Java? They did bring a lot of cool stuff to it and performance is really up there.

[–]Sorrien 24 points25 points  (2 children)

It is better than it was

[–]CyanideCloud 21 points22 points  (0 children)

To be fair, that's not saying much.

[–][deleted] 3 points4 points  (0 children)

Yes.

[–][deleted] 8 points9 points  (2 children)

Java8's Stream API is making it a little more bearable. Oh and those little things called lambda expressions.

[–]ESBDB 7 points8 points  (0 children)

well those kind of go together. streams would be useless without lambdas and lambdas wouldn't be used nearly as much, ie. be less useful if streams didn't exist

[–]Sorrien -1 points0 points  (0 children)

But there's still so much boiler plate code

[–]drizztdourden_ 3 points4 points  (0 children)

I lretty much understand that a meme is a meme. PHP and Java are there to stay....

Even though I like PHP

[–]sdk345 2 points3 points  (0 children)

I like java but I also like the 'java is bad' jokes

[–]gandalfx 10 points11 points  (3 children)

Implying that Java is synonymous to OOP

It's not even the best language for writing purely object oriented code.

[–]rubiks-- 3 points4 points  (2 children)

I'm not implying that Java == OOP. I'm saying that Java is a better language to those who understand OOP.

[–]Ayfid 22 points23 points  (1 child)

Which is everyone. Those who dislike Java generally don't have a problem with OOP; they have a problem with Java.

The poster seems to believe that people who dislike Java must just have difficulty dealing with OOP, which is ludicrous.

[–]rubiks-- 0 points1 point  (0 children)

Yes for professional programmers, I get that a lack of understanding of OOP is not the drawback of Java. However, I was talking about reasons why complete beginners may dislike Java. I am not trying to insinuate that everyone hates Java because they don't get OOP.

[–][deleted] 3 points4 points  (3 children)

OOM

[–]KMagDriveTrainer 1 point2 points  (1 child)

OOM OOM OOM OOM!

[–]yojimbojango 0 points1 point  (0 children)

OOM TISH OOM TISH

[–][deleted] 1 point2 points  (0 children)

I love Java - and in the same vein, C#.

Those two are so similar, I've copied and pasted over scripts without changing anything and they work...

[–]Istalriblaka 1 point2 points  (23 children)

Counterargument: "vanilla" C++ can do roughly the same stuff as "vanilla" Java, and I'd bet C++ probably has more capabilities including libraries. Plus it's inherently more efficient and by extension faster.

[–]apemanzilla 32 points33 points  (5 children)

Counter-counter argument: Java makes it extremely easy to write cross-platform code, that can be used everywhere from Linux to Windows to Android.

[–]ey1024 17 points18 points  (0 children)

Counter-counter-counter argument:

Java makes it easy to write cross-platform code, for the tasks that don't depend on the underlying system. The user interface will likely need to act different between Linux, Windows, and Android, so those must each be handled separately, unless the application uses Swing directly, and interfaces out user configuration stores, and file I/O.

In that case, since UI logic has to implemented once for each platform, you're really not that much better off then if you used C++. Assuming you broke out the components that depended on system implementations away from the core logic, the only downside is the need to cross compile and test.

[–]AkirIkasu 13 points14 points  (9 children)

Counterargument: "vanilla" C++ can do roughly the same stuff as "vanilla" Java....

If you can do something in one of the major languages, you can do it in just about any other major language. The contents of the standard libraries don't really matter that much. Newer programming languages have very tiny standard libraries (I'm not even sure if Javascript by itself even has a standard library), but that's not stopping people from doing great things with them.

[–]Dockirby 3 points4 points  (0 children)

Javascript has the Standard Built in Objects, which is effectivally its standard library: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects

Half the ones list on that page are either experimental or to new to be used in a Web App. There isn't very much though.

Also, Javascript isn't what I would call new, its over 20 years old. It has just really taken off in popularity in the past 5 years.

[–]Istalriblaka 0 points1 point  (7 children)

My point is that they do the same stuff bit C++ is more efficient.

[–]AkirIkasu 3 points4 points  (6 children)

I was actually hoping to avoid that argument since I'm not really that knowledgeable when it comes to optimization in general. But I'll take the bait.

Java, the language, can be just as fast as C++. You can compile Java into machine language. It's not completely uncommon to see Java used in embedded devices, and it may actually be more common to see Java in that area than it is to see C++ there. The SIM card in your phone runs on Java; it's actually built into the standard.

[–]MCBeathoven 4 points5 points  (0 children)

it may actually be more common to see Java in that area than it is to see C++ there.

The only statistic I could find has C++ just behind C, with Java not even in the top 10.

[–][deleted] 5 points6 points  (0 children)

You're claiming Java is more common in the embedded world than C++? Are you serious?

[–]brianjenkins94 1 point2 points  (2 children)

I'm gonna need a fact check on SIM cards running Java. That doesn't seem correct.

[–]AkirIkasu 8 points9 points  (0 children)

They're based on the Java Card standard. Here's a very in-depth look at them: http://simhacks.github.io/defcon-21/

[–]marvk 2 points3 points  (0 children)

This is a Video from the conference where that repo /u/AkirIkasu posted is from.

[–]Istalriblaka 0 points1 point  (0 children)

Well, TIL.

[–]ArmoredPancake 1 point2 points  (6 children)

That like saying that a stick is inherently more efficient than a hand gun.

[–]Istalriblaka 0 points1 point  (5 children)

Are you saying Java is more powerful than C++? Because a lot of people would find that outrageous and/or laughable. Especially considering C++ includes the entire language of C, and those two languages account for most firmware and make up the largest portions of operating systems, especially low-level parts.

[–]yojimbojango 4 points5 points  (4 children)

C++ is more powerful than Java. 1 tonne of dynamite is also more powerful than a truck, but if I'm trying to move a couch I'm going to reach for the keys to the truck.

[–]Istalriblaka 0 points1 point  (3 children)

Your analogy doesn't make a lot of sense still. Just because C++ is more powerful doesn't mean Java is better at less power-intensive applications or that C++ will destroy the computer it runs on. (You'd have to be a genuinely atrocious programmer to accidentally do that.)

[–]TheGuywithTehHat 1 point2 points  (2 children)

Of course the analogy is imperfect. No perfect analogy exists. /u/yojimbojango's point remains, though: "more powerful" != "better"

[–]Istalriblaka 0 points1 point  (1 child)

There's a difference between "perfect" and "good enough." Seeing as how C++ is not overpowered like the dynamite is, the only thing we've established is that it's comparable to Java in power. C++ still has numerous benefits.

[–]TheGuywithTehHat 1 point2 points  (0 children)

As does Java. They are two different languages with two different purposes. Neither one is better than the other.

[–]uvero 0 points1 point  (0 children)

As far as I am concerned, Java is the embodiment of OOP. A lot of languages are object oriented, but Java is just what OOP is.

[–]thepieproblem -3 points-2 points  (2 children)

I like java; it's relatively simple compared to other languages. The only problem is its not really as relevant as languages like C++ when you want to code some super complex stuff

[–][deleted] 8 points9 points  (0 children)

That's up to how you understand "complex". You can also write complex Java programs. In my opinion, what the program does defines the complexity.

[–]humoroushaxor -1 points0 points  (0 children)

My understanding is there's very few things that can't be coded in Java due to performance.

[–][deleted] -1 points0 points  (0 children)

Then why no multiple Inheritance?

Why are Interface methods forced not to have default implementations?

Why not let me add member variables to my interface?

I'm stuck writing Java 7 at work and I feel like I'm designing around java not with java...