r/learnjava • • Feb 21 '21

Coming from python, what are a few things I should know before learning Java?

I currently know only python and want to expand my knowledge of languages, and thought java would be a good pick. Any things I should know before learning it?

49 Upvotes

28 comments sorted by

•

u/AutoModerator Feb 21 '21

It seems that you are looking for resources for learning Java.

In our sidebar ("About" on mobile), we have a section "Free Tutorials" where we list the most commonly recommended courses.

To make it easier for you, the recommendations are posted right here:

Also, don't forget to look at:

If you are looking for learning resources for Data Structures and Algorithms, look into:

"Algorithms" by Robert Sedgewick and Kevin Wayne - Princeton University

Your post remains visible. There is nothing you need to do.

I am a bot and this message was triggered by keywords like "learn", "learning", "course" in the title of your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

36

u/desirecampbell Feb 21 '21
  • Java is strongly typed - meaning you have to declare the datatype for every variable.

  • Semicolons.

8

u/MAGICJJAFFFF Feb 21 '21

Yeah from what I've seen so far there are quite a few semicolons. Thanks for your help

10

u/Migeil Feb 21 '21

Java is strongly typed

Java is indeed strongly typed, but so is Python (for most definitions anyway, as there isn't one single definition).

You mean to say that Java is statically typed, whereas Python is dynamically typed.

meaning you have to declare the datatype for every variable

This isn't the definition of static typing. Take Haskell for instance. It is a statically typed language, but has full type inference, meaning you don't have to declare any types if you don't want to.

The difference is that Java has a compilation step before being executed. During that compilation, Java code is type checked to make sure no operations are performed on types not supporting said operations. That's static typing. Python doesn't have this, it only checks the code right before executing, possibly resulting in TypeErrors during runtime.

51

u/desrtfx Feb 21 '21

The best advice that can be given is to start completely from zero. Java is a different beast to Python.

Don't even try to compare the two languages.

11

u/[deleted] Feb 21 '21

Semicolons. Semicolons will be the end of you in the beginning.

10

u/H34dsp1nns Feb 21 '21

Curly braces for blocks, semicolons, and declaring the type of your variables. Also, you have to compile your programs before you can run them. Your .java files become .class files once compiled and can then be run. Try catch instead of try Except.

9

u/schmidtforge Feb 21 '21

It can be difficult. I’m still in school so take this with a grain of salt. But I learned Python first then we went into Java and it took me a while to switch my brain to understand Java. There is a lot more typing involved. Example print statement. Python: print() Java: System.out.println ();

6

u/[deleted] Feb 21 '21

Typing is one thing, but java is far more specific than python, the System.out.<> has a lot of print methods that do specific tasks... It was a challenge for me to understand which one exact method I need for my task when I first started with java coming from python...

Also I use intelliJ so typing "sout" gives me System.out.println(), sout is less alphabets than print() in python.

But yes I agree it can be difficult

3

u/griefwatcher101 Feb 21 '21 edited Feb 21 '21

Here to add that NetBeans also has the sout-TAB shortcut.

For Eclipse, it’s “syso” or “sysout”, then Ctrl + Space.

I use NetBeans, had to google the Eclipse one lol

1

u/schmidtforge Feb 22 '21

Ah ok I’ll have to remember that thank you. How do you like net beans?

2

u/griefwatcher101 Feb 22 '21

It’s just what I started on a couple years ago when learning Java from Mooc.fi. But from what I’ve read about the others, you can’t really go wrong with any of the three. IMO, the differences are too small to get worked up over. Just get familiar with one of them and you’re golden. They’re all used in professional development.

Edit: as an engineer, I’ve really been meaning to learn python! Any advice?

2

u/schmidtforge Feb 22 '21

I got ya, my school has us working with eclipse so that’s what I’ll stick with regardless.

Python is great and pretty easy to learn honestly. I bout python crash course book on Amazon and zero to hero python by Jose something from Udemy. Two great resources that really helped me out

2

u/schmidtforge Feb 21 '21

And you have accessors and mutators different classes that interact. It seems way more in depth

13

u/Hullo99 Feb 21 '21

Java is strictly object oriented. Unlike Python, every line of code must be contained within a class. If you don’t know what object oriented programming is, I would look into that first.

5

u/hugthemachines Feb 21 '21

I can tell you a thing that got me a bit confused in the beginning. When you make your programs you will have a main class, that is static. Not all other methods are static and if you want to run a non static method from the main method you have to first make an object(/instance) out of the class and then you can run the methods of that object.

4

u/[deleted] Feb 21 '21

Java’s concurrency model is one of the best ones out there. I like Python for some things but its concurrency model is absolute garbage.

1

u/sinnerou Mar 06 '21 edited Mar 06 '21

I don't understand this. I'm a Java newbie but from what I have seen of its concurrency model it is thread based instead of coroutine based which I don't see as superior. 99% of what I want to do with concurrency is manage non-blocking io and coroutines are better for that. I was actually looking for a Java coroutine implementation if you happen to have a recommendation that would be helpful.

Python doesn't support parallelism at all due to the GIL but that is a different paradigm and that limitation is mitigated with multi-processing/messaging. I never found that particularly limiting but I imagine it could be if you were writing an application that is meant to live on one and only one machine.

1

u/[deleted] Mar 06 '21

It depends on what you’re trying to do. In high throughput applications, threads are used because they allow true parallelism. For what I do throughout matters and coroutines do not work.

Regarding your question about Java coroutines, I have not a clue. I’ve never needed them.

1

u/Grimsqueaker69 Feb 22 '21

Rookie question here, but what is a concurrency model?

2

u/[deleted] Feb 22 '21

To put it simply, it’s the way Java handles multithreading. Java was designed from the ground up to support multithreaded programs and it uses whatever native threads the OS has by default (in Unix you get posix threads). Python has a global interpreter lock that makes its threads very inefficient. Unless you’re doing some kind of IO that gets handled by the OS, a Python program can only ever execute on one CPU core at a time. Java programs can achieve true concurrency (run on multiple cores) without having to do IO.

3

u/import_numpy_as_np Feb 21 '21

The concept of interfaces took me forever to understand when learning Java. Started with Python for about 2-3 years and there’s not really anything to compare it to. But like others have said, I would get a solid grasp of OOP before diving into Java.

3

u/[deleted] Feb 22 '21

Java is going to be a different thing all together. Don’t try to compare just learn from the ground up. Conceptualizing java classes is weird at first, but once you get it it’s a super solid language.

2

u/[deleted] Feb 22 '21

In Java you have to be very explicit about things that are handled "under the hood" in Python, like types, access, objects and what is stored in memory and how it's passed between parts of your program. Java is less of a black box.

1

u/boriisi Feb 21 '21

java is pretty easy if you know basic syntax, rest of it is in the modules just like most of other languages

1

u/poply Feb 22 '21

For me, the hardest thing to work around when picking up Java has been my reliance on list comprehensions. Knowing how to make use of streams can help a lot.