Assignment of Advanced Programming
On
Java Programs
Submitted To: - Submitted By:-
[Link] -------------------
--------------------
[Link] 1st Semester
SHRI MATA VAISHNO DEVI UNIVERSITY
1. Program of GET and SET method :-
import [Link].*;
public class GETSET {
int x = 0;
void setx(int x) {
this.x = x;
}
void getx() {
[Link]("The value of x " + x);
}
public static void main(String[] args) {
GETSET g = new GETSET();
[Link]("Enter the Value of X");
Scanner sc = new Scanner([Link]);
int a = [Link]();
[Link](a);
[Link]();
}
}
2. Program of Multithreading by Extending Thread Class:-
public class ExtendingThread extends Thread{
public void run()
{
[Link]("Thread is running");
}
public static void main(String[] args) {
ExtendingThread e = new ExtendingThread();
[Link]();
3. Program of Implementing Runnable Interface:-
public class ImplementRun implements Runnable{
public void run()
{
[Link]("Thread is running");
}
public static void main(String[] args) {
ImplementRun r = new ImplementRun();
Thread t = new Thread(r);
[Link]();
}
}
4. Program of Frame by Extending JFrame:-
import [Link];
import [Link];
import [Link].*;
import [Link].*;
class Frame extends JFrame {
Frame() {
setTitle("Anmol");
setSize(600, 600);
JButton btn = new JButton("yellow");
JLabel jlbl = new JLabel("color");
JPanel pnl = new JPanel();
[Link](pnl);
[Link](btn);
[Link](jlbl);
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
[Link]([Link]);
}
});
JMenuBar menu = new JMenuBar();
[Link](menu);
JMenu menu1 = new JMenu("file");
JMenu menu2 = new JMenu("help");
[Link](menu1);
[Link](menu2);
JMenuItem item1 = new JMenuItem("open");
[Link](item1);
[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
public static void main(String args[]) {
[Link](new Runnable() {
public void run() {
Frame f = new Frame();
[Link](JFrame.EXIT_ON_CLOSE);
[Link](true);
}
});
}
}
5. Program to copy one array to another :-
import [Link];
import [Link];
public class ArrayCopy {
public static void main(String[] args) {
int [] arrcopy;
int [] arr = new int[5];
[Link](arr,4);
String str = [Link](arr);
[Link]("Arays is :" + str);
arrcopy = [Link](arr,2);
[Link]("new Array is :" + [Link](arrcopy));
}
}
6. Program to Sort an array:-
import [Link].*;
public class Sort {
public static void main(String args[]) {
Student[] arr = new Student[3];
Scanner sc = new Scanner([Link]);
[Link]("Enter the Salary");
for (int i = 0; i < 3; i++) {
arr[i].salary = [Link]();
[Link](arr);
for (Student st : arr) {
[Link]([Link]);
}
}
}
7. Program of StringBuffer:-
public class StringBufferExample {
public static void main(String[] args) {
String abc = "ANmol";
StringBuffer sb = new StringBuffer(abc);
[Link]("Sharma");
[Link](sb);
}
8. Program to Compare two Strings:-
import [Link];
public class CompareStrings {
public static void main(String[] args) {
[Link]("Enter the First String");
Scanner sc = new Scanner([Link]);
String input = [Link]();
[Link]("Enter the Second String");
Scanner scc = new Scanner([Link]);
String inputt = [Link]();
if ([Link](inputt)) {
[Link]("Strings are equal");
} else {
[Link]("Strings are not equal");
}
}
[Link] for SubString:-
public class SubStringExample {
public static void main(String[] args) {
String str = "Java programming Language ";
String a = [Link](5, 7);
[Link]("SubString is :" + a);
}
}
[Link] for Fill Array:-
import [Link];
public class FillExample {
public static void main(String[] args) {
int[] arr = new int[5];
[Link](arr,7);
String a = [Link](arr);
[Link](a);
}
}