JavaScript Vs Java
JavaScript Vs Java
Java JavaScript
Java is a strongly typed language JavaScript is a loosely typed
and variables must be declared first language and has a more relaxed
to use in the program. In Java, the syntax and rules.
type of a variable is checked at
compile-time.
Java is an object-oriented JavaScript is a scripting
programming language primarily language used for creating
used for developing complex interactive and dynamic web pages.
enterprise applications.
Java applications can run in any JavaScript code used to run only in
virtual machine(JVM) or browser. the browser, but now it can run on
the server via Node.js.
Objects of Java are class-based JavaScript Objects are prototype-
even we can’t make any program in based.
java without creating a class.
Java program has the file extension JavaScript file has the file extension
“.Java” and translates source code “.js” and it is interpreted but not
into bytecodes which are executed compiled, every browser has the
by JVM(Java Virtual Machine). Javascript interpreter to execute JS
code.if compile time
Java is a Standalone language. contained within a web page and
integrates with its HTML content.
Java has a thread-based approach Javascript has an event-based
to concurrency. approach to concurrency.
Java supports multithreading, which JavaScript does not support
allows multiple threads of execution multithreading, although it can
to run concurrently within a single simulate it through the use of web
program. workers.
Java is mainly used for backend Javascript is used for the frontend
and backend both.
Java is statically typed, which JavaScript is dynamically typed,
means that data types are which means that data types are
determined at compile time. determined at runtime.
Java uses more memory Javascript uses less memory.
Java requires a Java Development Javascript requires any text editor
Kit(JDK) to run the code or browser console to run the code.
<body>
<button onclick="create()">
Click Here!
</button>
<script>
function create() {
let geeks = document.createElement('geeks');
geeks.textContent = "Geeksforgeeks";
geeks.setAttribute('class', 'note');
document.body.appendChild(geeks);
}
</script>
</body>
</html>
JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box.
Alert:
alert("I am an alert box!");
Confirm:
if (confirm("Press a button!")) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
}
Prompt:
let person = prompt("Please enter your name", "Harry Potter");
let text;
if (person == null || person == "") {
text = "User cancelled the prompt.";
} else {
text = "Hello " + person + "! How are you today?";
}