Know about the difference between JAVA & JAVA SCRIPT

image

Beginners in programming, when they start to study Java, tend to have doubts about Javascript and vice versa. According to the popularity rankings of the TIIOBE and Github programming languages, both languages ​​are in the top 5! In addition, they are from the last century (the 90s) and due to antiquity, many of the differences between them were eliminated, and today both are much more similar. Here we already have the first successful lesson to be learned by us in relation to our career: learn from your colleagues the strengths and keep growing.

general definition

JAVA

Java is an object-oriented programming language that uses a hybrid compilation strategy: the original source code is compiled into an intermediate language ( bytecode ) capable of being interpreted by the JVM (Java Virtual Machine) specific to each operating system. Java was created as a cross-platform technology, allowing the writing of desktop, web, corporate, distributed, embedded and mobile applications. Over time, applets , created to “compete” with Javascript, were removed from browsers as they were considered a threat to web security.

Javascript

Javascript is a programming language that allows you to implement complex items in web pages. Although not originally object-oriented, in the ES6(ECMAScript2015) update, features of classes, objects, constructors, etc. But, are objects older than that in the Javascript world, or have you never heard of JSON?

The basic

Javascript is traditionally a weakly typed language. That is, a variable is not “stuck” to a specific type. For example, the following code is valid, so you can test it in your browser by going to the “Developer Tools” feature.

                        1let texto = 'hello world';
                        2typeof(texto);// vai informar "string"
                        3texto = 123;
                        4typeof(texto);// vai informar "number"
                    

In Java, although it is possible to use “var”, the type of the variable will be defined by the compiler. That is, it is just a way of summarizing the code, but “under the hood”, it remains the same.

With the addition of functionalities based on functional programming, Java started to allow the use of “ map, filter, predicate ” and other “darlings” already known in JS. For example, below we define a list of people and we want to display in uppercase the name of those over 60 years old.

                        1public class Aplicacao {
                            2    public static void main(String[] args) {
                            3        var pessoas = List.of(new Pessoa("Marcos", 65), new Pessoa("Luana", 32), new Pessoa("Breno", 45), new Pessoa("Ana", 72));
                            4        pessoas.stream().filter(p -> p.idade() >= 60)
                            5            .map(Pessoa::nome).map(String::toUpperCase)
                            6            .forEach(System.out::println);
                            7    }
                            8}
                            9record Pessoa(String nome, int idade) {}
                    

Myths and truths

From what we've talked about so far, Java and Javascript were born with different goals, they left many differences along the way, but they are not the same thing. So let's discuss some myths and truths?

1) Javascript is not for desktop applications - MYTH!

You must have already used the Visual Studio Code and Atom editors. If not, you may have already used Microsoft Teams or, most likely, Whatsapp Web. All these desktop applications are developed with Javascript! The myth that JS is not good for desktop applications is in the past. electronJS is a framework that allows you to write programs with HTML, CSS and JS that run on top of Chromium .

2) Javascript is not good for developing backend and REST APIs - MYTH!

It is true that the main objective of Javascript (pure!) is to develop rich and dynamic web pages. But, NodeJS revolutionized this scenario and brought a rich module management environment to the JS world. Proof of this is Angular (one of the most popular frameworks for web development) and ExpressJS . The latter is a popular framework for server-side development . Together they form one of the most popular (and coveted) development stacks : MEAN (MongoDB, Express, Angular, Node).

3) Java is Object Oriented, not Javascript - TRUE!

Although Javascript supports object orientation since ES6, this paradigm is optional, in JS it is very common to use “loose” functions. On the other hand, in Java, with the exception of primitive types, everything is an object! In Java we need to think about classes, interfaces, methods, inheritance all the time.

4) Writing in Java can be as easy as writing in JS - TRUE!

Here in Let's Code courses we present a modern Java, writing little, in a simple and performative way. Much of what is blamed on Java comes from programmers who are not responsible for the code they write. In recent years, Java has added features that use both the functional and reactive paradigms. Also, it is modernizing its syntax with the use of “var”, lambdas and “record classes” .

5) Java and Javascript together form one of the most disputed professional profiles on the market - TRUTH!

The programming market is “hot” for front-end, back-end, Javascript, Java developers… Now, imagine if you master both technologies? You will be a FullStack developer (see our blog article here) , one of the most coveted professionals on the market, where salaries for senior professionals exceed R$ 15,000! Interested and want to know more? Check out our Java course !