ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
...
I remember in my Java coding times, having the sensation that, even though you couldn't control how pointers behave, it does not mean that Java DOES NOT use them. In fact, to me Java HAS NOTHING ELSE but pointers. Since I recall being able to perform certain assignation and thinking how could I be capable of performing an analog operation in C++? I usually ended up answering something with a lot of dereferencing and castings involved.
Any thoughts? This topic actually reminded me of the Java and pointers topic, which I consider really interesting.
...
I think you are missing the point(er).
When you are doing bare metal programming, you sometimes need to load/store data from/to certain address of computer memory (let's forget for a time being about physical <-> logical memory mapping, and in simple HW there is no mapping). Java can not do it.
I.e. in Java in you can not write the equivalent of this:
Code:
char *ptr = (char *)0x100;
*ptr = (char)0xa5;
"C" code.
Similarly, think how you'd write in Java a device driver.
... portable devices computing aka limited resources computing. Before, Java was extremely useful for this ...
Even though Java is widely used in portable devices, it's more nonsense than not.
Portable devices have limited energy source; JVM is more often than not less efficient than native code; less efficient means more HW cycles are needed to do the same job, and this means shorter time from battery charge to batter charge.
Even though Java is widely used in portable devices, it's more nonsense than not.
Portable devices have limited energy source; JVM is more often than not less efficient than native code; less efficient means more HW cycles are needed to do the same job, and this means shorter time from battery charge to batter charge.
Java still has a big place in enterprise computing. It may not be used as common for small one off developer jobs or for doing certain tasks on your Linux box. But as I said before use the right tool for the job. I currently manage around 60 RedHat servers and more than half of them I manage apps servers such as Tomcat, JBoss, Weblogic, and Jetty. As a servlet container and for business logic Java has many uses.
In fact when you're talking about hosting enterprise apps you're more likely going to be using Java. Oh and never PHP. I work for an educational institution and it's used to process admissions applications, Turbotax during tax season, Term Master Schedule (where students look up their courses for registering), Blackboard/Learn9, and much more that I could go on. When I worked for PJM Interconnection they used it in several places such as their market where power companies buy and sell power from each other. I was programming in C at the time but I had to set up a JMS system for them at some point (Java Messaging Service).
Just because Java may be useless for what you want to accomplish does not mean it is useless as a language or a technology. The fact that it is a JVM (Virtual Machine) means that it's secure and contained from the host OS. That means if the app get's compromised then they only have the database backend and the JVM with which the malicious attacker could do harm (and that's only if the setup is poorly designed). A smarter setup wouldn't even affect the database. If your network service written in C is compromised then you don't have the security of a virtual machine unless you're running it in a VM or the process is chroot jailed. Not sure if it's a misunderstanding of the technology and its uses or what but you seem to have personal a bias against it. I could also have mistaken your statements as you may have just been trying to get certain points across rather than actually having a bias.
As always I like to say use the best tool for the job. If Java is a better choice then I use it. If C is a better choice then I use it. Truly good programmers have a variety of languages at their fingertips in which they can solve their pragmatic problems. It's not uncommon for good a programmer to know 20 or more languages. Once you understand programming concepts and the math it's only a matter of syntax and a few other core concepts unique to the language. So my suggestion to the OP is to learn both if they wish to be versatile.
A note to the OP of this thread.
If the OP doesn't want to learn both and just wants to tackle one language then the OP should take a hard look at where they want their career to go. If they want to develop enterprise apps then I would say Java is more useful. If they want to develop iPhone apps (Objective C and not C per se), do network programming, or the many other genres dominated by C then you wouldn't want to waste your time on Java for that. So it really comes down to your goals and what you wish to get out of the experience.
Also check out SweetHome 3D. That's a real cool application I use to organize the interior of my house which was written in Java (shameless plug for a good open source app).
When one considers languages to learn, he/she may look at different aspects. For example, at number of available jobs or at what a languages teaches conceptually.
My main point is that C++ is much closer to computing reality than Java. That is, people with in-depth C++ knowledge understand much better real cost (in terms of computing) of things.
I'm not sure what you mean by computing reality and you may have to elaborate on "real cost" in terms of computing. Any Java programmer I've talked to understands how the JVM works and is able to utilize its potential. It usually comes down to getting out pen and paper and solving the problem before writing a line of code. All programmers should do that. I'm not really sure what you're trying to imply. Java programmers are in high demand just like many other programming languages so I don't think any of the points you've made are valid for not considering Java to learn as a language.
The skills of a Java developer are just as marketable as the skills of a C++ developer. Don't get me wrong, I love C and C++ but I'm just trying to say that there's nothing wrong with learning Java either as a first programming language or for professional interest.
Parallel computing is the future of programming (PThreads, OpenMP, MPI in C or java.lang.thread in Java) and will be in much higher demand as microprocessors come out with more cores. Though the OP needs to learn basic programming concepts before they venture into that arena. Single threaded applications aren't able to get as much performance gain with new processors because processing performance is scaling out rather than scaling up (i.e. more cores instead of higher frequency/more pipeline stages).
I'm not sure what you mean by computing reality and you may have to elaborate on "real cost" in terms of computing.
...
Does a Java programmer understand the cost of function call ? Does a Java programmer understand the cost of function return statement ? Does a Java programmer understand benefits and drawbacks of inlined functions ? Does a Java programmer understand how much memory a data structure can occupy ? Which implies understanding what pointer and its size is. Does a Java programmer understand cache-friendliness ? Does Java guarantee continuity of RAM allocated for an array ?
Being part of a specific group does not imply virtue.
And from my experience of talking to C/C++ programmers on one hand and to Java programmers on the other the latter typically have much less clear idea what in reality is happening and how much computationally it costs.
Or, as somebody has already said, they soar in their object-oriented clouds.
Though "Being part of a specific group does not imply virtue" is correct, in practice there is some correlation.
Does a Java programmer understand the cost of function call ? Does a Java programmer understand the cost of function return statement ? Does a Java programmer understand benefits and drawbacks of inlined functions ?
I don't remember if the Java compiler can inline functions or not (perhaps only if a method is declared final), but certainly the JIT compiler can. JIT will make the cost of all those things much harder to understand.
Quote:
Does a Java programmer understand how much memory a data structure can occupy ? Which implies understanding what pointer and its size is.
On the one hand, data structures can only contain references and primitive types in Java. References are always 32 bits. On the other hand:
Quote:
2.7. Representation of Objects
The Java virtual machine does not mandate any particular internal structure for objects.
The word, versus, has almost no practical application in any discussion of computer programming languages. Each one ... every one ... is "a tool for a job." The designers of each system carefully selected among a system of inter-related technical compromises (so to speak...) in order to devise a pragmatic and practical tool. Each tool stands alongside all of its peers ... not against them.
...
I'm fairly certain the answer to this is yes (though I'm unable to find the official answer).
AFAIK, the answer is no. And this is funny in the light of the fact that I see, say, FFT implementations in Java.
Among various mathematically equivalent FFT implementations the cache-friendly ones work faster, but how can we speak about cache-friendliness if arrays are not necessarily contiguous in memory ?
AFAIK, the answer is no. [i.e. arrays need not be contiguous]
Hmm, you might be right about this. I may have been confusing between constant time access and contiguous layout, although I can't even find a statement saying plain array access is constant time! ArrayList.get() is specified to be constant time.
Quote:
Among various mathematically equivalent FFT implementations the cache-friendly ones work faster, but how can we speak about cache-friendliness if arrays are not necessarily contiguous in memory ?
If you are talking about a specific implementation, you can decide to only consider jvms that have contiguous arrays. Are there any that don't have contiguous arrays?
...
If you are talking about a specific implementation, you can decide to only consider jvms that have contiguous arrays. Are there any that don't have contiguous arrays?
My point is that C99/C++ standard prescribes contiguous arrays.
And, if you think about it, without this requirement you won't be able to write, for example, a program loader. I.e. in terms of an OS there are code/data/stack/etc memory areas, so the language you write in absolutely must have a notion of memory the way the OS and the CPU see it.
Likewise, the notion of memory at least allows to think about cache friendliness - not the case with Java.
...
Hopefully, you folks remember that I was talking about real computational cost of things and about computational reality. And, as I said, in this respect C++ beats Java hands down.
...
About dummies/smarties. Of course, generalizations often go wrong. Alas, it's quite often among "Java-only folks" (i.e. among folks who never studied HW/assembly/S/C++) to have great misconceptions about computing reality.
That's why I think if Java is studied after exposure to computing reality/low level/HW, it's OK. But if it is studied before, it is a "disaster". The same applies to other interpreted/"high level" languages, e.g. Perl/PHP/Python/Ruby and the like.
...
ntubski, I learned a lot of interesting things from you in C/C++ area, so are not at all a part of my generalizations .
Likewise, the notion of memory at least allows to think about cache friendliness - not the case with Java.
I think you are overestimating the impact of the standard. It's true that if you restrict yourself to pure standard abstract Java language, you can't make any conclusions about cache friendliness. But if you are writing real code, you can think about real implementations.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.