#### Archived

This topic is now archived and is closed to further replies.

# I don't understand Java....

This topic is 5065 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

##### Share on other sites
It seems that the idea was to make it a simpler language by taking features away. Good point.

The true general first seeks victory, then seeks battle
- Sun Tzu

##### Share on other sites

Why was Java/.Net ever created? Could it be that some of the features you mentioned historically seen has created tons of problems? This has been discussed on many forums many times before. Please, browse some of those old threads before starting another thread.

##### Share on other sites
You think Java is broken? Man, (advanced) C++ is a first class mess. I think the only reason why I''m still using is because of the monetary investment I''ve already made, and a lot of (game) code is already written in C/C++ that I can learn from.

##### Share on other sites
Nobody understands Java, that''s why C# was invented.

##### Share on other sites
quote:
Original post by timmay314
First of all, where are the pointers? I''ve heard people say that a lack of explicit pointers is a good thing, but I''ll never believe that. Adding them to the language would certainly not make it worse, as you still wouldn''t have to use them if you don''t want to.

Every variable that is a class is really just a pointer to that class. That''s why you use the new keyword.

quote:
As I understand it, there is no way to make functions return more than one value easily since you cannot make reference parameters or pointers. This makes some things a major pain.

Java has arrays and even includes things like ArrayList.

You''ll have to accept that Java''s features were designed the way they are for a reason, even if you don''t agree with the decisions made in the language.

-Agent1

##### Share on other sites
quote:
Original post by timmay314
First of all, where are the pointers?

quote:
As I understand it, there is no way to make functions return more than one value easily since you cannot make reference parameters or pointers.
Oh, Lord.

Because you can pass parameters by reference or pointer in C++ doesn''t make functions actually able to return multiple parameters; it''s a non-intuitive hack. The real solution is to support tuples in your language, which neither C++ nor Java do. The "fake" solution is to aggregate your return values into a collection of some sort - a simple sequence or an aggregation (struct) - and return that by value. "Returning by parameter" is effectively a workaround.

quote:
Secondly, why is there no operator overloading? I cannot understand the logic in leaving this out.
I concur. The rationale was that operator overloading is often abused, and the Java mantra is to eliminate anything that is potentially confusing, obscure or "dangerous". It''s a pretty tame language. Nevertheless, the C++ operator overloading syntax is fugly, unintuitive and necessitates the addition of another keyword (operator). The elegant way to do it would be to have certain specially-named functions (perhaps with leading underscores, indicating their reserved status) which, when implemented, were evaluated as symbolic operators.

quote:
Thirdly, interfaces. Why must every method be pure virtual? This adds unnecessary declarations to the class and is annoying, although it''s far less so than the other two things mentioned so far.
This is just wrong. An interface, by definition, can not be instantiated. Ever. It exists purely to define, believe it or not, an interface, not any functionality.

Get over it.

quote:
Fourthly, why can''t you write procedural code?
You can. As you stated, make all methods static, have no constructors or object data.

That said, I agree with you to a large extent that the exclusively OO philosophy is sometimes questionable, but I think it is most questionable because of the relationship between entities in the class library. In C#, the strictly OO approach doesn''t irk me at all because of the transparent uses of properties and a few other flexibilities that differentiate it from Java.

quote:
Lastly, why must objects be created by dynamic memory allocation? This isn''t so much of a complaint as a confusion. Is there a reason that it is bad to create an object the same way it would normally be created in C++?
Unified syntax. Not having to differentiate between statically allocated and dynamically allocated objects, with their different scope termination rules. It''s no big deal since dynamically allocated objects go out of scope the way statically allocated ones in C++ do, their memory being garbage collected.

quote:
I could go on...
No, you couldn''t. For the most part, you''re simply resisting difference. I felt the same way the first time I encountered Python (which uses whitespace to indicate scope). I got over it, so can you.

quote:
Will someone please explain why Java isn''t improved as it easily could be, at least with respect to my first two problems?
Java and C++ aren''t designed to apply to the same domain. While we''re on the topic, allow me to reiterate that C++ is a confused language unsure whether it wants to be high-level or low-level, thoroughly unteachable and filled with contradictions; is that what you want Java to be?

Once again, get over it.

##### Share on other sites
quote:
Original post by timmay314
I know C++ and have been learning Java for the past month now. Will someone please tell me that this language is nowhere near complete and that they are planning on adding more, and soon? I simply cannot comprehend why this is considered a good language. I don't want this to be a flame thread at all, but I don't understand why they chose to leave out many features that would make the language much better.

You mean, features that would essentially make Java just like C++, even though they're different languages.

quote:
First of all, where are the pointers? I've heard people say that a lack of explicit pointers is a good thing, but I'll never believe that. Adding them to the language would certainly not make it worse, as you still wouldn't have to use them if you don't want to. As I understand it, there is no way to make functions return more than one value easily since you cannot make reference parameters or pointers. This makes some things a major pain.

Pointers are quite dangerous in a sense, and the designers chose to leave them out of Java.

quote:
Secondly, why is there no operator overloading? I cannot understand the logic in leaving this out. Code looks so much cleaner and simpler when you can add two vectors without using an explicit function call.

Another design decision. Operators on objects aren't as naturally defined so-to-speak as operators on built-in types, so the designers though they would lead to confusion and mass hysteria and left them out.

quote:
Thirdly, interfaces. Why must every method be pure virtual? This adds unnecessary declarations to the class and is annoying, although it's far less so than the other two things mentioned so far.

Interfaces basically mean that an object must implement those methods, but at the same time there is no default implementation, as there might be in an inheritance situation with base classes. You're right that they're kinda analogous to pure virtual functions, but the Java designers took it one step further and made it a completely different concept.

quote:
Fourthly, why can't you write procedural code? Why is it beneficial to be entirely OO? Using static methods you can generally achieve the same effect as procedural code, but I simply do not understand the logic of having no procedural code.

Java was designed from the start to be as true an object-oriented programming language as possible. And that means everything is in a class, one way or another. Design.

quote:
Lastly, why must objects be createed by dynamic memory allocation? This isn't so much of a complaint as a confusion. Is there a reason that it is bad to create an object the same way it would normally be created in C++?

I guess they figured it would be easier to keep track of where objects are created and how you're allocating resources.

These are all basically decisions the designers made about what they wanted Java to be. I have an extensive C++ background and have been learning Java over the past year, and I really do like the language. Sure, it's missing a lot of the things from C++, but then I remember that is isn't C++. If you've been doing C++ for a long time it's a bit hard to understand how a language can lack such seemingly "fundamental" things, but in the end it makes sense.

[edited by - Zipster on April 12, 2004 1:51:00 PM]

##### Share on other sites
quote:
Original post by Oluseyi
quote:
I could go on...
No, you couldn''t. For the most part, you''re simply resisting difference.

##### Share on other sites
quote:
Original post by timmay314
First of all, where are the pointers? I've heard people say that a lack of explicit pointers is a good thing, but I'll never believe that. Adding them to the language would certainly not make it worse, as you still wouldn't have to use them if you don't want to. As I understand it, there is no way to make functions return more than one value easily since you cannot make reference parameters or pointers. This makes some things a major pain.

First, Java was designed to be a high-level language. Pointers represent a low-level feature. They were therfore discarded from the language. That doesn't mean that Java doesn't have pointers, every instance is a pointer.

Second, you cannot return multiple values either in C++: what you can do is change some values by using pointers. While you can't do this in Java, you can simply return an array with the values you want. Of course, the best solution as someone mentionned would be to have a tuple type, or to use the Common lisp [tt]multiple-values[/tt] solution.

quote:

Secondly, why is there no operator overloading? I cannot understand the logic in leaving this out. Code looks so much cleaner and simpler when you can add two vectors without using an explicit function call.

Operator overloading has been abused so much in the past that I think it's not so big a deal. One thing I noticed though, is that operator overloading seems much more important to the people who have never done Lisp programming (or any language with prefix syntax.)

quote:

Fourthly, why can't you write procedural code? Why is it beneficial to be entirely OO? Using static methods you can generally achieve the same effect as procedural code, but I simply do not understand the logic of having no procedural code.

Well, you can, you just said it. Just add the keyword [tt]static[/tt] before every method and stick everything into the same class, and you have procedural code.

quote:

I could go on, but these are my major complaints/confusions. I've worked with C# as well, and while it also has some of the same annoying "features", it fixes the most annoying problems (operator overloading and pointers) and is all around better in every way I can think of. With a special compiler and libraries, C# (or C++, for that matter) should be able to write applets just as well as Java, so I don't see any reason that Java continues to be used for applets when it has so many flaws. Will someone please explain why Java isn't improved as it easily could be, at least with respect to my first two problems?

What you want, is for Java to stay exactly how you always saw languages. You don't want to get rid of your pointers for example. I suggest you learn to appreciate the differences between languages. Right now, you only compare Java to C++ and see the negative about Java; how about trying to see the positive side of things? Or, how about we compare C++ to other languages and point out its flaws so you can feel better about Java? Try different languages, every one of them will throw you off in its own specific way:

- SML or O'Caml: you'll be thrown off by the fact that you can't add an integer to a float, by the fact that you cannot change the value of a variable, by the fact that recursion is the prefered looping method and many other things

- Smalltalk: you'll be thrown off by the all-message syntax, by the environment, by the method-by-method compile, by the lack of source files, by the general environment, by the late-binding nature of the language.

- Lisp: you'll be thrown off by the prefix syntax, by the dynamic typing, by the macros, etc.

Programming does not need to be how C and C++ creators saw it. Expand your horizons, try other languages.

[edited by - GnuVince on April 12, 2004 2:15:02 PM]

##### Share on other sites
quote:

Pointers are quite dangerous in a sense, and the designers chose to leave them out of Java.

Anything can be quite dangerous in a sense. As I said earlier, adding them would not require the use of them, so I don''t see any drawbacks. As for Java being a high level langauge; that''s just not a reason. A high level language can and should use low level features if they improve productivity or speed. Simply excluding it because it is a low level feature is only shooting yourself in the foot.

quote:

While we''re on the topic, allow me to reiterate that C++ is a confused language unsure whether it wants to be high-level or low-level, thoroughly unteachable and filled with contradictions; is that what you want Java to be?

I don''t think C++ is perfect; not even remotely. I dislike several things, including how templates are handled, how messy things can get with forward declarations of classes, and adding strong typedefs would certainly be nice. Once again, I see making this language "high level" and another one "low level" and refusing to use extra features for this reason alone is ultimately restricting more than anything else. As for it being unteachable, I learned to program in C++ so I don''t agree with this at all.

quote:

Operator overloading has been abused so much in the past that I think it''s not so big a deal.

How has it been abused? I don''t understand what you mean, exactly.

##### Share on other sites
quote:
Original post by timmay314
quote:

Anything can be quite dangerous in a sense. As I said earlier, adding them would not require the use of them, so I don''t see any drawbacks. As for Java being a high level langauge; that''s just not a reason. A high level language can and should use low level features if they improve productivity or speed. Simply excluding it because it is a low level feature is only shooting yourself in the foot.

Pointers can give rise to some really obscure and hard to find bugs. Even if you personally are very controlled and know what you''re doing, it doesn''t stop somebody else using them in a bad way (or even in a good way that introduces accidental bugs). For large scale projects, it really is in your best intrest to limit the risk of introducing bugs and constraining pointers does help. The same goes for manual memory management really. Remember, it''s not just your code you have to worry about but your team mates and in the libraries you use.

##### Share on other sites
quote:
Original post by timmay314
I don''t think C++ is perfect; not even remotely. I dislike several things, including how templates are handled, how messy things can get with forward declarations of classes, and adding strong typedefs would certainly be nice. Once again, I see making this language "high level" and another one "low level" and refusing to use extra features for this reason alone is ultimately restricting more than anything else.
Scope. Objective. Intent. Do we need the kind of "unbridled power" used to forge operating systems and bootloaders for writing word processors and web services? If you do, stick to a language the provides it. If you don''t, quite kvetching and get to work.

Java''s not going to change, so it''s up to you.

quote:
As for it being unteachable, I learned to program in C++ so I don''t agree with this at all.
Of course you don''t. But I can''t vouch for how good of a programmer you are, or how long it took you, or how solid your foundations are, or...

Anecdotal evidence is worthless.

##### Share on other sites

micro\$oft gave up c++ and inventend a "new" language called C#

and guess what, it is strangely similar to JAVA...

aehoaehaos .. JAVA IS HORRIBLE =P

##### Share on other sites
Finally, I get to use this link.

##### Share on other sites
quote:
Original post by timmay314
Anything can be quite dangerous in a sense. As I said earlier, adding them would not require the use of them, so I don''t see any drawbacks. As for Java being a high level langauge; that''s just not a reason. A high level language can and should use low level features if they improve productivity or speed. Simply excluding it because it is a low level feature is only shooting yourself in the foot.

If you give them the possibility, they will use it. Pointers can introduce hard to find bugs. Also, it is very clearly mentionned in the original Java paper that the language is intended for average programmers, the kind who might mess up if you give them pointers. so they were removed. And anyway, what do you want pointers for? I use many languages in which pointers would be useless because the language provides everything that pointers would.

quote:

How has it been abused? I don''t understand what you mean, exactly.

Addition is an operation applied on numbers. Addition is commutative: 2+5 is the same as 5+2. Many languages use + to also concatenate strings, but this changes the behaviour of addition: "foo"+"bar" is not the same as "bar"+"foo". Of course, since this one is so much common, I''ve grown used to it, and it is at least a little intuiative what is accomplished. But in some situations, you just have no idea:

Person Serge = new Person("Serge");Person Mary = new Person("Mary");Mary + Serge;

What happens when you add Mary and Serge? A Baby instance, because maybe Serge has a male attribute and Mary has a female attribute? A new Person called MarySerge? A new Company, a new Family? This is the kind of abuse people talk about. On the other hand, if you have code like this:
Person John = new Person("John");Person Stacey = new Person("Stacey");John.startNewCompanyWith(Stacey);

It''s easier to know what happens. Sure it''s longer to type, it''s more verbose, but when someone reads this code, they''ll know what''s going on.

##### Share on other sites
quote:
Original post by GnuVince
Addition is an operation applied on numbers.
Or vectors or matrices or functions or whatever.
quote:
Addition is commutative: 2+5 is the same as 5+2.
Some say multiplication is commutative: 2*5 is the same as 5*2. But then you take matrix multiplication. A*B is not the same as B*A generally, and we''re still talking about pretty basic math and not some ugly computer science. Addition, like multiplication, is commutative only for what types it''s defined to be commutative. I have no problem accepting other definitions for other domains such as strings. Mary + Serge sure is abuse, but defining new numerical types with overloaded operators is not.

##### Share on other sites
quote:
Original post by GnuVince
Addition is an operation applied on numbers. Addition is commutative: 2+5 is the same as 5+2. Many languages use + to also concatenate strings, but this changes the behaviour of addition: "foo"+"bar" is not the same as "bar"+"foo". Of course, since this one is so much common, I''ve grown used to it, and it is at least a little intuiative what is accomplished. But in some situations, you just have no idea:

Person Serge = new Person("Serge");Person Mary = new Person("Mary");Mary + Serge;What happens when you add Mary and Serge?  A Baby instance, because maybe Serge has a male attribute and Mary has a female attribute?  A new Person called MarySerge?  A new Company, a new Family?  This is the kind of abuse people talk about.  On the other hand, if you have code like this:   Person John = new Person("John");Person Stacey = new Person("Stacey");John.startNewCompanyWith(Stacey);

It''s easier to know what happens. Sure it''s longer to type, it''s more verbose, but when someone reads this code, they''ll know what''s going on.

But operator+() is not a suitable ''alias'', if you will, for a startNewCompanyWith() method. This is, then, mostly a question about giving functions improper names; the Java analogue for operator+() would be wrapping the functionality of startNewCompanyWith() into a method called add(), which IMO is as idiotic as the operator method. How is operator+() less clear than add()?

##### Share on other sites
Why is it that the people who piss and moan the most about Java are always converting from C or C++? Learn some other languages, get some perspective, then bitch about Java. It might be easier for people to learn Java if it DIDN''T share syntax with C/C++, because then they would stop expecting it to be identical.

##### Share on other sites
quote:
Original post by Miserable
But operator+() is not a suitable ''alias'', if you will, for a startNewCompanyWith() method. This is, then, mostly a question about giving functions improper names; the Java analogue for operator+() would be wrapping the functionality of startNewCompanyWith() into a method called add(), which IMO is as idiotic as the operator method. How is operator+() less clear than add()?

It''s just as clear (or unclear depending on the situation). The problem is that since Java doesn''t have operator+(), its programmers are not tempted to use it, so they tend to choose descriptive method names. Of course, if add() is used intead of a more descriptive method name, well what can you do. But the temptation to abuse operator overloading is not there. Don''t have an apple hanging if you fear eating it would be bad.

##### Share on other sites
quote:
Original post by Anonymous Poster
Why is it that the people who piss and moan the most about Java are always converting from C or C++? Learn some other languages, get some perspective, then bitch about Java. It might be easier for people to learn Java if it DIDN''T share syntax with C/C++, because then they would stop expecting it to be identical.

But then a Smalltalk programmer hearing it''s OO would be quite disappointed to see Java.

##### Share on other sites
quote:
Original post by Oluseyi
I concur. The rationale was that operator overloading is often abused, and the Java mantra is to eliminate anything that is potentially confusing, obscure or "dangerous". It''s a pretty tame language. Nevertheless, the C++ operator overloading syntax is fugly, unintuitive and necessitates the addition of another keyword (operator). The elegant way to do it would be to have certain specially-named functions (perhaps with leading underscores, indicating their reserved status) which, when implemented, were evaluated as symbolic operators.

Oluseyi is now officially a D fan

##### Share on other sites
Java is a "SAFE" language and thats why it doesn''t allow pointers. Or maybe you would like to watch that cool java applet that shows a lake while it''s messing up your memory or erases the contents of your computer in the background.

##### Share on other sites

And you''re right: we were not out to win over the Lisp programmers; we were after the C++ programmers. We managed to drag a lot of them about halfway to Lisp. Aren''t you happy?

-- Guy Steele

--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]

##### Share on other sites
Java is just horrible.