adavajava2
adavajava2
Date: .....................................
Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50
Date: .....................................
// String array
String[] strArray = {"Hello", "World", "Generics"};
System.out.println("\nString Array:");
printArray(strArray); // Calling generic method with String array
// Double array
Double[] doubleArray = {1.1, 2.2, 3.3, 4.4};
System.out.println("\nDouble Array:");
printArray(doubleArray); // Calling generic method with Double array
}
}
String Array:
Hello
World
Generics
Double Array:
1.1
2.2
3.3
4.4
Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50
Date: .....................................
@Override
public void run() {
// Print "Hello, World!" 5 times
for (int i = 0; i < 5; i++) {
System.out.println("Hello, World!");
try {
Thread.sleep(500); // Sleep for 500 milliseconds to slow down the output
} catch (InterruptedException e) {
System.out.println("Thread interrupted: " + e.getMessage());
}
}
}
}
Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50
Date: .....................................
@Override
public void run() {
// Thread tries to increment the shared resource counter
for (int i = 0; i < 5; i++) {
sharedResource.increment();
}
}
}
Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50
Date: .....................................
Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50
Date: .....................................
// Read the file byte by byte until the end of the file is reached
while ((byteRead = bufferedInputStream.read()) != -1) {
// Convert the byte to a character and print it
System.out.print((char) byteRead);
}
System.out.println(); // For a newline after printing the content
} catch (IOException e) {
System.out.println("An error occurred while reading from the file.");
e.printStackTrace();
}
}
}
Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50
Date: .....................................
int bytesRead;
// Read from the source file and write to the destination file
while ((bytesRead = fis.read(buffer)) != -1) {
fos.write(buffer, 0, bytesRead); // Write the read bytes to the destination
file
}
} catch (IOException e) {
System.out.println("An error occurred during file copy.");
e.printStackTrace();
}
}
}
int bytesRead;
// Read from the source file and write to the destination file
while ((bytesRead = fis.read(buffer)) != -1) {
fos.write(buffer, 0, bytesRead); // Write the read bytes to the destination
file
}
} catch (IOException e) {
System.out.println("An error occurred during file copy.");
e.printStackTrace();
}
}
}
Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50
Date: .....................................
import java.io.*;
try {
// Prompt the user for input
System.out.print("Enter a line of text: ");
Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50
Date: .....................................
import java.io.*;
public class FileCopyExample {
public static void main(String[] args) {
// Source file (input file)
String sourceFile = "source.txt";
// Destination file (output file)
String destinationFile = "destination.txt";
try {
// Initialize FileReader to read from the source file
fileReader = new FileReader(sourceFile);
// Initialize FileWriter to write to the destination file
fileWriter = new FileWriter(destinationFile);
} catch (IOException e) {
e.printStackTrace();
} finally {
// Close the resources to avoid memory leaks
try {
if (fileReader != null) {
fileReader.close(); }
if (fileWriter != null) {
fileWriter.close(); }
} catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
} finally {
// Close the resources to avoid memory leaks
try {
if (fileReader != null) {
fileReader.close();
}
if (fileWriter != null) {
fileWriter.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
css
Copy code
Reading from source file and writing to destination file...
Hello, this is the content of the source file.
We will copy this content to another file.
File copied successfully!
Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50
Date: .....................................
csharp
Servlet is being destroyed.
Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50