Java SE 7u1 released with download link here: http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html
Details of the release notes, please refer: http://www.oracle.com/technetwork/java/javase/jdk7-relnotes-429209.html
Sunday, October 23, 2011
Monday, October 17, 2011
Sort array of object using custom Comparator
Example:
import java.util.Arrays;
import java.util.Comparator;
public class SortComparator {
final static int NUMBER_OF_OBJ = 5;
public class MyClass {
String name;
int number;
MyClass(String n, int i){
name = n;
number = i;
}
}
public static void main(String[] args){
System.out.println("Sort Comparator");
SortComparator sortComparator = new SortComparator();
MyClass[] myClassArray = new MyClass[NUMBER_OF_OBJ];
myClassArray[0] = sortComparator.new MyClass("ABC", 9);
myClassArray[1] = sortComparator.new MyClass("Eric", 6);
myClassArray[2] = sortComparator.new MyClass("Java", 7);
myClassArray[3] = sortComparator.new MyClass("Android", 199);
myClassArray[4] = sortComparator.new MyClass("test", -3);
showMyClass(myClassArray);
Arrays.sort(myClassArray, comparatorName);
System.out.println("\nmyClassArray sorted by name");
showMyClass(myClassArray);
Arrays.sort(myClassArray, comparatorNumber);
System.out.println("\nmyClassArray sorted by number");
showMyClass(myClassArray);
}
static Comparator<? super MyClass> comparatorName
= new Comparator<MyClass>(){
public int compare(MyClass obj1, MyClass obj2) {
return String.valueOf(obj1.name).compareTo(obj2.name);
}
};
static Comparator<? super MyClass> comparatorNumber
= new Comparator<MyClass>(){
public int compare(MyClass obj1, MyClass obj2) {
return Integer.valueOf(obj1.number).compareTo(obj2.number);
}
};
static void showMyClass(MyClass[] mc){
for(int i = 0; i < mc.length; i++){
System.out.println(mc[i].name
+ " : "
+ mc[i].number);
}
}
}
Thursday, October 13, 2011
Sort Array
java.util.Arrays can be used to sort a array.
Example:
Related Article:
- Sort array of object using custom Comparator
Example:
import java.lang.String;
import java.util.Arrays;
public class exSortArray{
public static void main(String[] args){
String src[] ={
"MNO",
"A",
"DEF",
"GHI",
"JKL",
"PQR",
"BC",
"STU",
"YZ",
"VWX"};
System.out.println("Sort Array Exerecise");
System.out.println();
System.out.println("Array before Sort");
showAll(src);
System.out.println();
Arrays.sort(src);
System.out.println("Array after Sort");
showAll(src);
}
static void showAll(String[] a){
for(int i = 0; i < a.length; i++){
System.out.println(i + ": " + a[i]);
}
}
}
Related Article:
- Sort array of object using custom Comparator
Tuesday, October 11, 2011
Copy Array
The System class provide an arraycopy() method to copy array.
import java.lang.String;
public class exCopyArray{
public static void main(String[] args){
String src[] ={
"ABC",
"DEF",
"GHI",
"JKL",
"MNO",
"PQR",
"STU",
"VWX",
"YZ"};
System.out.println("Copy Array Exerecise");
showAll(src);
System.out.println();
String[] dest = new String[5];
System.arraycopy(src, //Copy from
2, //Source position
dest, //Copy to
0, //Destination position
5); //length to copy
showAll(dest);
}
static void showAll(String[] a){
System.out.println(a.toString());
for(int i = 0; i < a.length; i++){
System.out.println(i + ": " + a[i]);
}
}
}
Saturday, October 8, 2011
NetBeans IDE 7.1 Beta Released with JavaFX 2.0 supported
NetBeans IDE 7.1 Beta introduces support for JavaFX 2.0 by enabling the full compile/debug/profile development cycle for JavaFX 2.0 applications. The release also provides significant Swing GUI Builder enhancements, CSS3 support, and tools for visual debugging of Swing and JavaFX user interfaces. Additional highlights include Git support integrated into the IDE, new PHP debugging features, various JavaEE and Maven improvements, and more.
NetBeans IDE 7.1 Beta is available in English, Brazilian Portuguese, Japanese, Russian, and Simplified Chinese.
link: http://netbeans.org/community/releases/71/
NetBeans IDE 7.1 Beta is available in English, Brazilian Portuguese, Japanese, Russian, and Simplified Chinese.
link: http://netbeans.org/community/releases/71/
Monday, October 3, 2011
Exercise on LinkedList
import java.util.LinkedList;
public class exLinkedList{
static LinkedList<String> myLinkedList;
public static void main(String[] args){
System.out.println("LinkedList Exerecise");
myLinkedList = new LinkedList<String>();
myLinkedList.add("ABCDEF");
myLinkedList.add("G");
myLinkedList.add("HIJ");
myLinkedList.add("KLM");
myLinkedList.add("NOPQRST");
myLinkedList.add("UVW");
myLinkedList.add("XYZ");
showAll();
System.out.println();
myLinkedList.removeFirst();
myLinkedList.removeLast();
myLinkedList.remove("KLM");
myLinkedList.remove("JAVA"); //Can't found!
showAll();
}
static void showAll(){
for(int i = 0; i < myLinkedList.size(); i++){
System.out.println(myLinkedList.get(i));
}
}
}
Saturday, October 1, 2011
Java The Complete Reference, 8th Edition
The Definitive Java Programming Guide
In Java: The Complete Reference, Eighth Edition, bestselling programming author Herb Schildt shows you everything you need to develop, compile, debug, and run Java programs. Updated for Java Platform, Standard Edition 7 (Java SE 7), this comprehensive volume covers the entire Java language, including its syntax, keywords, and fundamental programming principles. You'll also find information on key elements of the Java API library. JavaBeans, servlets, applets, and Swing are examined and real-world examples demonstrate Java in action. In addition, new Java SE 7 features such as try-with-resources, strings in switch, type inference with the diamond operator, NIO.2, and the Fork/Join Framework are discussed in detail.
Coverage includes:
- Data types and operators
- Control statements
- Classes and objects
- Constructors and methods
- Method overloading and overriding
- Interfaces and packages
- Inheritance
- Exception handling
- Generics
- Autoboxing
- Enumerations
- Annotations
- The try-with-resources statement
- Varargs
- Multithreading
- The I/O classes
- Networking
- The Collections Framework
- Applets and servlets
- JavaBeans
- AWT and Swing
- The Concurrent API
- Much, much more
About the Author
Herbert Schildt is a world leading programming author. He is an authority on the C, C++, Java, and C# programming languages, and a master Windows programmer. His programming books have sold more than three million copies worldwide and have been translated into all major foreign languages. He is the author of numerous best sellers including C: The Complete Reference, Java 2: The Complete Reference, Java 2: A Beginner's Guide, C#: A Beginner's Guide, and many more. Schildt holds a master's degree in computer science from the University of Illinois.