CODE
import java.io.PipedReader;
import java.io.PipedWriter;
class PipeReaderThread implements Runnable
{
PipedReader pr;
String name = null;
public PipeReaderThread(String name, PipedReader pr)
{
this.name = name;
this.pr = pr;
}
public void run()
{
try {
// continuously read data from stream and print it in console
while (true) {
char c = (char) pr.read(); // read a char
if (c != -1) { // check for -1 indicating end of file
System.out.print(c);
}
}
} catch (Exception e) {
System.out.println(" PipeThread Exception: " + e);
}
}
}
class PipeWriterThread implements Runnable
{
PipedWriter pw;
String name = null;
public PipeWriterThread(String name, PipedWriter pw) {
this.name = name;
this.pw = pw;
}
public void run() {
try {
while (true) {
// Write some data after every two seconds
pw.write("Testing data written...n");
pw.flush();
Thread.sleep(2000);
}
} catch (Exception e) {
System.out.println(" PipeThread Exception: " + e);
}
}
}
public class PipedCommunicationTest
{
public static void main(String[] args)
{
new PipedCommunicationTest();
}
public PipedCommunicationTest()
{
try
{
// Create writer and reader instances
PipedReader pr = new PipedReader();
PipedWriter pw = new PipedWriter();
// Connect the writer with reader
pw.connect(pr);
// Create one writer thread and one reader thread
Thread thread1 = new Thread(new PipeReaderThread("ReaderThread", pr));
Thread thread2 = new Thread(new PipeWriterThread("WriterThread", pw));
// start both threads
thread1.start();
thread2.start();
}
catch (Exception e)
{
System.out.println("PipeThread Exception: " + e);
}
}
}
Write a Java program that uses pipes to communicate between processes.
Write a complete Java program that uses a for loop to compute the sum of the even numbers and the sum of the odd numbers between 1 and 25.
Asap
Please write a Java program with comments
Asap: Please write a java program with comments Write a program that uses recursion to display concentric circles, as shown in the figure below. The circles are centered in the pane. The gap between two adjacent circles is 10 pixels, and the gap between the border of the pane and the largest circle is also 10 pixels. res
In Java, write a program that uses a stack to print the prime factors of a positive integer in descending order.
Write a Java program that uses a java mail API that sends an encrypted email from google mail using TLS and giving the MAIL FROM, MAIL TO, SUBJ, and message
Following is my java program that i need help with. Write a program that uses a JavaFX GUI that allows a user to enter a directory (folder) and then displays the number of the files in the directory. The number of files in the directory should be determined recursively.
This is for Java
3. Counting by Halves Write a program called Countingßyllalves. java that uses a for loop. With the loop, make the variable x go from -10 to 10, counting by o.5. (This means that x can't be an int.) -10.0 -9.5 -9.0 -8.5 -8.0 9.0 9.5 10.0
in java Write a program that uses recursion to find the largest number in an array. Declare and initialize an array of 10 different numbers.
Java: makes sure program compiles before posting. Write a program that uses nested for loops to create the pattern of Xs and Os, in which on every line each letter is displayed one additional space to the right. Use a toggle variable ( a boolean flag) to alternate between X and O to produce output as shown in the sample run below: Enter the number of lines: 7 X O X O X O X
MUST BE WRITTEN IN JAVA CODE Write a program that uses a stack to determine whether a string is a palindrome (i.e., the string is spelled identically backward and forward). The program should ignore spaces and punctuation.
Write a Java program which uses a for loop to sum all the even numbers from 1 to 30.