# My school seems to mainly teach java

Next semester I plan on taking a comp science class, and my school seems to mainly teach java. I always considered the standard language to be c++, I think it was a few years ago here, but I guess they recently switched over.

My questions are:

Are there any major differences between Java and C++, as in if I was able to program decently in one, would I be ok in the other?

Also, I plan on continuing to use linux. Is this going to create a problem with Java programming?

One more thing. I will be mainly making simple math learning programs (probably with heavy graphics), will this be ok with both? I am guessing yes, maybe one is better than the other? My high school math teacher was really into Java, so I am going to assume that it works well enough for most things.

Thanks.

Related Computing and Technology News on Phys.org
chroot
Staff Emeritus
Gold Member
Java is basically a "regularized" C++. It maintains all of the core C++ concepts, but avoids all of the syntactic and debugging nightmares that are inherent in C++. The syntax is similar, but the structure of the language is rather different. I consider them to be closely related languages.

Java will run anywhere, including on Linux.

You can do anything in Java, short of writing a device driver perhaps.

- Warren

Thanks, sounds good!

dduardo
Staff Emeritus
Its a shame the college board got rid of the C++ curriculum. I think it is important for students new to programming to understand low level concepts. People are getting too reliant on managed code. I remember the day when you were thrilled to have 16k of memory and wrote highly optimized code.

chroot
Staff Emeritus
Gold Member
Let's not get into a language debate here, dduardo.

- Warren

One more question. The "Java Class" thread says that I need to download J2SE 1.4.2 SDK; however, I do not see one listed as that, I do see J2EE 1.4.2 SDK, though. I am going to assume that is what I need. Also, I do not have java installed at all on my computer, not that I know of at least, will I need to install the J2SE 1.4.2, or does it come with the sdk? Thanks.

No, you want J2SE 1.4.2 SDK. Try here:

The SDK includes everything you need.

chroot said:
Java is basically a "regularized" C++. It maintains all of the core C++ concepts, but avoids all of the syntactic and debugging nightmares that are inherent in C++. The syntax is similar, but the structure of the language is rather different. I consider them to be closely related languages.

Java will run anywhere, including on Linux.

You can do anything in Java, short of writing a device driver perhaps.

- Warren
Some differences between Java and C++

- Java is a pure object oriented language, while C++ can use a hybrid of OO and procedural/imperative constructs (global functions, structs, etc.)

- Java is based on a virtual machine. Compiling a Java program does not produce a native, OS depedent executable. It produces bytecode which can they be interpreted by a Java bytecode interpreter. This makes Java somewhat slower and bigger than C++

- C++ has multiple inheritance while Java does not -
althought it does have interfaces, which a class can implement many of. These are similiar to "pure virtual" classes in C++ - they have only function declarations and no instance variables

- Java has no header files - definitions are never separate from declarations (with the exception of interfaces as noted)

- Java does not have compiler directives (#define, #ifdef, etc.) . There is no "preprocessing" stage. This can really make C++ code a mess - whey you have lots of #ifdef's for portability purposes

- C++ has templates while Java does not: these allow you to define a "parameterized" data structure - for instance if you have a stack, and you want to have a stack of integers and a stack of characters, you could write a class that handled stack operations with a template, and declare something like stack<int> int_stack and stack<char> char_stack. This would ensure type safety in your data structure, something that would be impossible to guarantee with Java for a generalized data structure ( You would have to have your class operate on Object(the parent of all classes) or some other parent class, but then you when you did the operations, they would always "cast down" to object upon manipulation).

- I hate to be subjective, but I feel that Java's GUI functions are 5x as easy to use as OS implementations in C++ such as MFC on windows and GTK, QT on linux.

- As noted, the syntax in Java is much cleaner and regular

Last edited:
Plus:

- Interpreted Java is much slower than C++ code
- Java is not only a programming language, but also a set of libraries, and a technology

I agree with dduardo that universities should not discard C++ which offers lower level programming, and necessarily, more power to the programmer.
Knowing C++ it would have been very easy to learn Java in a few weeks.
In my university programming was introduced with C++ and later we had a module for Java Programming. But I had learnt Java independently knowing C++ earlier.

In my opinion Java syntax is quite troublesome and I don't like the lack of .hpp files.

danne89 said:
In my opinion Java syntax is quite troublesome
How so? Nothing wrong with that, I'm just wondering why .

Edit: gnome, wouldn't it be better for him to get the latest version of the JDK (well, J2SE 5.0)?

Last edited:
graphic7
Gold Member
Edit: gnome, wouldn't it be better for him to get the latest version of the JDK (well, J2SE 5.0)?
That was my thought, as well; however, the book and/or instructor may be making use of deprecated functions in J2SE 5.0 that may not be so deprecated in the J2SE 1.4.2 release (if there are any - I'm not sure).

Damn you graphic, you're a smart one .

chroot
Staff Emeritus
Gold Member
so-crates said:
Compiling a Java program does not produce a native, OS depedent executable.
Such compilers exist; they just don't come with the JDK.

- Warren

chroot
Staff Emeritus
Gold Member
ramollari said:
- Interpreted Java is much slower than C++ code
This is a myth; the actual difference in speed depends strongly on what you're doing. If you're doing a lot of math in a loop, e.g. scientific computing, Java will be almost as fast as C++, and in some cases a bit faster. This is thanks to the JIT, of course.

- Warren

chroot said:
Such compilers exist; they just don't come with the JDK.

- Warren
This wouldn't have anything to do with JNI would it? I dunno about JNI, so..

chroot
Staff Emeritus
Gold Member
No, Nylex, I'm talking about commercial products, e.g. Jet:

http://www.excelsior-usa.com/jet.html

The JNI (Java Native Interface) is just the mechanism by which a Java program can interface with code written in other languages.

- Warren

Nylex said:
How so? Nothing wrong with that, I'm just wondering why .

Edit: gnome, wouldn't it be better for him to get the latest version of the JDK (well, J2SE 5.0)?
Maybe because I'm a C++ programmer by nature, I prefare shorter keywords, like in C++, and think it's iritating to write "public class HelloWorld extends Applet". Public should be default and the extends keyword seems unneccesarily long to me.

Warren: ahh ok, sorry!

danne89: how do you do inheritance in C++? I don't think I got that far when I tried learning it. I prefer seeing the words myself, the whole :: thing in C++ is a bit confusing (I can't even remember what it's for!).

chroot
Staff Emeritus
Gold Member
Nylex, like this:

Code:
class Square : public Shape
{
...
}
- Warren

This makes Java somewhat slower and bigger than C++
Compiled Java programs are much smaller than their C++ equivalents.
Java is slower, but I don't find that an issue. The most annoying I think is the loading time (time it takes for VM to start, load class files and start execution).

el-half said:
Compiled Java programs are much smaller than their C++ equivalents.
Java is slower, but I don't find that an issue. The most annoying I think is the loading time (time it takes for VM to start, load class files and start execution).
The VM is only required for interpreted Java programs. If you use JIT compilers, there is no need for the VM and dynamic loading of class files.

chroot said:
This is a myth; the actual difference in speed depends strongly on what you're doing. If you're doing a lot of math in a loop, e.g. scientific computing, Java will be almost as fast as C++, and in some cases a bit faster. This is thanks to the JIT, of course.
JIT compilers are part of the solution, but they are not optimized enough to compete with C++ compilers. The future however will gradually bring better compilers for Java.