Professional Documents
Culture Documents
KANU
KANU
Mat No.:COS/5543/2019
Course:CSC413
Java:
import java.util.*;
class Student {
String name;
String matNo;
String gender;
String department;
String dob;
int level;
int schoolFees;
int sugFee;
int deptDues;
public Student(String name, String matNo, String gender, String department, String dob, int
level, int schoolFees, int sugFee, int deptDues) {
this.name = name;
this.matNo = matNo;
this.gender = gender;
this.department = department;
this.dob = dob;
this.level = level;
this.schoolFees = schoolFees;
this.sugFee = sugFee;
this.deptDues = deptDues;
}
JavaScript:
class Student {
constructor(name, matNo, gender, department, dob, level, schoolFees, sugFee, deptDues) {
this.name = name;
this.matNo = matNo;
this.gender = gender;
this.department = department;
this.dob = dob;
this.level = level;
this.schoolFees = schoolFees;
this.sugFee = sugFee;
this.deptDues = deptDues;
}
computeTotalFees() {
return this.schoolFees + this.sugFee + this.deptDues;
}
}
const students = [
new Student("John Doe", "CS1001", "Male", "Computer Science", "2000-01-01", 100,
100000, 5000, 2000),
// Add more students here
];
Comparison:
Syntax: Java and JavaScript have different syntaxes. Java is a statically typed language with a
syntax resembling C++, while JavaScript is dynamically typed and has a syntax similar to C.
Type System: Java is statically typed, meaning variables must be declared with their types at
compile time, while JavaScript is dynamically typed, allowing variables to hold values of any
type without explicit declaration.
Platform: Java is often used for building server-side applications, Android apps, and enterprise
systems, while JavaScript is primarily used for front-end web development, but also for server-
side development (Node.js) and mobile app development (React Native).
Concurrency: Java has built-in support for threads and concurrency through the
java.util.concurrent package, while JavaScript relies on asynchronous programming with
callbacks, promises, and async/await for handling concurrency.
Ecosystem: Java has a mature ecosystem with extensive libraries and frameworks like Spring,
Hibernate, and Android SDK, while JavaScript has a vast ecosystem with libraries and
frameworks like React, Angular, and Express.js.
Compilation: Java code is compiled into bytecode that runs on the Java Virtual Machine (JVM),
while JavaScript code is interpreted or just-in-time compiled by the JavaScript engine in the
browser or Node.js runtime.