You are on page 1of 5

Kingdom of Saudi Arabia

Ministry of Education
University of Bisha
College of Computing and Information Technology

LAB-2
Verify the software components
a. System files
b. Log files
c. Check for a change
d. Check for modification
e. Check for blemishes
f. Check for add-ons
......................................................................................................................................
public class GetCurrentThread {
public static void main(String[] args) {
Thread currentThread = Thread.currentThread();
System.out.println(currentThread);
}
}
......................................................................................................................................
/*Get Thread State
class GetThreadState extends Thread {

public void run() {


try {
sleep(4000);
} catch (Exception e) {}
}
public static void main (String args[]) {
Thread t = new GetThreadState();
System.out.println("State: " + t.getState());
t.start();
System.out.println("State: " + t.getState());
try {
t.sleep(2000);
} catch (Exception e) {}
System.out.println("State: " + t.getState());
try {
t.sleep(5000);
} catch (Exception e) {}
System.out.println("State: " + t.getState());

}
}

[Assist. Prof. Dr.Mahmoud Abdelgadir Khalifa] [mkhalifa@ub.edu.sa]


Kingdom of Saudi Arabia
Ministry of Education
University of Bisha
College of Computing and Information Technology

......................................................................................................................................

/*
Joining Threads
The join() method allows one thread to wait for the
completion of another.
If t is a Thread object whose thread is currently
executing,
t.join() causes the current thread to pause execution
until t's thread terminates.
Source: (JoiningThreads.java)
*/
class JoiningThreads extends Thread {
int sleep;
JoiningThreads(int sleep) {
this.sleep = sleep;
}
public void run() {
System.out.println("Begin: " + this.getName());
try {
Thread.sleep (sleep);
} catch (InterruptedException e) {
}
System.out.println("End: " + this.getName());
}
public static void main (String args[]) throws
InterruptedException {
JoiningThreads t1 = new JoiningThreads(6000);
JoiningThreads t2 = new JoiningThreads(2000);
JoiningThreads t3 = new JoiningThreads(3000);
t1.start();
t2.start();
t3.start();
t1.join();
t2.join();
t3.join();
System.out.println("Finished");
}
}

[Assist. Prof. Dr.Mahmoud Abdelgadir Khalifa] [mkhalifa@ub.edu.sa]


Kingdom of Saudi Arabia
Ministry of Education
University of Bisha
College of Computing and Information Technology

..........................................................................................................
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class RunTimeExample {
public static void main(String[] args) {
try {
// print a message
System.out.println("Executing notepad.exe");
// create a process and execute notepad.exe
Process process = Runtime.getRuntime().exec("notepad.exe");
// print another message
System.out.println("Notepad should now open.");
Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"dir \"");
Runtime.getRuntime().exec("cmd /c start c:/Users/adobegc.log /K \" \"");
System.out.println("Notepad should now open.");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

.........................................................................................................

// Java code for stack implementation

[Assist. Prof. Dr.Mahmoud Abdelgadir Khalifa] [mkhalifa@ub.edu.sa]


Kingdom of Saudi Arabia
Ministry of Education
University of Bisha
College of Computing and Information Technology

import java.io.*;
import java.util.*;
class TestStack
{
// Pushing element on the top of the stack
static void stack_push(Stack<Integer> stack)
{
for(int i = 0; i < 5; i++)
{
stack.push(i);
}
}
// Popping element from the top of the stack
static void stack_pop(Stack<Integer> stack)
{
System.out.println("Pop Operation:");

for(int i = 0; i < 5; i++)


{
Integer y = (Integer) stack.pop();
System.out.println(y);
}
}
// Displaying element on the top of the stack
static void stack_peek(Stack<Integer> stack)
{
Integer element = (Integer) stack.peek();
System.out.println("Element on stack top: " + element);
}
// Searching element in the stack
static void stack_search(Stack<Integer> stack, int element)
{
Integer pos = (Integer) stack.search(element);

if(pos == -1)
System.out.println("Element not found");

[Assist. Prof. Dr.Mahmoud Abdelgadir Khalifa] [mkhalifa@ub.edu.sa]


Kingdom of Saudi Arabia
Ministry of Education
University of Bisha
College of Computing and Information Technology

else
System.out.println("Element is found at position: " + pos);
}

public static void main (String[] args)


{
Stack<Integer> stack = new Stack<Integer>();

stack_push(stack);
stack_pop(stack);
stack_push(stack);
stack_peek(stack);
stack_search(stack, 2);
stack_search(stack, 6);
}
}
/*
Output:

Pop Operation:
4
3
2
1
0
Element on stack top: 4
Element is found at position: 3
Element not found
*/

[Assist. Prof. Dr.Mahmoud Abdelgadir Khalifa] [mkhalifa@ub.edu.sa]

You might also like