Skip to content

Instantly share code, notes, and snippets.

View NAVNEETOJHA's full-sized avatar
🏠
Working from home

Navneet Ojha NAVNEETOJHA

🏠
Working from home
View GitHub Profile
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");
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;
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)
class Address
{
public String streetAddress, city, country;
public Address(String streetAddress, String city, String country)
{
this.streetAddress = streetAddress;
this.city = city;
this.country = country;
class Person
{
// address
public String streetAddress, postcode, city;
// employment
public String companyName, position;
public int annualIncome;
enum CoordinateSystem
{
CARTESIAN,
POLAR
}
class Point
{
private double x, y;
class Person
{
// address
public String streetAddress, postcode, city;
// employment
public String companyName, position;
public int annualIncome;
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;
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.
class Document
{
}
interface Machine
{
void print(Document d);
void fax(Document d) throws Exception;
void scan(Document d) throws Exception;