1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 import java.util.*;
15 
16 
17 public class Breakpoints implements IBreakpoints {
18 	static {
19 	 	new Vector(1);
20 	 	System.out.println("Initializer");
21     }
22 
23     public class InnerBreakpoints {
innerInstanceMethod()24     	public void innerInstanceMethod() {
25     		System.out.println("inner instance");
26     	}
27     }
28 
myNamedEnumerate(final Object array[])29         Enumeration myNamedEnumerate(final Object array[]) {
30         	final int count[] = {0}; // final reference to mutable array
31         	class E implements Enumeration {
32            	 public boolean hasMoreElements(){
33            	 	 return count[0] < array.length;
34            	 }
35            	 public Object nextElement(){
36            	 	 return array[count[0]++];
37            	 }
38         	}
39         	return new E();
40         }
41 
myAnonymousEnumerate(final Object array[])42 	    Enumeration myAnonymousEnumerate(final Object array[]) {
43     	    return new Enumeration() {
44         	    int count = 0;
45            		 public boolean hasMoreElements(){
46            	 		 return count < array.length;
47            	 	}
48            	 	public Object nextElement(){
49            	 		 return array[count++];
50            	 	}
51         	};
52     	}
53 
main(String[] args)54  public static void main (String[] args) {
55  	threading();
56 	Breakpoints bp= new Breakpoints();
57 	bp.instanceMethod();
58 	bp.instanceMethod2();
59 
60  }
61 
62 public class InnerRunnable implements Runnable {
run()63   	public void run() {
64   		System.out.println("Threading");
65   	}
66  }
threading()67  public static boolean threading() {
68  	try {
69  		Thread runner = new Thread(new Breakpoints().new InnerRunnable(), "BreakpointsThread");
70 		runner.setPriority(Thread.MIN_PRIORITY);
71 		runner.start();
72 		runner.join();
73 	} catch (InterruptedException ie) {
74 	}
75 	return false;
76  }
77 
Breakpoints()78  public Breakpoints() {
79  	super();
80  	System.out.println("Constructor");
81  }
instanceMethod()82  public void instanceMethod() {
83  	if (true) {
84  		System.out.println("If");
85  	} else {
86  		System.out.println("Can't get here");
87  	}
88  	if (false) {
89  		System.out.println("Can't get here");
90  	} else {
91  		System.out.println("Else");
92  	}
93 
94  	int i;
95  	for (i= 0; i < 3; i++) {
96  		System.out.println("for");
97  	}
98 
99  	while (i < 6) {
100  		System.out.println("while");
101  		i++;
102  	}
103 
104  	{
105  		System.out.println("block");
106  	}
107  }
108 
instanceMethod2()109   public void instanceMethod2() {
110   	int count= 0;
111   	do {
112 		System.out.println("dowhile");
113 		count++;
114 	} while (count < 5);
115 
116 
117 	try {
118 			Vector v= new Vector(1);
119 			v.firstElement();
120 		} catch (NoSuchElementException nsee) {
121 			System.out.println("catch block");
122 		} finally {
123 			System.out.println("finally after catch");
124 
125 	}
126 	try {
127 			new Vector(1);
128 			System.out.println("try");
129 		} catch (NoSuchElementException nsee) {
130 		} finally {
131 			System.out.println("finally after try");
132 
133 	}
134 	switch (count) {
135 		case 5:
136 		System.out.println("switch");
137 		break;
138 	}
139 		switch (count) {
140 		case 3:
141 		break;
142 		default:
143 		System.out.println("switch default");
144 	}
145 
146 
147   	Object lock= new Object();
148   	synchronized (lock) {
149   		System.out.println("synchronized");
150   	}
151 
152 	InnerBreakpoints ibp= new InnerBreakpoints();
153 	ibp.innerInstanceMethod();
154 
155 	String[] array= {"1", "2", "3"};
156 	Enumeration myNamed= myNamedEnumerate(array);
157 	myNamed.hasMoreElements();
158 
159 	Enumeration myAnonymous= myAnonymousEnumerate(array);
160 	myAnonymous.hasMoreElements();
161 
162 	ibp.innerInstanceMethod();
163   }
164 }
165