C++ transition to Java

JC0133

Senior member
Nov 2, 2010
201
1
76
I am taking my 2nd level programming class. I took C++ last semester. It was basically C++ level one class. However, the school I am going to, took out the next level C++ class and it is now the Java level 2 class.

I have never studied Java before. My professor said switching over to Java is an easy transition and I don't need to worry about it.

I am just trying to get feedback to see if this is a smart move or should I take the first level intro to Java class first?
 

MagnusTheBrewer

IN MEMORIAM
Jun 19, 2004
24,122
1,594
126
It depends on you and how you learn. It's a common attitude in CS across the country to view one programming language as easily transferred to another.
 

sdurant

Junior Member
Aug 10, 2011
3
0
0
If you have no experience with object oriented programming, you have a lot to cope up first. From things like inheritance, there are some more power to your language now.

In java for example, you can create your own class that you could extend on another class so that it gets the functions you wrote originally. It gives dimension to what you are doing as you can write, to put it simply, what could be your own variable for later use.

Being a computer science major, your learning curve with this programming languages should be fast and effective.
 

veri745

Golden Member
Oct 11, 2007
1,163
4
81
If you have no experience with object oriented programming, you have a lot to cope up first. From things like inheritance, there are some more power to your language now.

In java for example, you can create your own class that you could extend on another class so that it gets the functions you wrote originally. It gives dimension to what you are doing as you can write, to put it simply, what could be your own variable for later use.

Being a computer science major, your learning curve with this programming languages should be fast and effective.


The same is true of c++, though. If you're familiar with these concepts in c++, transferring them to Java is not a big deal.
 

Cogman

Lifer
Sep 19, 2000
10,284
138
106
If you really understand and know how to use C++, it won't be hard at all. If you struggle with a lot of the basic concepts, you're millage may vary.

Java is easier in the sense that making something like a memory leak is hard to do. It is harder in the sense that from the get go, you have a HUGE amount of libraries and functions that you can work with. Getting the core of java down is difficult because the core of java is very large.

So if you didn't find C++ difficult, you won't find java difficult. If you did find C++ difficult you MAY find java difficult (depending on how well you learned C++).
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,645
4,588
75
I went from C++ to Java, too, although very late in college. There are two main things you'll find very different. The first is, as Cogman mentioned, the "HUGE amount of libraries and functions that you can work with." I'd never used the C++ STL; if you have, you have an advantage. Basically, look here. The essential packages are probably java.lang (automatically included) and java.util. If that makes sense to you, you're halfway there.

The second, more fundamental thing is the multiple inheritance system in Java. You can't inherit two classes, but you can create things called "interfaces", abstract classes with no functions implemented. You can inherit one class and any number of interfaces. Oh, and if you know what "virtual" means in C++, everything's virtual in Java. If that makes sense to you, you're probably ready.
 

Aikouka

Lifer
Nov 27, 2001
30,383
912
126
Oh, and if you know what "virtual" means in C++, everything's virtual in Java. If that makes sense to you, you're probably ready.

I assume you're referring to methods in Java and how they can be overridden by a class that implements the class containing the specific method. Although, it's worth noting that a method with the final qualifier cannot be overridden. I've always seen it recommended to specifically declare a method as final if you don't want it overridden... or just make the class final (which means you can't implement it).
 

KIAman

Diamond Member
Mar 7, 2001
3,342
23
81
The concepts are the same for both languages. The more difficult portion of jumping from C++ to JAVA is learning the packages, features and limitations. You might find a situation that should be really easy in C++ that takes a little extra work in JAVA and something that was hard in C++ that is a one liner in JAVA.

One large caveat for JAVA is that it is a managed code vs C++ which is unmanaged. If you are used to seeing compiled code, get used to seeing bytecode.
 

JC0133

Senior member
Nov 2, 2010
201
1
76
Thank you all for you input, this was actually helpful. I will take the next level Java class. I have confidence in myself.
 

Pia

Golden Member
Feb 28, 2008
1,563
0
0
Good call. Java is very, very easy for someone who already knows C++.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
I was bored in Java 1 class when I took it after working with C++ for 10 years.

Level 2 was interesting but I really needed level 3 - which was only sporadically taught.
 

AyashiKaibutsu

Diamond Member
Jan 24, 2004
9,306
4
81
Java is really easy to learn. Whatever you're trying to do look at their library documentation to see if they already have a class implemented.
 

hooflung

Golden Member
Dec 31, 2004
1,190
1
0
The biggest thing I've noticed about Java is that despite being a full featured programming language it works more like a scripting language. Not in power mind you but in the context of the JVM and the platform it is on.

To get a good idea of what I am saying take building stand alone applications. Anyone can do it with Java with or without GUIs. It is fast, and I consider it fun. The moment you want to go full force and deploy said application the real difference between .NET/C/C++ become clear.

Classpaths, runtime executables and the like aren't for the non computer oriented. Companies spend thousands of dollars on build systems to do this while the C/C# world have widely available options that are open source projects. There ARE good free ones for Java now but the best ones are expensive.

Where as a .exe can just run java programs need the JVM. This is where things work like scripting languages. Not that it is a hinderance, and in fact can be robust if used correctly, but it is something that makes going from C++ to Java weird.

As for the language just remember Java is always pass-by-value.

So

foo(Planet planet) {
planet.setName('Earth'); //will set the name of the object at the reference's value

Planet planet = new Planet('Red Planet');

planet.setName('Mars');// will modify the new object which has a new pointer reference and it will NOT overwite the original object's name of "Earth".
}
 
Last edited: