Java Glossary : newbie

CMP home Java glossary home Menu no menu Last updated 2004-06-28 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : N words : newbie.

newbie
An inexperienced Java programmers. Here is how to code like a newbie by inserting the tell-tale signs inexperienced Java programmers leave in their code. You might want to masquerade as someone young and inexperienced. Here is how to do it in your Java Code.

Boolean Redundancy

Newbies love to balloon out their code with redundancy. Here are some typical examples: Newbies will write:
if ( i < 7 )
   {
   return true;
   }
else
   {
   return false;
   }
An experienced programmer would handle that as:
return i < 7;
A newbie might try:
return b ? true : false;
It should be handled:
return b;
A newbie might code:
return b ? false : true;
It should be handled:
return !b;
avoid:
boolean b;
if ( i < 7 )
   {
   b = true;
   }
else
   {
   b = false;
   }
just use:
boolean b = i < 7;
Similarly avoid this redundancy:
if ( b == true ) j++;
just use:
if ( b ) j++;
A newbie might code:
if ( a.startsWith ( "c$$" ) )
   {
   System.out.println( "true" );
   }
else
   {
   System.out.println( "false" );
   }
You could abbreviate that as:
System.out.println( a.startsWith( "c$$" ) );

String Redundancy

Newbies love to write things like:
String s = new String( "abc" );
To avoid littering the constant pool with redundant Strings, this should be written:
String s = "abc";
Newbies write things like:
String s = new String();
To avoid littering the constant pool with redundant copies of "", this should be written:
String s = "";
new String(String) rarely has legitimate use. One use is freeing up RAM of a large base String when you no longer need the base base String, but only want the substring kept around. If you use it otherwise you create needless duplicate Strings in your literal pool. For details on when new String( String) is valid, see intern.

If Redundancy

if ( i <= 10 )
   {
   /*... */
   }
else if ( 11 <= i && i <= 15 )
   {
   /*... */
   }
should be written:
if ( i <= 10 )
   {
   /*... */
   }
else if ( i <= 15 )
   {
   /*... */
   }
A newbie might code:
public String getNull()
   {
   return(String)null;
   }
There is no need to cast null, so this method is not needed at all. Plain null will do.

Conversions

Instead of consulting conversion in the Java glossary to find the optimal code, newbies, concoct preposterously complicated chains of conversions to convert a double to a String for example, leaving behind a trail of discarded dummy objects. Here is some typical newbie code:
String s = "1";
int i= new Integer(s).intValue(); /* newbie */
int i = Integer.parseInt( s ); /* correct */
//...
int i = 1;
String s = new Integer( i ).toString(); /* newbie */
String s = i + ""; /* lazy */
String s = Integer.toString( i ); /* correct */

Too Big And Flexible a Hammer

Newbies discover exceptions and use them where simpler and more efficient constructs would work better. For example they might use them in place of a loop ending condition or even a boolean return flag.

Reflection dazzles, and newbies will use it where simple interfaces and delegate objects would suffice.

Sometimes an old-fashioned if or switch statement is easier to understand and maintain than a complicated nest of inherited classes. A newbie is intoxicated with the power of oo and wants to use it everywhere.

The more advanced newbie might discover the facade design pattern, and go overboard thinking that every class should implement every method with a wrapper.

If you enjoyed this essay you might like this one on how to write unmaintainable code.


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 19778.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/newbie.html J:\mindprod\jgloss\newbie.html