• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java code review?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic