2 Most Useful Java Quotes for Java Developers

2 Most Useful Java Quotes for Java Developers

Quote 1: Prevent developing needless things and always want to do Sluggish Initialization

Learn Java

Object development in Java is one of the most costly functions with regards to storage usage and efficiency effect. It is thus recommended to make or initialize an item only when it is needed in the system code.

public class Countries {

     private List countries;

public List getCountries() {

//initialize only when required

if(null == countries) {

countries = new ArrayList();

}

return countries;

}

}

Quote 2: Never make example areas of category public

Making a category area community can cause lot of problems in a system. For example you may have a category known as MyCalender. This category contains a range of Sequence Monday to Friday. But as this range is community, it may be utilized by anyone. Someone by error also may modify the value and place a bug!

public class MyCalender {

public String[] weekdays =

{“Sun”, “Mon”, “Tue”, “Thu”, “Fri”, “Sat”, “Sun”};

//some code

}

Best strategy as many of you already know is to always make the area personal and add a getter technique to accessibility the components.

private String[] weekdays =

{“Sun”, “Mon”, “Tue”, “Thu”, “Fri”, “Sat”, “Sun”};

public String[] getWeekdays() {

return weekdays;

}

But composing getter technique does not exactly fix our issue. The range is still available. Best way to make it unmodifiable is to come back a replicated of range instead of range itself. Thus the getter technique will be modified to.

public String[] getWeekdays() {

return weekdays.clone();

}

Thus you can be a part of our program to learn java.

Don't be shellfish...Email this to someonePrint this pageTweet about this on TwitterShare on StumbleUponShare on TumblrShare on LinkedInShare on RedditDigg thisShare on Google+Pin on PinterestShare on FacebookBuffer this page

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>