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 ClonePerson { | |
private String name; | |
public ClonePerson(String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; |
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 ClonePerson1 implements Cloneable{ | |
private String name; | |
public ClonePerson1(String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; |
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.Date; | |
public class ClonePerson2 implements Cloneable{ | |
private String name; | |
private Date dob; | |
public ClonePerson2(String name, Date dob) { | |
this.name = name; | |
this.dob = dob; |
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 junit.framework.*; | |
final class LazySingleton { | |
private int i; | |
private static class LazySingletonLoader { | |
private static final LazySingleton INSTANCE = new LazySingleton(); | |
} | |
private LazySingleton() { | |
if (LazySingletonLoader.INSTANCE != null) { | |
throw new IllegalStateException("Already instantiated"); |
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.HashMap; | |
import java.util.Map; | |
public class FooMultiton { | |
private static final Map<Object, FooMultiton> instances = new HashMap<Object, FooMultiton>(); | |
private FooMultiton() { | |
// no explicit implementation | |
} | |
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
// Single-threaded version | |
public class DoubleCheckedLocking { | |
private Helper helper; | |
public Helper getHelper() { | |
if (helper == null) { | |
helper = new Helper(); | |
} | |
return helper; | |
} | |
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 myjavaprogram; | |
import java.util.Arrays; | |
public class TestClass1 { | |
public static void main(String[] args){ | |
int[] array = {23, 23, 0, 43, 545, 12, -55, 43, 12, 12, -999, -87, 12, 0, 0}; | |
//int[] array = {23, -22, 0, 43, 545, 12, -55, 43, 12, 0, -999, -87, 12}; | |
//int[] array = {23, -22, 0, 23}; | |
//int[] array = {23, -22, 23}; | |
calculate_duplicates(array); |
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 HideInstanceVariable { | |
public static void main(String[] args) { | |
Car car = new SportCar(); | |
System.out.println(car.getSpeedMax()); | |
} | |
} | |
class Car { | |
private int speedMax = 150; |
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 Main { | |
public static void main(String[] args) { | |
Car car = new SportCar(); | |
System.out.println(car.getSpeedMax()); | |
} | |
} | |
class Car { | |
private int speedMax = 150; |
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 Overriding { | |
public static void main(String[] args) { | |
Car car = new SportCar(); | |
System.out.println(car.getSpeedMax()); | |
} | |
} | |
class Car { | |
protected int speedMax = 150; |
OlderNewer