KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > ReturnTypeExample


1 /* ****************************************************************************
2  * ReturnTypeExample.java
3 * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package examples;
11
12 import java.util.List JavaDoc;
13 import java.util.Vector JavaDoc;
14 import java.util.Map JavaDoc;
15 import java.util.HashMap JavaDoc;
16
17 public class ReturnTypeExample {
18
19     public static int returnInteger() {
20         return 1;
21     }
22
23     public static Integer JavaDoc returnIntegerObject() {
24         return new Integer JavaDoc(2);
25     }
26
27     public static short returnShort() {
28         return 3;
29     }
30
31     public static Short JavaDoc returnShortObject() {
32         return new Short JavaDoc((short)4);
33     }
34
35     public static long returnLong() {
36         return 5;
37     }
38
39     public static Long JavaDoc returnLongObject() {
40         return new Long JavaDoc(6);
41     }
42
43     public static float returnFloat() {
44         return 7;
45     }
46
47     public static Float JavaDoc returnFloatObject() {
48         return new Float JavaDoc(8);
49     }
50
51     public static double returnDouble() {
52         return 3.14159;
53     }
54
55     public static Double JavaDoc returnDoubleObject() {
56         return new Double JavaDoc(3.14159);
57     }
58
59     public static byte returnByte() {
60         return (byte)11;
61     }
62
63     public static Byte JavaDoc returnByteObject() {
64         return new Byte JavaDoc((byte)12);
65     }
66
67     public static boolean returnBoolean() {
68         return true;
69     }
70
71     public static Boolean JavaDoc returnBooleanObject() {
72         return new Boolean JavaDoc(false);
73     }
74
75     public static char returnCharacter() {
76         return 'a';
77     }
78
79     public static Character JavaDoc returnCharacterObject() {
80         return new Character JavaDoc('b');
81     }
82
83     public static String JavaDoc returnString() {
84         return "returing a string";
85     }
86
87     public static Coordinate returnCoordinateObject() {
88         return new Coordinate(4,2);
89     }
90
91     public static int[] returnIntegerArray() {
92         int[] intarr = { 1, 2, 3, 4, 5 };
93         return intarr;
94     }
95
96     public static String JavaDoc[] returnStringArray() {
97         String JavaDoc[] strarr = { "one", "two", "three", "four", "five" };
98         return strarr;
99     }
100
101     public static Coordinate[] returnCoordinateObjectArray() {
102         Coordinate[] coarr = { new Coordinate(1,1),
103                                 new Coordinate(2,2),
104                                 new Coordinate(3,3),
105                                 new Coordinate(4,4),
106                                 new Coordinate(5,5) };
107         return coarr;
108     }
109
110     public static List JavaDoc returnIntegerList() {
111         List JavaDoc list = new Vector JavaDoc();
112         list.add(new Integer JavaDoc(1));
113         list.add(new Integer JavaDoc(2));
114         list.add(new Integer JavaDoc(3));
115         list.add(new Integer JavaDoc(4));
116         list.add(new Integer JavaDoc(5));
117         return list;
118     }
119
120     public static Map JavaDoc returnIntegerMap() {
121         Map JavaDoc map = new HashMap JavaDoc();
122         map.put("one", new Integer JavaDoc(1));
123         map.put("two", new Integer JavaDoc(2));
124         map.put("three", new Integer JavaDoc(3));
125         map.put("four", new Integer JavaDoc(4));
126         map.put("five", new Integer JavaDoc(5));
127         return map;
128     }
129
130     public static List JavaDoc returnCoordinateObjectList() {
131         List JavaDoc list = new Vector JavaDoc();
132         list.add(new Coordinate(1,1));
133         list.add(new Coordinate(2,2));
134         list.add(new Coordinate(3,3));
135         list.add(new Coordinate(4,4));
136         list.add(new Coordinate(5,5));
137         return list;
138     }
139
140     public static Map JavaDoc returnCoordinateObjectMap() {
141         Map JavaDoc map = new HashMap JavaDoc();
142         map.put("one", new Coordinate(1,1));
143         map.put("two", new Coordinate(2,3));
144         map.put("three", new Coordinate(5,8));
145         map.put("four", new Coordinate(13,21));
146         map.put("five", new Coordinate(34,55));
147         return map;
148     }
149
150     static public class Coordinate {
151         public int x;
152         public int y;
153
154         public Coordinate(int x, int y) {
155             this.x = x;
156             this.y = y;
157         }
158
159         public String JavaDoc toString() {
160             return "x: " + this.x + ", y: " + this.y;
161         }
162     }
163
164 }
165
Popular Tags