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 interface AutoCloseable { | |
void close() throws Exception; | |
} | |
public interface Closeable extends AutoCloseable { | |
void close() throws IOException; | |
} |
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
interface MyInterface { | |
void doWork() throws IOException; | |
} | |
class MyClass { | |
public void moreWork() throws FileNotFoundException { | |
... |
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 void logMessage(String message) { | |
if (message == null) { | |
throw new NullPointerException("'message' must not be null'"); | |
} | |
if (message.isEmpty()) { | |
throw new IllegalArgumentException("'message' must not be empty"); | |
} | |
... |
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
try (Socket socket = new Socket(); | |
InputStream input = new DataInputStream(socket.getInputStream()); | |
OutputStream output = new DataOutputStream(socket.getOutputStream())) { | |
... | |
} |
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
try (FileReader reader = new FileReader("awesome-file.txt")) { | |
int content = 0; | |
while (content != -1) { | |
content = reader.read(); | |
... | |
} | |
} | |
catch (IOException e) { | |
// handle any exceptions | |
} |
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
FileReader reader = null; | |
try { | |
reader = new FileReader("awesome-file.txt"); | |
int content = 0; | |
while (content != -1) { | |
content = reader.read(); | |
... | |
} | |
} |
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
try { | |
... | |
} | |
catch (FileNotFound | UnsupportedEncodingException e) { | |
... | |
} |
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
try { | |
// open a file | |
// read file | |
// do the work | |
} | |
catch(FileNotFoundException e) { | |
// handle missing file | |
} |
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 boolean isDeleted() { | |
return getTimeDeleted() != null; | |
} |
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
long primitiveValue = 1_024L; | |
Long objectValue = 1_024L; | |
long primitiveSum = primitiveValue + objectValue; | |
Long objectSum = primitiveValue + objectValue; |