This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package threads; | |
public class MyRunnable implements Runnable { | |
@Override | |
public void run() { | |
System.out.println("Inside run method"); | |
System.out.println("Doing some important work concurrently"); | |
System.out.println("sleep for a while."); | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package threads; | |
public class ThreadDemo { | |
public static void main(String[] args) { | |
Thread t1 = new MyThread(); | |
Thread t2 = new MyThread(); | |
t1.start(); | |
t2.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package threads; | |
public class MyThread extends Thread { | |
@Override | |
public void run() { | |
for (int i = 0; i < 10; i++) { | |
System.out.println(i); | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package file; | |
public class Main { | |
public static void main(String[] args) { | |
Copier copier = new Copier(); | |
copier.copy("hello.txt", "hello-copied1.txt"); | |
Copier2 copier2 = new Copier2(); | |
copier2.copy("hello.txt", "hello-copied2.txt"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package file; | |
public class Main { | |
public static void main(String[] args) { | |
Copier copier = new Copier(); | |
copier.copy("hello.txt", "hello-copied1.txt"); | |
Copier2 copier2 = new Copier2(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package file; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.nio.channels.FileChannel; | |
public class Copier3 { | |
public void copy(String src, String dest) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package file; | |
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
public class Copier2 { | |
public void copy(String from, String to) { | |
Path src = Paths.get(from); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package file; | |
import java.io.*; | |
public class Copier { | |
public void copy(String src, String dest) { | |
File sourceFile = new File(src); | |
if (!sourceFile.exists()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package file; | |
import java.io.*; | |
public class Copier { | |
public void copy(String src, String dest) { | |
File sourceFile = new File(src); | |
if (!sourceFile.exists()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Reluctant { | |
private Reluctant reluctant = new Reluctant(); | |
public Reluctant() throws Exception { | |
throw new Exception("I'm not coming out"); | |
} | |
public static void main(String[] args) { | |
try { |