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
import java.io.*; | |
class BasicSingleton implements Serializable | |
{ | |
// cannot new this class, however | |
// * instance can be created deliberately (reflection) | |
// * instance can be created accidentally (serialization) | |
private BasicSingleton() { | |
System.out.println("Singleton is initializing"); |
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
import org.apache.commons.lang3.SerializationUtils; | |
import java.io.Serializable; | |
// some libraries use reflection (no need for Serializable) | |
class Foo implements Serializable | |
{ | |
public int stuff; | |
public String whatever; |
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
import java.util.Arrays; | |
// Cloneable is a marker interface | |
class Address implements Cloneable { | |
public String streetName; | |
public int houseNumber; | |
public Address(String streetName, int houseNumber) |
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
class Address | |
{ | |
public String streetAddress, city, country; | |
public Address(String streetAddress, String city, String country) | |
{ | |
this.streetAddress = streetAddress; | |
this.city = city; | |
this.country = country; |
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
class Person | |
{ | |
// address | |
public String streetAddress, postcode, city; | |
// employment | |
public String companyName, position; | |
public int annualIncome; |
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
enum CoordinateSystem | |
{ | |
CARTESIAN, | |
POLAR | |
} | |
class Point | |
{ | |
private double x, y; |
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
class Person | |
{ | |
// address | |
public String streetAddress, postcode, city; | |
// employment | |
public String companyName, position; | |
public int annualIncome; |
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
import java.util.ArrayList; | |
import java.util.Collections; | |
class HtmlElement | |
{ | |
public String name, text; | |
public ArrayList<HtmlElement> elements = new ArrayList<HtmlElement>(); | |
private final int indentSize = 2; |
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
import org.javatuples.Triplet; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Objects; | |
import java.util.stream.Collectors; | |
// A. High-level modules should not depend on low-level modules. | |
// Both should depend on abstractions. |
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
class Document | |
{ | |
} | |
interface Machine | |
{ | |
void print(Document d); | |
void fax(Document d) throws Exception; | |
void scan(Document d) throws Exception; |
NewerOlder