Java
Java is an object-oriented programming language and has a virtual machine platform that allows you to create compiled programs that run on nearly every platform. Java promised, “Write Once, Run Anywhere”.
Features of Java are as follows:
- Platform Independent: The compiler converts source code to bytecode and then the JVM executes the bytecode generated by the compiler. This bytecode can run on any platform.
- Object-Oriented Programming Language: Organizing the program in terms of a collection of objects is a way of object-oriented programming, each of which represents an instance of the class. There are 4 pillars of OOP’s concept:
- Simple: Java is one of the simple languages as it does not have complex features like pointers, operator overloading, multiple inheritances, and Explicit memory allocation.
- Robust: Java language is robust which means reliable. It is developed in such a way that it puts a lot of effort into checking errors as early as possible, which is why the Java compiler can detect even those errors that are not easy to detect by another programming language.
- Secure: In Java, we don’t have pointers, and so we cannot access out-of-bound arrays i.e. it shows ArrayIndexOutOfBound Exception if we try to do so.
- Distributed: We can create distributed applications using the Java programming language. Remote Method Invocation and Enterprise Java Beans are used for creating distributed applications in java.
- Multithreading: Java supports multithreading. It is a Java feature that allows concurrent execution of two or more parts of a program for maximum utilization of the CPU.
Example: This is the basic Java program.
// Importing required classes
import java.io.*;
// Main class
class GFG {
// Main driver method
public static void main(String[] args)
{
// Print statement
System.out.println(
"Welcome to w3wiki Learning");
}
}
Output
Welcome to w3wiki Learning
Difference between Java and JavaScript
Java is a statically typed, object-oriented programming language for building platform-independent applications. JavaScript is a dynamically typed scripting language primarily used for interactive web development. Despite similar names, they serve different purposes and have distinct syntax, runtime environments, and use cases.