PDA

View Full Version : Java instead of C++


RadicalEd
11th October 2002, 20:56
Apparently my school is switching over from C++ to Java next year, which if I continue with programming class, I'll have to take. From what I've heard, Java is much slower and clumsier than C, and since speed is the need in the world of video, it probably wouldn't be practial for any of the programs I'd be developing. If it was up to me, I'd like to take C++ as a class and then Assembler, since these seem to be the most useful for applications in the video field. So, the question remains, do I drop programming and take another elective like multimedia, or is Java worth the time and effort?

Of course, right now I'm stuck making junky little toys with Visual Basic ;P maybe I'll take up delphi as an extracurricular hobby since it seems more useful for GUI making than BASIC.

DSPguru
11th October 2002, 21:01
i hate java, i hate delphi, i hate vb, i even hate c++.
only assembly & c are valid for signal processing.

Emp3r0r
11th October 2002, 21:22
at my school they've done this with me in order i've taken them
1 C class
2 Java classes
1 Data Structure classes
1 Scheme class (shoot me in the head)
1 Assembly class
1 UML & C++ class
and I'm almost a senior

The more languages you know the better (except for scheme)!

Nic
11th October 2002, 23:04
Have you done Z yet? That makes drawing UMP pictures actually seem enjoyable.. :)

& unfortunatly Dg is right, for signal processing C & assembler are the way to go.

But Java will hone your OOP skills....
...and drive you nuts.

-Nic

avih
12th October 2002, 08:13
@RadicalEd

java is as good as c++ when you learn how to PROGRAM. you can learn object oriented approach with java the same way you can with c++. these languages are VERY similar. the syntax differences are minimal. the real difference is multiple inheritance/interfaces and the various libraries that are standard part of the language.

if you know one you can learn the other in 10 minutes.

when they teach you is how to program. after you know that, you can apply your knoledge to be productive with any language you choose to.

Koepi
12th October 2002, 11:21
Am I the only one who had a COBOL class, too? ;)
I can try writing a cobol version of xvid-GUI ;)

Regards,
Koepi

dragongodz
12th October 2002, 11:27
we did pascal for 1 term. this was back in the 80's mind.
how things have changed. god, now i am starting to sound my age. :)

trbarry
12th October 2002, 19:52
Am I the only one who had a COBOL class, too?
I can try writing a cobol version of xvid-GUI

I sorta started out life as a Cobol programmer. One boss even had me write a Cobol parser in Cobol because "it would be easier to maintain". ;)

- Tom

esby
14th October 2002, 17:06
About execution speed,
all depends the virtual machine you are using,
i heard msoft virtual machine was 10 times slower than the ibm one...
I ve done some little prog in java (little games etc...)
but i wont use it for any heavy processing application (like DSPguru said)

esby

int 21h
16th October 2002, 04:01
Java will always be slower on a machine of the same specifications than similar C/C++ code because of the difference between compiled and interpeted languages. (Not even JIT can save the day here :( )

Journalists and such that write nonsense like "Java sucks, Java is bloated, C++ rulz youz allz! Pascal is the best!" are ignorant. Java is just another tool in a programmer's toolbox. Its the programmer's job to select which tool will accomplish his/her job. Sure you can use an electric drill to cut boards in half, but doesn't a circular saw work much better?

In other news, learning ASM is most useful. Not only because of its speed qualities, but because of the general usefuless of applying its concepts in other embedded areas. ;)

And no offense but, as Tom indirectly pointed out, no matter what you want to develop in, the end decision usually lies with your supervisor. Unless you're doing the supervising, in which case, its even more important to know the value and uses of your tools.

Besides, Java is very useful for teaching the basics and intermediate principles of oO, something everyone needs to know, and while it may not seem useful now, 5 years from now when your boss comes up with some silly idea you have to implement, you'll be happy you expanded your horizon.

Infophreak
2nd November 2002, 23:32
At the university I am attending (University of Copenhagen Faculty of Science (http://www.nat.ku.dk/english/index.htm) - more specifically: math), the computer science students are forced to learn ML and Java the first year. The philosophy is rather simple: Later on, you will be responsible for learning new programming languages by yourself, so they spend the first year learning you how to learn to use a new language (so to say). Their motivation for choosing Java thus has nothing to do with its speed (or lack thereof), but that it illustrates some important points about object oriented programming. While it is true that Java is slow if you run it through a virtual machine, Java code compiled into an executable that only works on one platform should be right up there with C++ in terms of performerance (maybe slightly slower because of automatic garbage collection).

NB: I am completely unaware of any Java compiler that generates native executables for either Windows, Linux or Solaris (but I could imagine that there would be one for Solaris seeing as how Sun invented Java).

sh0dan
3rd November 2002, 19:55
Originally posted by int 21h
Java will always be slower on a machine of the same specifications than similar C/C++ code because of the difference between compiled and interpeted languages. (Not even JIT can save the day here :( )

There is the possibility that a JIT/Hotspot compiler is capable of generating faster assembler, since it doesn't have to go with the lowest common denominateor (386, P5 for example). The JIT can choose to do assembler using processor specific instructions, since it's done runtime.
Another thing may be that Java (byte)code can be easier to optimize, since it doesn't have any pointers. Pointer optimization can be very difficult for compilers, since they have to do run-time profiling to optimize them.


In other news, learning ASM is most useful. Not only because of its speed qualities, but because of the general usefuless of applying its concepts in other embedded areas. ;)

Yes - assembler gives a very good picture of the internals of your machine. Just a shame that it is so immensely complex to count cycles and know which code is faster, on machines nowadays ;)


Besides, Java is very useful for teaching the basics and intermediate principles of oO, something everyone needs to know, and while it may not seem useful now, 5 years from now when your boss comes up with some silly idea you have to implement, you'll be happy you expanded your horizon.
I wouldn't live without my java experiences. I'd probably be writing crappy C code, because I never learned how to properly use OOP.

Btw, find a Java->Windows EXE compiler at http://www.excelsior-usa.com/jet.html

Milkman Dan
4th November 2002, 18:16
I'm glad to see lots of real discussion about Java, and not bashing it, like I hear alot in #mcf. :rolleyes:

I've read lots of material about server-side performance of HotSpot compiled Java on 4-way and 8-way systems, compared to other non-JIT, non Sun compilers.

Most of the time, the performance was between 40-50% better for the HotSpot VM/compiler. There was a SQL benchmark case that was 98% faster, and scaled across n-way systems almost that well. I was very impressed.

About that native-code compiler linked above: Last I checked into that sort of thing, you couldn't use these tools on apps that used Swing or the AWT. Since the app I'm programming for MCF authoring uses Swing, that wasn't an option to me. I seem to remember the reason being a licensing conflict about the Swing packages. Has this situation been fixed?

While I wouldn't want to solely distribute my app as an exe, I would rather have one to shut the yap of all the people who would mail me with "j00r app sux0r!!!!!111 JaVAA sux0r!!!!!111" and thus not use it at all. [sigh] I want the linux crowd to be able to access the features of MCF in a easy, useful way. Without having to re-code a ton of stuff.

Great discussion.

int 21h
5th November 2002, 06:50
Originally posted by sh0dan
There is the possibility that a JIT/Hotspot compiler is capable of generating faster assembler, since it doesn't have to go with the lowest common denominateor (386, P5 for example). The JIT can choose to do assembler using processor specific instructions, since it's done runtime.
Another thing may be that Java (byte)code can be easier to optimize, since it doesn't have any pointers. Pointer optimization can be very difficult for compilers, since they have to do run-time profiling to optimize them.


I still would be willing to bet that hand written assembly is always faster than JIT (if you're writing for a specific environment [i.e. SSE2])


Yes - assembler gives a very good picture of the internals of your machine. Just a shame that it is so immensely complex to count cycles and know which code is faster, on machines nowadays ;)


The real fun is when you program in embedded environments. When you're programming on someone else's machine, its very important to know the difference of what each instruction's clock cycles are.


I wouldn't live without my java experiences. I'd probably be writing crappy C code, because I never learned how to properly use OOP.

Btw, find a Java->Windows EXE compiler at http://www.excelsior-usa.com/jet.html

I totally agree. While I would never want to write something that needs high performance (such as Avisynth) in Java, it is a very, very, good learning tool.

trbarry
7th November 2002, 05:42
I know more or less diddly about Java though I'll probably have to someday. But by temperment and belief I consider myself mostly an assembler programmer.

So I have a question for the Java experts. In C or C++ it's fairly easy to write an ap and then recode the inner loops into assembler until it goes fast enough. This is especially common in things like video. How well does this same process work in Java?

I realize the moment you put the assembler in there the portability goes away but obviously things like real time video might be willing to make the compromise. Does assembler fit gracefully into Java somehow?

- Tom

vlad59
7th November 2002, 10:25
As far as I know, it's not possible to add inline assembler in Java (mostly for the lack of portability).

But on the last Java project I've been working on. We were working on both linux and win32 and to gain some performance we used JNI to allow our java classes to acces to specific C (portable) dll (for win32) or lib (for Linux). Of course those C app weren't using any ASM (we don't need as much perf) but we could have used some ASM.

The C part only represent 1% of the total number of lines written. But the speed gain was interesting.

Milkman Dan
9th November 2002, 02:25
Yes. If you need access to native code, JNI (Java Native Interface) is the way to go.

As far as Java in video goes, our MCF4Java developer was able to capture to Xvid through the Java Media Framework without trouble on his machine. And I know that IBM has a Java-based MPEG4 codec, although I don't know how it looks. But I've heard it performs just fine.


Originally posted by vlad59
As far as I know, it's not possible to add inline assembler in Java (mostly for the lack of portability).

But on the last Java project I've been working on. We were working on both linux and win32 and to gain some performance we used JNI to allow our java classes to acces to specific C (portable) dll (for win32) or lib (for Linux). Of course those C app weren't using any ASM (we don't need as much perf) but we could have used some ASM.

The C part only represent 1% of the total number of lines written. But the speed gain was interesting.

TheUnforgiven
10th November 2002, 00:05
don't forget that java rulez in server-side/database/web/e-commerce programming. thats what enterprises need.
but in system programming or speed its not the right choice. although through JNI it gives the same speed but this is just another layer of complexity if all u need is system programming u better go to cpp.

abo_alkeem
10th November 2002, 00:18
u can even program directx and opengl in java