Java String, Buffer, Vector Methods
Java String, Buffer, Vector Methods
6. Constructors to add complex numbers 7. Multilevel Inheritance 8. Single Inheritance (Room Area and Volume)
public class StringExample { [Link](4, " Language"); public class IntegerWrapper { class Complex { class A { class Room { int length, breadth;
public static void main(String[] args) { [Link](4, 13, " is a"); public static void main(String[] args) { int real, imag; void displayA() {
Room(int l, int b) {
String s = " Hello Java "; [Link](4, 10); Integer i = 100; Complex() {} [Link]("Class A"); length = l;
breadth = b;
[Link]("Length: " + [Link]()); [Link](); [Link]("Byte: " + [Link]()); Complex(int r, int i) { }
}
[Link]("Char at 1: " + [Link]("StringBuffer: " + [Link]("Short: " + [Link]()); real = r; }
[Link](1)); [Link]()); int area() {
[Link]("Int: " + [Link]()); imag = i; class B extends A {
return length * breadth;
[Link]("Substring: " + } }
[Link]("Long: " + [Link]()); } void displayB() {
[Link](1, 5));
}
[Link]("Float: " + [Link]()); Complex add(Complex c) { [Link]("Class B"); }
[Link]("Equals: " + [Link]("
Hello Java ")); [Link]("Double: " + return new Complex(real + [Link], imag + } class RoomVolume extends Room { int height;
3. Vector methods [Link]()); [Link]);
[Link]("Ignore Case: " + }
RoomVolume(int l, int b, int h) {
[Link](" hello java ")); import [Link]; } }
class C extends B { super(l, b);
[Link]("Index of 'J': " + public class VectorExample { } void display() { height = h;
void displayC() {
[Link]('J')); }
public static void main(String[] args) { [Link](real + " + " + imag + "i");
[Link]("Class C");
[Link]("Replace: " +
Vector<String> v = new Vector<>(); 5. Convert Integer object to primitive } int volume() {
[Link]("Java", "World")); }
return length * breadth * height;
[Link]("Apple"); public class IntegerToPrimitive { }
[Link]("To Upper: " + } }
[Link]()); [Link]("Banana"); public static void main(String[] args) { public class ComplexDemo {
public class MultiLevel { }
[Link]("To Lower: " + [Link]("Cherry"); Integer obj = 150; public static void main(String[] args) {
public static void main(String[] args) {
[Link]()); public class InheritanceDemo {
[Link](1, "Mango"); byte b = [Link](); Complex c1 = new Complex(2, 3);
C obj = new C();
[Link]("Trim: " + [Link]()); public static void main(String[] args) {
[Link](v); short s = [Link](); Complex c2 = new Complex(1, 4);
[Link]();
[Link]("Starts With: " + RoomVolume obj = new RoomVolume(10, 20,
[Link]("Banana"); double d = [Link](); Complex c3 = [Link](c2);
[Link](" ")); [Link]();
30);
[Link]("Contains Apple? " + [Link]("Byte: " + b); [Link]();
[Link]("Ends With: " + [Link]();
[Link]("Apple")); [Link]("Area: " + [Link]());
[Link](" ")); [Link]("Short: " + s); }
}
[Link]("First: " + [Link]("Volume: " + [Link]());
} [Link]("Double: " + d); }
[Link]()); }
} } }
[Link]("Last: " +
2. All methods of StringBuffer [Link]()); } }
public class StringBufferExample { }
9. Multiple Inheritance with Interfaces 10. Area of rectangle and circle using interfaces 14. Multithread: print even and odd numbers 15. Three threads with setPriority 16. Password check with exception 17. NotMatchException
interface A { interface Shape { class Even extends Thread { class Task extends Thread { import [Link]; class NotMatchException extends Exception {
void methodA(); public void run() { public Task(String name) { class AuthenticationFailure extends Exception { public NotMatchException(String msg) {
void area();
} for (int i = 0; i <= 10; i += 2) super(name); public AuthenticationFailure(String msg) { super(msg);
}
interface B { [Link]("Even: " + i); } super(msg); }
class Rectangle implements Shape {
void methodB(); } } }
class C implements A, B { public void area() { class Odd extends Thread { [Link]("Running " + getName()); public class PasswordCheck { public class MatchCheck {
public void methodA() { [Link]("Rectangle Area: " + (length * public void run() { } public static void main(String[] args) { public static void main(String[] args) {
[Link]("Method A"); breadth)); for (int i = 1; i <= 10; i += 2) } Scanner sc = new Scanner([Link]); String country = "USA";
public void methodB() { } } public static void main(String[] args) { String input = [Link](); try {
}
[Link]();
}
[Link]();
}
18. RadioButton and Checkbox using Swing public class CityList { 21. Menu with disabled "Black [Link](new JButton([Link](i))); 25. JTree: Root and Subfolders [Link](true);
import [Link].*; public static void main(String[] args) { import [Link].*; } import [Link].*; }
public class GUIRadioCheckbox { JFrame f = new JFrame("City List"); public class MenuColor { [Link](300, 300); import [Link]; }
public static void main(String[] args) { String[] cities = {"Mumbai", "Delhi", "Pune", public static void main(String[] args) { [Link](true); public class JTreeExample {
"Nagpur", "Chennai", "Kolkata", "Bhopal",
JFrame f = new JFrame("Radio and JFrame f = new JFrame("Color Menu"); } public static void main(String[] args) { 27. KeyEvent example
"Lucknow", "Indore", "Ahmedabad"};
Checkbox");
JMenuBar mb = new JMenuBar(); } JFrame f = new JFrame("JTree Example"); import [Link].*;
JList<String> list = new JList<>(cities);
[Link](300, 200);
JMenu menu = new JMenu("Colors"); 23. Display number on button 0–9 File root = new File("C:/"); import [Link].*;
JScrollPane sp = new JScrollPane(list);
[Link](null);
JMenuItem red = new JMenuItem("Red"); import [Link].*; JTree tree = new JTree([Link]()); public class KeyEventExample {
[Link](sp);
JRadioButton r1 = new JRadioButton("Male");
JMenuItem blue = new JMenuItem("Blue"); import [Link].*; [Link](new JScrollPane(tree)); public static void main(String[] args) {
[Link](200, 200);
JRadioButton r2 = new
JMenuItem black = new JMenuItem("Black"); public class ButtonNumbers { [Link](300, 400); JFrame f = new JFrame("Key Event");
JRadioButton("Female"); [Link](true);
[Link](false); public static void main(String[] args) { [Link](true); JTextField tf = new JTextField();
[Link](50, 20, 100, 30); }
[Link](red); JFrame f = new JFrame("Number Buttons"); } JLabel l = new JLabel();
[Link](150, 20, 100, 30); }
[Link](blue); [Link](new GridLayout(2, 5)); }
ButtonGroup bg = new ButtonGroup();
[Link](black); for (int i = 0; i <= 9; i++) { [Link](new KeyAdapter() {
[Link](r1); [Link](r2); 20. Select multiple newspapers
[Link](menu); [Link](new JButton([Link](i))); 26. JTable with 10 students public void keyPressed(KeyEvent e) {
JCheckBox cb = new JCheckBox("Accept import [Link].*;
Terms"); [Link](mb); } import [Link].*; [Link]("Key Pressed");
public class NewsPaperList {
[Link](50, 60, 150, 30); [Link](300, 200); [Link](300, 100); public class StudentTable { }
[Link](r1); [Link](r2); [Link](cb); public static void main(String[] args) { [Link](true); [Link](true); public static void main(String[] args) { });
[Link](true); JFrame f = new JFrame("Newspapers"); } } JFrame f = new JFrame("Student Table"); [Link](tf, "North");
} String[] papers = {"TOI", "Hindustan Times", "The } } String[] columns = {"Name", "Percentage", [Link](l, "South");
Hindu", "Indian Express", "DNA"}; "Grade"};
} 22. Grid of 5x5 [Link](300, 100);
String[][] data = {
JList list = new JList<>(papers); import [Link].*; 24. Custom Output (Add specific content if [Link](true);
[Link]([Link] required) {"A", "85", "A"}, {"B", "78", "B"}, {"C", "90",
import [Link].*; }
IPLE_INTERVAL_SELECTION); "A"}, {"D", "56", "C"}, {"E", "88", "A"},
public class CustomOutput {
}
[Link](new JScrollPane(list)); {"F", "66", "B"}, {"G", "73", "B"}, {"H", "92",
public static void main(String[] args) {
public class Grid5x5 { "A"}, {"I", "59", "C"}, {"J", "80", "A"}
[Link](200, 200); [Link]("Java Practical Output
public static void main(String[] args) { };
Example");
[Link](true); JFrame f = new JFrame("5x5 Grid"); JTable table = new JTable(data, columns);
}
19. List of 10 cities } [Link](new GridLayout(5, 5)); [Link](new JScrollPane(table));
}
import [Link].*; } for (int i = 1; i <= 25; i++) { [Link](400, 200);
28. MouseMotionListener (mouseDragged & [Link]("Output Example Line 32. InetAddress - IP from hostname
mouseMoved) 2");
import [Link].*;
import [Link].*; }
public class IPAddress {
import [Link].*; }
public static void main(String[] args) throws
public class MouseMotionDemo extends JFrame 30. Addition using JTextField Exception {
implements MouseMotionListener {
import [Link].*; InetAddress ip =
JLabel label; [Link]("[Link]");
import [Link].*;
MouseMotionDemo() { [Link]("IP Address: " +
public class AddNumbers {
[Link]());
label = new JLabel();
public static void main(String[] args) {
}
add(label);
JFrame f = new JFrame("Add Two Numbers");
}
addMouseMotionListener(this);
JTextField t1 = new JTextField();
33. URL class (protocol, host, port, file)
setSize(300, 200);
JTextField t2 = new JTextField();
import [Link].*;
setVisible(true);
JTextField result = new JTextField();
public class URLInfo {
}
JButton b = new JButton("Add");
public static void main(String[] args) throws
public void mouseDragged(MouseEvent e) {
[Link](50, 20, 100, 30); Exception {
[Link]("Dragged at " + [Link]() + "," +
[Link](160, 20, 100, 30); URL url = new
[Link]());
URL("[Link]
[Link](100, 60, 80, 30);
}
[Link]("Protocol: " +
[Link](100, 100, 100, 30);
public void mouseMoved(MouseEvent e) { [Link]());
[Link](e -> {
[Link]("Moved at " + [Link]() + "," + [Link]("Host: " + [Link]());
[Link]()); int a = [Link]([Link]());
[Link]("Port: " + [Link]());
} int b1 = [Link]([Link]());
[Link]("File: " + [Link]());
public static void main(String[] args) { [Link]([Link](a + b1));
}
new MouseMotionDemo(); });
}
} [Link](t1); [Link](t2); [Link](b); [Link](result);
} [Link](300, 200);