Jump to content
  • Advertisement

Archived

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

timmay314

I don't understand Java....

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. 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. 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. 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. 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. 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++? 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?

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
Go to Google and do your homework!

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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
Nobody understands Java, that''s why C# was invented.

Share this post


Link to post
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 this post


Link to post
Share on other sites
quote:
Original post by timmay314
First of all, where are the pointers?
Hidden, for your "safety."

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 this post


Link to post
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 this post


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

Share this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!