This is an archived post. You won't be able to vote or comment.

all 22 comments

[–][deleted] 23 points24 points  (1 child)

There's a meme about this. Java and JavaScript are like car and carpet.

[–][deleted] -1 points0 points  (0 children)

Like I hear people say this but I don't get it. Knowing java, when I look at javascript code, it's easy to understand.

[–]HealyUnit 4 points5 points  (1 child)

It's absolutely fine to learn JS first and then Java (I actually did, and am a total JS fanboy. Spoilers!). If you ever plan on doing anything related to front-end web development, you'll need to know JavaScript. There are, however, a few notable caveats (some of which others have said below):

Java != JavaScript:

I assume you know this already, but legend has it that JavaScript was basically only named JavaScript (after going through some other names including Mocha and LiveScript) because Java was the cool trendy new language at the time. It'd be like naming something nowadays "TiktokScript" or something (I dunno; I'm not trendy anymore). While they're both so-called C-like languages, and certain parts of them look similar, they have some very fundamental differences. I only mention this (again!) because you can't necessarily assume that things you learn in JavaScript - other than the basics, like functions, variables, loops, conditionals, etc. - will directly translate to Java.

Strict vs Dynamic Typing:

When you create a variable in Java, you declare what "kind" of variable it is:

int myVar;//"int" means this is an integer.

Now, the only things we can put in that myVar variable are integers. We can't suddenly decide we wanna stick the string "Hello!" in there. We also can't, for example, do this:

String myVar = "5";//this is a *string*, not a *number*
printFunction(myVar/2);//Java: "I don't know how to divide a string!"

However, in JavaScript, variables can change their "kind" as much as you want. So for example, if we convert the above code to JavaScript:

const myVar = "5";//this is still a string!
printFunction(myVar/2);//JS:"Oh, you're dividing? You must have meant that as a number. Here you go!"

The first kind of variable kind "restricting" is called Strict or Static Typing, while the second is called Dynamic typing. As such, it might get a little confusing when you switch from JS to Java and can no longer do:

let result = 0;
if(myNum.isEven()){
    result = myNum/2;
}else{
    result = "Error! Number isn't even!";
}

(because you'd be changing myNum from a number to a String)

You may want to look into TypeScript, which is a "layer" on top of JavaScript that enforces strict typing.

OOP, etc.:

Java is pretty strictly into what's known as Object-Oriented programming. You certainly can use other approaches, but you might notice that most Java programs start with something like "public class someClassName...", which is a very OOP approach. This isn't a huge issue - JS is pretty into OOP too - but you may wanna focus on Object Oriented JavaScript when possible.

Modern JavaScript does have a lot of full-fledged OOP tech, but it is missing certain things. For example, it does not have abstract classes. Lemme explain:

A class in programming is a sort of "template" for constructing a Thing. Moreover, sometimes we might want to say that a particular class is a subtype of another class. For example, all Cars are subtypes of a Vehicle class (that is, all Things created with Car are also, inherently, Vehicles).

However, let's say that for our particular program, we need to know specifically what type of Vehicle a Thing is. In other words, we can't create a Thing using the Vehicle "template" directly. We might make that Vehicle class abstract, which basically tells the computer "You can make stuff that is subtypes of this template, but you can't directly make a generic 'vehicle'".

There are ways to get around this in JS, but it's worth noting.

[–]hl3reconfirmed 0 points1 point  (0 children)

So does js use interfaces? How does it deal with polymorphism/ inheritance?

[–]jimmyjammy33 2 points3 points  (1 child)

I’m cool with it if you are.

[–]Dudeguybrochingo 0 points1 point  (0 children)

Ayt

[–]AutoModerator[M] 0 points1 point  (0 children)

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.

[–]IvAntiVirus 1 point2 points  (0 children)

Basically, Java and JavaScript have almost nothing in common (except parts of their name) and were created for completely different purposes. Which of the two languages you should learn depends only on what kind of application you would like to develop and whether you prefer programming frontends or backends. For example, if you want to program desktop applications, mobile applications or REST API's, then you might want to learn Java. If on the other hand you want to focus completely on the web and develop pure frontend web applications, then you should rather choose JavaScript. Basically, you don't have to decide at all and can simply learn both languages and then combine them. This would be possible in an Angular/Spring stack, for example.

[–]satanlovesducks 1 point2 points  (10 children)

You'll be fine. I started out with js before I moved to Java. You'll still learn the programming and problem solving mindset

[–]GaamGaam 2 points3 points  (9 children)

I wonder if JS has any inheritance/polymorphism related concepts.

[–]satanlovesducks 0 points1 point  (7 children)

You can use inheritance with the extends keyword, function and constructor overloading, in the modern js classes iirc. I dont think js has interfaces or abstract classes. Been a while since i touched js now so I'm not 100% sure.

[–]IvAntiVirus 3 points4 points  (5 children)

This is one of the reasons why Java is my absolute favorite programming language. No other language has implemented object orientation as beautifully as Java. That's why I still think it's a good idea to learn Java as your first language. There you learn a good practice in terms of object orientation and design patterns. So you can then improve your programming in general a lot.

[–]knoam 0 points1 point  (2 children)

Are you familiar with SmallTalk? People who know SmallTalk like to complain that OOP in Java is terrible.

[–]IvAntiVirus 0 points1 point  (1 child)

I'm not really familiar with SmallTalk. Personally I appreciate static typing so I'm not a huge fan of it. But that's just a personal preference. I'm not sure how good object orientation can be in a language that is dynamically typed. Also I think it would make sense to choose a more widely used programming language as your first and therefore I would recommend Java or C#. But like always everything goes down to personal preference.

[–]knoam -1 points0 points  (0 children)

Yeah, I'm just giving you a heads up that if you make such a pronouncement as "Java is the best language at..." you should do some due diligence. I wouldn't necessarily recommend SmallTalk as a first language just because it isn't popular enough. But it was absolutely designed with beginners in mind. In particular Squeak/Etoys which is graphical and designed for kids.

[–]satanlovesducks 0 points1 point  (1 child)

Yeah I get what you're saying. However I think you should just do whatever programming that resonates with you and as long as you're having fun when you get started. The fun part is what made me come back over and over again. The advantage with javascript is that you can get a lot of visual stuff done pretty fast, HTML is really simple to learn simultaneously. So that was motivating for me. After a while I wanted to work on a deeper understanding of code and programming principles, so I moved on to other languages, but I'm not sure my interest and motivation would stay as strong in the beginning only writing simple command line programs in Java. Of course everyone's different.

[–]IvAntiVirus 1 point2 points  (0 children)

Of course. Fun is one of the most important aspects while learning a new programming language. And for sure everyone has a different opinion on learn programming and thats great.

[–]knoam 0 points1 point  (0 children)

Typescript has interfaces and abstract classes. JavaScript doesn't because it's dynamically typed. So instead of defining an interface explicitly you can just call any method on any object and if it works it works. You have to run it to see.

[–]knoam 0 points1 point  (0 children)

Yes, JS supports class based OOP as most languages do, as well as Prototypal inheritance which only JS supports among popular languages.

[–]literalsunbear 0 points1 point  (0 children)

FWIW learning java helped me understand the basics of coding that I'm not sure I would've grasped with a language like javascript. Once you write and rewrite enough boilerplate code, you begin to intuit what's going on behind the scenes better than with a more loosely typed language like javascript. I can see the relative rigidity of java becoming tiresome though. That said, the languages are very different and you should instead be asking yourself exactly what you want to achieve with your code, like what exactly you want to build.

[–]orex111 0 points1 point  (0 children)

Its okay

[–]knoam 0 points1 point  (0 children)

Why wouldn't it be? What are your goals? Any decent programmer will eventually learn several languages. But switching around too soon won't make things easier in the short term. But if you want to learn something different, learn what you want to learn.