Sep 052011
 

A programmer uses the keyboard more often than the mouse, and when typing, a right click to select a function also costs much time and effectiveness.

No matter you’re an eclipse user or a new comer to Eclipse, the following list of shortkeys can help you to save much time.

Ctrl + Shift + O : to open Resource.

image thumb5 Use short keys to save your time with Eclipse

You can use this shortkey to open almost everything, and the good news is that you can use expression character like * or extension like .java or .html… eg: if I want to search for a Java file that contains “Test” in the file name, I can use the expression like the above: *Test*.java.

Ctrl + / : to comment a line, Ctrl + Shift + / to comment multiple lines
Ctrl + E : to open current editors, you can use expression here to search for file name.

image thumb6 Use short keys to save your time with Eclipse

Ctrl + O : to open Inherited Members of class.

image thumb7 Use short keys to save your time with Eclipse

Tips: you can also use expression to search and jump to methods or fields.

Ctrl + Shift + O: To organize Imports

Most of the time, Eclipse can automatically imports classes in other packages for you. But sometimes you need to import them manually. Use Ctrl + Shift + O can help you import unique class automatically and for classes that have the same name, it will popup a selector for you.

Continue reading »

Jul 142011
 

If your Java application runs out of memory (Tomcat, jBoss, Eclipse…), the following error occurs:

Exception in thread “main” java.lang.OutOfMemoryError: Java heap space

This can have two reasons:

  • Your Java application has a memory leak. There are tools like YourKit Java Profiler that help you to identify such leaks.
  • Your Java application really needs a lot of memory (more than 128 MB by default!). In this case the Java heap size can be increased using the following runtime parameters:

java -Xms -Xmx

Defaults are: Continue reading »

Jul 142011
 

Recently a friend of mine asked me “What the hell is Java Reflection? What is it used for ?” After a couple of minutes explaining for him that Java Reflection was invented to “introspect” Java class by giving away meta-data that explain the Java class itself and blah blah…but seemed like he didn’t understand at all, I decide to write a blog, and here it goes. OK suppose that you have a Man class with following declaration:

package copy;

/**
 * Java Reflection Object Copier by http://java.searchdaily.net
 * 
 * @author namnvhue
 * 
 */
public class Man {
	private String copyName; // can be copied
	private String copyEmail; // can be copied
	private String copyAddress; // can be copied
	private Integer nationalIdentityNumber; // cannot be copied
	private String bankAccount;

	public Man() {
		// default value
		this.copyName = "Robin Hood";
		this.copyAddress = "123 The Earth";
		this.copyEmail = "robin@hood.com";
		this.nationalIdentityNumber = 12345;
		this.bankAccount = "B12345";
	}

	public void gotoSchool() {

	}

	public void goFishing() {

	}

	public String getCopyName() {
		return copyName;
	}

	public void setCopyName(String copyName) {
		this.copyName = copyName;
	}

	public String getCopyEmail() {
		return copyEmail;
	}

	public void setCopyEmail(String copyEmail) {
		this.copyEmail = copyEmail;
	}

	public String getCopyAddress() {
		return copyAddress;
	}

	public void setCopyAddress(String copyAddress) {
		this.copyAddress = copyAddress;
	}

	public Integer getNationalIdentityNumber() {
		return nationalIdentityNumber;
	}

	public void setNationalIdentityNumber(Integer nationalIdentityNumber) {
		this.nationalIdentityNumber = nationalIdentityNumber;
	}

	public String getBankAccount() {
		return bankAccount;
	}

	public void setBankAccount(String bankAccount) {
		this.bankAccount = bankAccount;
	}

}
 


And then you have a SuperMan class as follow:

package copy;

/**
 * Java Reflection Object Copier by http://java.searchdaily.net
 * 
 * @author namnvhue
 * 
 */
public class SuperMan {
	private String copyName; // can be copied
	private String copyEmail; // can be copied
	private String copyAddress; // can be copied
	private Integer nationalIdentityNumber; // cannot be copied
	private String bankAccount;
	private String superWeapon;

	public SuperMan() {
		// default value
		this.copyName = "Peter Pan";
		this.copyAddress = "123 Never Land";
		this.copyEmail = "peter@pan.com";
		this.nationalIdentityNumber = 54321;
		this.bankAccount = "S54321";
		this.superWeapon = "LightSpeed Pistol";
	}

	public void gotoSchool() {

	}

	public void goFishing() {

	}

	public String getCopyName() {
		return copyName;
	}

	public void setCopyName(String copyName) {
		this.copyName = copyName;
	}

	public String getCopyEmail() {
		return copyEmail;
	}

	public void setCopyEmail(String copyEmail) {
		this.copyEmail = copyEmail;
	}

	public String getCopyAddress() {
		return copyAddress;
	}

	public void setCopyAddress(String copyAddress) {
		this.copyAddress = copyAddress;
	}

	public Integer getNationalIdentityNumber() {
		return nationalIdentityNumber;
	}

	public void setNationalIdentityNumber(Integer nationalIdentityNumber) {
		this.nationalIdentityNumber = nationalIdentityNumber;
	}

	public String getBankAccount() {
		return bankAccount;
	}

	public void setBankAccount(String bankAccount) {
		this.bankAccount = bankAccount;
	}

	public String getSuperWeapon() {
		return superWeapon;
	}

	public void setSuperWeapon(String superWeapon) {
		this.superWeapon = superWeapon;
	}
}

 


OK, first I’ll show you how to use Java Reflection to examine object.

Continue reading »