File: Breakpoints.java

package info (click to toggle)
eclipse-jdt-debug 4.30-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,876 kB
  • sloc: java: 234,390; xml: 6,367; makefile: 5
file content (164 lines) | stat: -rw-r--r-- 3,702 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
import java.util.*;


public class Breakpoints implements IBreakpoints {
	static {
	 	new Vector(1);
	 	System.out.println("Initializer");
    }

    public class InnerBreakpoints {
    	public void innerInstanceMethod() {
    		System.out.println("inner instance");
    	}
    }

        Enumeration myNamedEnumerate(final Object array[]) {
        	final int count[] = {0}; // final reference to mutable array
        	class E implements Enumeration {
           	 public boolean hasMoreElements(){
           	 	 return count[0] < array.length;
           	 }
           	 public Object nextElement(){
           	 	 return array[count[0]++];
           	 }
        	}
        	return new E();
        }

	    Enumeration myAnonymousEnumerate(final Object array[]) {
    	    return new Enumeration() {
        	    int count = 0;
           		 public boolean hasMoreElements(){
           	 		 return count < array.length;
           	 	}
           	 	public Object nextElement(){
           	 		 return array[count++];
           	 	}
        	};
    	}

 public static void main (String[] args) {
 	threading();
	Breakpoints bp= new Breakpoints();
	bp.instanceMethod();
	bp.instanceMethod2();

 }

public class InnerRunnable implements Runnable {
  	public void run() {
  		System.out.println("Threading");
  	}
 }
 public static boolean threading() {
 	try {
 		Thread runner = new Thread(new Breakpoints().new InnerRunnable(), "BreakpointsThread");
		runner.setPriority(Thread.MIN_PRIORITY);
		runner.start();
		runner.join();
	} catch (InterruptedException ie) {
	}
	return false;
 }

 public Breakpoints() {
 	super();
 	System.out.println("Constructor");
 }
 public void instanceMethod() {
 	if (true) {
 		System.out.println("If");
 	} else {
 		System.out.println("Can't get here");
 	}
 	if (false) {
 		System.out.println("Can't get here");
 	} else {
 		System.out.println("Else");
 	}

 	int i;
 	for (i= 0; i < 3; i++) {
 		System.out.println("for");
 	}

 	while (i < 6) {
 		System.out.println("while");
 		i++;
 	}

 	{
 		System.out.println("block");
 	}
 }

  public void instanceMethod2() {
  	int count= 0;
  	do {
		System.out.println("dowhile");
		count++;
	} while (count < 5);


	try {
			Vector v= new Vector(1);
			v.firstElement();
		} catch (NoSuchElementException nsee) {
			System.out.println("catch block");
		} finally {
			System.out.println("finally after catch");

	}
	try {
			new Vector(1);
			System.out.println("try");
		} catch (NoSuchElementException nsee) {
		} finally {
			System.out.println("finally after try");

	}
	switch (count) {
		case 5:
		System.out.println("switch");
		break;
	}
		switch (count) {
		case 3:
		break;
		default:
		System.out.println("switch default");
	}


  	Object lock= new Object();
  	synchronized (lock) {
  		System.out.println("synchronized");
  	}

	InnerBreakpoints ibp= new InnerBreakpoints();
	ibp.innerInstanceMethod();

	String[] array= {"1", "2", "3"};
	Enumeration myNamed= myNamedEnumerate(array);
	myNamed.hasMoreElements();

	Enumeration myAnonymous= myAnonymousEnumerate(array);
	myAnonymous.hasMoreElements();

	ibp.innerInstanceMethod();
  }
}