12. // Returns the sum of the elements of a int sum(int[] a) { int result = 0; for (int i : a) result += i; return result; } For Arrays ● Eliminates array index rather than iterator ● Similar advantages
13.
14. public int sum(int... intList){ int i, sum; sum=0; for(i=0; i<intList.length; i++) { sum += intList[i]; } return(sum); } Possible ways to call this method int arr[] = { 3,5,7 }; int result = sum (arr); int result = sum (20, 30, 10 ,5 ); int result = sum(); Example of a method that takes an arbitrary number of int arguments and returns their sum:
15.
16. J2SE 1.4.0 ArrayList arrayList = new ArrayList(); Integer intObject = new Integer(10); arrayList.add(intObject); // cannot add 10 directly J2SE 5.0 ArrayList arrayList = new ArrayList(); arrayList.add(10); // int 10 is automatically wrapped into Integer
17.
18.
19.
20. interface ShapeNumbers { public static int CIRCLE = 0; public static int SQUARE = 1; public static int TRIANGLE = 2; } Implementing this interface creates an unnecessary dependence on the ShapeNumbers interface. It becomes awkward to maintain as the class evolves, especially if other classes need access to these constants also and implement this interface
21. To make this cleaner, the static members are placed into a class and then imported via a modified syntax of the import directive . package MyConstants; class ShapeNumbers { public static int CIRCLE = 0; public static int SQUARE = 1; public static int TRIANGLE = 2; } To import the static members in your class, specify the following in the import section of your Java source file. import static MyConstants.ShapeNumbers.*; // imports all static data You can also import constants individually by using the following syntax: import static MyConstants.ShapeNumbers.CIRCLE; import static MyConstants.ShapeNumbers.SQUARE;
22.
23.
24.
25. How CDS Works : When JRE is installed on 32-bit platforms using the Sun provided installer, it loads a set of classes from the system jar file into a private internal representation, and dumps that representation to a file, called a " shared archive ". Unix : jre/lib/[arch]/client/classes.jsa Windows : jre/bin/client/classes.jsa During subsequent JVM invocations, the shared archive is memory-mapped in, saving the cost of loading those classes and allowing much of the JVM's metadata for these classes to be shared among multiple JVM processes. CDS produces better results for smaller applications because it eliminates a fixed cost of loading certain core classes .