This is the fifth day of my participation in Gwen Challenge
Over time, the world of software programming has evolved rapidly and provided many programming languages. You’ve probably heard of the Java and JavaScript programming languages, their names sound similar, and you might be confused about whether they are different names for the same language or different. After this nanny-level and dry article, I’m sure all your confusion will go away.
What is Java?
Java is an OOP (Object-oriented programming language), class-based, multi-platform programming language with a VM (virtual machine) platform. OOP is a programming paradigm based on the concept of objects that contain code and data. Virtual machines help you create compilers that run flexibly on any platform, anywhere. Java calls this concept write once, run anywhere.
How do I get started writing code in Java
You need to follow two simple setup steps:
Download and set up the Java SE development kit. 2. Select any editor you prefer
As a beginner I suggest you choose Notepad because it is the most basic. Other editors or ides will work, just try not to be too fancy, because you want to focus on the basics now.
Write a simple code in Java
Let’s look at how to simply print a Hello World program in Java.
// A Java program that prints a simple string (character input type, such as HelloWorld),
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!"); }}Copy the code
Code instructions
- The first line you see begins with a generic comment statement that describes the functionality of our program. You can see it with
//XXX
At the beginning, it is the symbolic representation of a single-line comment (limited to single-line comments). - Before we move on to the next line, let’s explore the braces. Curly braces
{
Refers to the beginning of the corresponding class or function, and braces}
It’s where it ends. class
An object constructor, or simply, the blueprint from which we create the object. Each class has a name, and in our case, our class name isHelloWorld
.- Now the main way to get into our program, namely
public static void main(String[] args)
Copy the code
Now let’s break it down into pieces:
1. Public means that anyone can access this method from anywhere, which means that it is available globally.
2. Static is a keyword that simply defines the method as static and cannot be changed.
Void is also a keyword that refers to a method that does not return anything.
4. Main refers to the Java main method name.
5.String args[] refers to the arguments passed to the main method. Args refers to the name of the string. You can name args with any other string name, this is just the standard name used for it.
6.System.out.println(“Hello, World!” ); This is our Hello, World! The actual output line printed. Individual statements and variable declarations end with a semicolon.
Does this sound complicated for a program that just prints a single string on the screen? This is true, and one of the reasons why learning JavaScript is a better option for beginner developers.
What is JavaScript?
JavaScript is a lightweight, high-level scripting language commonly used to make web pages dynamic and interactive. It can add dynamic text to HTML and is known as a browser language. We’ll discuss its detailed features in a comparison with Java.
How do I get started coding in JavaScript
You only need two things to start using JavaScript:
1. Browsers (Google Chrome, Safari, Firefox, Internet Explorer, etc.)
2. Editors (Notepad, VS Code, Atom, etc.)
How to write your first JavaScript program
Let’s see how to write our first Hello World program in JavaScript.
// A JavaScript program that prints a simple string (character input type, such as HelloWorld),
console.log('Hello World');
Copy the code
Code instructions
- The first line is also the same single-line comment, as we saw earlier in Java programs.
- In JavaScript, we simply use statements
console.log
Copy the code
Print anything on the console (an object that provides access to the browser debugging console). In short, you can view it when:
You right click the mouse
2. Click Check
3. Select the Console TAB
4. View recorded statements on the console
Now tell me, how much easier is it compared to Java?
You’re right, they’re not even remotely similar.
Key differences between Java and JavaScript
We can note the following major differences between the two languages:
- Programming paradigm: Java strictly follows the object-oriented programming paradigm, while JavaScript follows multiple paradigms, including object-oriented programming, procedural, and scripting languages.
- Code execution: Java applications have the flexibility to run on the JVM (Java’s virtual runtime environment), whereas JavaScript only runs in a browser-specific application-specific environment.
- Objects: Java objects are purely class-based, whereas JavaScript objects are prototype-based.
- Type checking: Java ensures that its variables and functions are strongly typed before compilation, which makes it very unlikely that they will run at run time or compile time. However, JavaScript is weakly typed, and the type of a variable is unknown until compiled, thus increasing the chance of runtime or compile-time errors.
- File extensions: Java has a. Java file extension, while JavaScript has a. Js file extension. (By the way, we often say that Js is the same as JavaScript, but one is the full name and the other is the abbreviation.)
- Multithreading: Java supports multithreading (executing two or more threads at the same time to maximize CPU utilization), while JavaScript does not.
- Memory usage: Because Java has a lot of content, it takes up more space and JavaScript takes up less space.
- Language dependencies: Both languages can work independently or in pairs with other languages.
- Concurrent approach: Java takes advantage of its multithreading capabilities and has a thread-based approach, while JavaScript follows an event-driven approach.
- Performance: Because of its participatory nature, scripting languages are always more efficient than pure programming languages, and as a result, Java is less efficient and slower than JavaScript.
Similarities between Java and JavaScript
What’s the difference? Now let’s also explore what the two have in common.
- Browser compatibility: Both languages can run in browsers.
- Support: There are many online support communities for both languages.
- Syntax and programming concepts:
Although both are different languages, they share the same core programming concepts and some syntactic concepts, such as:
1. Use programming loops, such as for loops and while loops. 2. Use conditional statements such as if and else if. 3. Use Math libraries like Math.pow. 4. Common shared syntax symbols, such as code block delimiter {}, code statements ending with a semicolon.
- Similar names: Oddly enough, both Java and JavaScript have “Java” in common, even though the two languages are completely different.
conclusion
To sum up, Java and JavaScript are two different languages. Some of the similarities between them come primarily from core programming principles, but other than that, they are two different worlds with similar names, but the main difference lies in each other.
More related articles and my contact information I put here: gitee.com/haiyongcsdn…
And finally, don’t forget ❤ or 📑