Jump to content
  • Advertisement
Sign in to follow this  
Romee

Switching from C++ to Java

This topic is 919 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

Hello everyone.

Some time ago I started learning C++ as my first programming language. I bought a book and
never regretted it. I nearly finished the book (I learned much, from variables to templates), but decided that I wanted to learn Java first,
because of two reasons: 1) I wanted to start making something 'more fancy' than staring at the console. I wanted to either learn web development or software (desktop GUI)/mobile app development. I chose the last one due to my second reason.
2) After next year I'm going to university and currently I'm thinking that I want to study Computer Sciences. On this particular university, the first language that is used is Java, so I think learning Java now, will help me then.

Now my first question is, what are some good resources (I prefer books) to learn Java, if you already know some fair amount of C++. With such a resource I mean a book that doesn't go over the basics of programming over and over, but goes a bit more in depth and maybe already introduces some GUI/mobile development.

My second question: currently there are a lot of books regarding Java Android development or Java (swift) GUI development. Would it be wise to start immidiately with such a book, or would it be better if I first go through a book I asked for in the first question?

If you want me to explain something about my question, just ask!

Many thanks, your help is appreciated.

Share this post


Link to post
Share on other sites
Advertisement

Now my first question is, what are some good resources (I prefer books) to learn Java, if you already know some fair amount of C++. With such a resource I mean a book that doesn't go over the basics of programming over and over, but goes a bit more in depth and maybe already introduces some GUI/mobile development. 

You should find Java much easier to learn than C++. Infact many experienced programmers would advice that beginners should learn Java first because some low level C++ details could be a distraction for beginners. But its good to read that you started with C++ and you are not beaten, instead your enthusiasm is still very high.

But I would also advice that, while a lot of C++ programming methodology would help you learn Java, you should try to learn Java with a fresh mind (rather than basing your learning on an assumed knowledge of c++). .... With a fresh mind but at the same time noting the concept and syntax differences as you go along to avoid future confusion. 

In fact when you start to add more languages to your arsenal you would find this comparisons instinctive and very useful

Anyway here is a resource list for you (sorry i'm short on actual books as I use online resource when it comes to coding, I'm sure another poster would add books to this list for you)

http://www.tutorialspoint.com/java/

http://www.cprogramming.com/tutorial/java/syntax-differences-java-c++.html

http://www.pickatutorial.com/tutorial/javaprogramming/

https://www.seas.upenn.edu/~cis1xx/resources/JavaForCppProgrammers/j-javac-cpp-ltr.pdf

http://www.slideshare.net/zblair/intro-to-java-for-c-developers

http://www.javacoffeebreak.com/articles/thinkinginjava/comparingc++andjava.html

My second question: currently there are a lot of books regarding Java Android development or Java (swift) GUI development. Would it be wise to start immidiately with such a book, or would it be better if I first go through a book I asked for in the first question?

I would advice that you should learn Java first before learning GUI development. The aim here would be to learn basics in steps to avoid distraction, at least at the start. Later there will be a lot of overlapping learning and you would still end up learning all. At the start, if you learn in steps, when you start learning swift for web applications, you will be able to go more in depth on the technical details 

 

Above all no matter how much you learned at the beginning there would always be room for improvement as you begin to work on projects

Share this post


Link to post
Share on other sites

Hello everyone.

Some time ago I started learning C++ as my first programming language. I bought a book and
never regretted it. I nearly finished the book (I learned much, from variables to templates), but decided that I wanted to learn Java first,
because of two reasons: 1) I wanted to start making something 'more fancy' than staring at the console. I wanted to either learn web development or software (desktop GUI)/mobile app development. I chose the last one due to my second reason.
2) After next year I'm going to university and currently I'm thinking that I want to study Computer Sciences. On this particular university, the first language that is used is Java, so I think learning Java now, will help me then.

Now my first question is, what are some good resources (I prefer books) to learn Java, if you already know some fair amount of C++. With such a resource I mean a book that doesn't go over the basics of programming over and over, but goes a bit more in depth and maybe already introduces some GUI/mobile development.

My second question: currently there are a lot of books regarding Java Android development or Java (swift) GUI development. Would it be wise to start immidiately with such a book, or would it be better if I first go through a book I asked for in the first question?

If you want me to explain something about my question, just ask!

Many thanks, your help is appreciated.

 

You are thinking wrong. (Well not wrong, just not right xD)

Nobody switches languages, I know bunch of 'em and it should be like that.

A language is merely a tool in your toolbox, the goal is to learn as many tools as needed to build what you need.

And usually some work will do fine with a tool (Like hammering a screw), but it is better to learn a suitable tool (Like learn how to use a screwdriver).

 

So your goal is to develop applications, both web and desktop.

Today you can select any lanaguae and build both web and desktop applications, both frontends and backends.(Front= Client,application, back= server).

 

I actually advice against Java, it's a nice language after all and has its potential and marketshare.

However, you'll find more common syntax among C languages such as C# and C++. so it's in general a better solution to new-comers. (It's my opinion, not fact, so do what you find better for yourself).

---------------------

My personal advice, You are already familiar with the basics of programming. It's time to learn a specific tool.

C# -WPF, C++ QT or Java swift are all nice, pick one (I recommend WPF-C#).

Just google X(topic) pdf and find a nice book, and learn.

Share this post


Link to post
Share on other sites

In a university you will learn the basics of functions, subroutines, lists, sorting, recursion, hashing and tree structures before diving into object orientation since there are many things that can go wrong with inheritance if you start to inherit something as soon as you want to reuse its code. I dislike using classes in C++ because abstraction without memory protection can make it harder to see why the application is crashing while a plain C subset would make it obvious but that might be because I learned C before C++.

 

For learning programming, Java would make it a lot more difficult to practice functional programming because Java outlaws global functions which is very annoying for functional purists and modular programmers. You might have a course in the first year where you have to write an operating system kernel without using dynamic memory allocation.

Edited by Dawoodoz

Share this post


Link to post
Share on other sites
Some advice for learning java after knowing c or c++ (well especially c) - get ready to be very frustrated/annoyed

As far as books go - im not really a firm believer in going through books - i feel they tend to make you program in some certain way that the author has deemed good.

I would suggest thinking of some small gui project you want to do in java - and then getting resources online as needed to do the thing that you are trying to do at the time - starting from getting a basic window open.

If you want to get a book for reference just about any java book will do. There is plenty of reference online though.

Share this post


Link to post
Share on other sites

 

 

 Java outlaws global functions

.

public static void someMethod(){
//stuff goes here
}


.

In a way, you can have 'global functions' in Java by declaring a method as static - it's not recommended practice, since it can lead to spaghetti code ...

Edited by Code Fox

Share this post


Link to post
Share on other sites

Assuming what you said you already learned programming before, you can start looking for books that are specific to mobile development with Java.

 

If you want to startup your Java language, you can just search for "java basic tutorial" in Google and learn it in a day or two to get familiar with the syntax and libraries they have, cause you already have experience in programming. Like WoopsASword said, programming languages are just a tool.

Share this post


Link to post
Share on other sites

I'm also advising against going for java instead of c++. Learning java after you know c++ will be super simple, and you'll also get a better understanding what's actually happening in the binary.

Share this post


Link to post
Share on other sites
1) I wanted to start making something 'more fancy' than staring at the console.

The philosophy of C++ is a little different from eg Java. C++ aims just to provide the core language. Everything else is provided by means of libraries. The disadvantage of that choice is that there is not a single C++ gui library (or single <anything> library), there are several different implementations of each kind of library that you need. Each implementation has its own strong and weak points, so you can pick the one that fits best with your problem rather than being stuck with a standard library that doesn't nicely fit in your problem.

 

For C++, I recommend the Qt library for GUIs. I mostly use it as a Gui library, but actually it's much more than that, it aims to provide cross-platform functionality for your application.

Documentation is just awesome.

 

2) After next year I'm going to university and ... so I think learning Java now, will help me then.

Java is a good language to know, although given your experience, I don't think there is a real need to learn it now. Most things will be easy.

 

Java has three big differences with C++. The first thing is that everything is a reference (to be precise, everything except native integer, boolean, and real numbers). This will cause quite a few "gotchas" for you. On the other hand, you get garbage collection for free, which is useful, but no destructors (well, they exist, but not useful like in C++).

 

The second thing is that Java aims to prevent you from making mistakes. Where C++ doesn't mind if you add code under a "return", in Java it fails to compile as unreachable code is forbidden (except with a "if false" for debugging statements, which imo then nicely demonstrates why forbidding unreachable code in a language is stupid).

 

Finally, it's very backwards compatible. There is a 64K limit everywhere, and its generics are severely limited compared with c++ templates (which arguably are a bit too flexible perhaps :P ).

 

You won't have much trouble with the other parts of Java.

If you feel restricted by Java one day, and you want to have a reference based language, you could look at Python or C#.

 

 

I don't know any useful Java books. (Java is not quite aimed at expert programmers with its protective nature, which likely doesn't help here.)

For documentation, I always use the official documentation at https://docs.oracle.com/javase/tutorial/    It's nice and compact, and explains things well.

Edited by Alberth

Share this post


Link to post
Share on other sites

I wanted to start making something 'more fancy' than staring at the console.

I'm not sure why you think that means going from C++ to Java although you did have other reasons too.

As another poster said, going from console to GUI means using a library.

As a windows-fanboy (lol) it meant learning the win32 API in my case. So rather than #include <iostream> etc you #include <windows.h>, link to kernel32.lib, user32.lib, gdi32.lib and in some cases more libraries the fancier you go. When you start a new visual studio project most boilerplate is already done for you as well.

If cross-platform is paramount to you then of course ignore my post and use Qt like the other poster recommended.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!