List of usage examples for java.lang Object Object
@HotSpotIntrinsicCandidate
public Object()
From source file:Main.java
public static void main(String[] argv) throws Exception { Object o = new Object(); Class sup = o.getClass().getSuperclass(); // null }
From source file:Main.java
public static void main(String[] argv) throws Exception { Object o = new Object(); System.out.println(Thread.holdsLock(o)); synchronized (o) { System.out.println(Thread.holdsLock(o)); }// w ww . j a v a 2 s . com }
From source file:Main.java
public static void main(String str[]) { final Object monitor = new Object(); new Thread() { public void run() { try { synchronized (monitor) { System.out.println("10 seconds ..."); monitor.wait(10000); System.out.println("Wait over"); }//from w ww. j a v a 2s. c o m } catch (Throwable t) { t.printStackTrace(); } } }.start(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Object f = new Object() { public void finalize() { System.out.println("Running finalize()"); }//from w w w.j av a2 s .c om }; Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { System.out.println("Running Shutdown Hook"); } }); f = null; System.gc(); System.out.println("Calling System.exit()"); System.exit(0); }
From source file:Main.java
public static void main(String[] args) { Object obj1 = new Object(); Object obj2 = new Object(); CountDownLatch latch = new CountDownLatch(2); new Locker(obj1, obj2, latch).start(); new Locker(obj2, obj1, latch).start(); }
From source file:AllFieldsSnippet.java
public static void main(String[] args) { Object obj = new Object(); //start extract AllFieldsSnippet Class cls = obj.getClass();//from w w w. ja va2 s . co m List accum = new LinkedList(); while (cls != null) { Field[] f = cls.getDeclaredFields(); for (int i = 0; i < f.length; i++) { accum.add(f[i]); } cls = cls.getSuperclass(); } Field[] allFields = (Field[]) accum.toArray(new Field[accum.size()]); //stop extract AllFieldsSnippet }
From source file:Main.java
public static void main(String[] args) { ReferenceQueue referenceQueue = new ReferenceQueue(); Object object = new Object() { public String toString() { return "Referenced Object"; }//from ww w. j a v a 2 s . c o m }; Object data = new Object() { public String toString() { return "Data"; } }; HashMap map = new HashMap(); Reference reference = new SoftReference(object, referenceQueue); map.put(reference, data); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); System.gc(); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); object = null; data = null; System.gc(); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); }
From source file:Main.java
public static void main(String[] args) { ReferenceQueue referenceQueue = new ReferenceQueue(); Object object = new Object() { public String toString() { return "Referenced Object"; }//from w w w . j av a 2 s .com }; Object data = new Object() { public String toString() { return "Data"; } }; HashMap map = new HashMap(); Reference reference = null; System.out.println("Testing PhantomReference."); reference = new PhantomReference(object, referenceQueue); map.put(reference, data); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); System.gc(); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); object = null; data = null; System.gc(); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); }
From source file:Main.java
public static void main(String[] args) { // Boolean conversion System.out.printf("'%b', '%6b', '%.4b'%n", true, false, true); System.out.printf("'%b', '%6b', '%.4b'%n", "A", "B", "C"); System.out.printf("'%B', '%6b', '%.4b'%n", "A", "B", "C"); System.out.printf("%b %n", 2014); System.out.printf("%b %n", new Object()); // String conversion System.out.printf("'%s', '%5s', '%.3s'%n", "A", "B", "C"); System.out.printf("'%S', '%5S', '%.3S'%n", "A", "B", "C"); // Use '-' flag to left-justify the result. // width requires the '-' flag System.out.printf("'%S', '%-5S', '%.3S'%n", "A", "B", "C"); System.out.printf("%s %n", 2014); System.out.printf("%s %n", true); System.out.printf("%s %n", new Object()); // Hash Code conversion System.out.printf("'%h', '%5h', '%.3h'%n", "A", "B", "A"); System.out.printf("'%H', '%5H', '%.3H'%n", "A", "B", "A"); System.out.printf("%h %n", 2014); System.out.printf("%h %n", true); System.out.printf("%h %n", new Object()); }
From source file:Main.java
public static void main(String[] args) { ReferenceQueue referenceQueue = new ReferenceQueue(); Object object = new Object() { public String toString() { return "Referenced Object"; }/* ww w. jav a2 s . c o m*/ }; Object data = new Object() { public String toString() { return "Data"; } }; HashMap map = new HashMap(); Reference reference = new SoftReference(object, referenceQueue); map.put(reference, data); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); System.gc(); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); object = null; data = null; System.gc(); System.out.println(reference.get()); System.out.println(map.get(reference)); System.out.println(reference.isEnqueued()); }