JDK 1.0 Features
Java 1.0 (January 1996): The first version of Java was released by Sun Microsystems, the original creators of Java.
1.Object-oriented programming:
JDK 1.0 introduced object-oriented programming (OOP) concepts, which made it easier to develop complex applications. OOP allows developers to organize code into reusable and modular objects that interact with each other to perform tasks.
For example, consider the following Java code that creates a class named Person with attributes name and age:
public class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public void sayHello() {
System.out.println("Hello, my name is " + name + " and I am " + age + " years old.");
}
}
In this code, we create a Person class with two attributes name and age and a constructor that sets these attributes. We also define a sayHello() method that prints out a message using the name and age attributes.
2. Platform independence:
JDK 1.0 introduced the concept of "Write Once, Run Anywhere" (WORA), which means that Java code can run on any platform that has a Java Virtual Machine (JVM) installed. This is possible because Java code is compiled into bytecode, which can be executed by any JVM.
For example, consider the following Java code:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
public class MyClass {
public static void main(String[] args) {
while (true) {
new Object();
}
}
}
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
javac HelloWorld.java
java HelloWorld
import java.applet.*;
import java.awt.*;
public class MyApplet extends Applet {
public void init() {
// Initialize the applet here
}
public void paint(Graphics g) {
// Draw graphics here
g.drawString("Hello, World!", 20, 20);
}
}
<html>
<head>
<title>My Applet</title>
</head>
<body>
<applet code="MyApplet.class" width="200" height="200">
Your browser does not support Java applets.
</applet>
</body>
</html>
import java.awt.*;
public class MyFrame extends Frame {
public MyFrame(String title) {
super(title);
// Add components to the frame here
Button button = new Button("Click me!");
add(button);
}
public static void main(String[] args) {
MyFrame frame = new MyFrame("My Frame");
frame.setSize(200, 200);
frame.setVisible(true);
}
}
javac MyFrame.java
java MyFrame
import java.io.*;
public class PasswordExample {
public static void main(String args[]) {
Console console = System.console();
if (console == null) {
System.err.println("No console available");
System.exit(1);
}
char password[] = console.readPassword("Enter your password: ");
System.out.println("Your password is: " + new String(password));
}
}
Post a Comment
0 Comments