• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java code review?  RSS feed

 
A Aggr
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have some code segments. Can someone please review them and tell me if anything is wrong:

1.)
String a=null;
if (a!=null & a.length()>10) {
System.out.println("Inside if");
}
System.out.println("Outside if");


2.)
int m = 0;
while( m++ < 2 )
System.out.println( m );
3.)

Hashtable hashtable = new Hashtable();
hashtable.put("One", “1”);
hashtable.put("Two", “2”);
hashtable.put("One", “1”);

while(hashtable.keys().hasMoreElements() ){
System.out.println(hashtable.keys().nextElement());
}

Thanks for the time
Regards
Arvind
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Arvind,

Welcome to Code Ranch Please ask specific question. Should we explain the code sample or the errors in it. Can you post what error you came across when you tried & what resolution you need.

Ok... just to give help on 3rd, the reference should point to a single object.

 
A Aggr
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks John.

actually i did not see any issue with teh code before executing it. when i executed, it went into infinite loop.

your solution is perfect!
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you figured out 1 & 2 by yourself... can you post the modified code with resolution?
 
A Aggr
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2nd is ok

for 1st it shd be:

String a=null;
if (a!=null && a.length()>10) {
System.out.println("Inside if");
}
System.out.println("Outside if");


regards
Arvind
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!