Posts

Showing posts with the label funny java code

Some amazing java features

 Goto initialization; // code goes here   getmeout :{      for ( int i = 0 ; i < N ; ++ i ) {          for ( int j = i ; j < N ; ++ j ) {              for ( int k = j ; k < N ; ++ k ) {                  //do something here                  break getmeout ;              }          }      } } Null Check :  Haven't seen anyone mention instanceof being implemented in such a way that checking for null is not necessary. Instead of: if ( null != aObject && aObject instanceof String ) {      ... } just use: if ( aObject instanceof S...

Weird Funny Java!

Image
Weird Funny Java! Sometimes we can do really weird and funny things with Java; Some other times we are just being creative! Take a look at the following three examples and you will find out what I mean! Have Fun! Strine translator Translating to Strine  01 public   static   void   main(String... args) { 02          System.out.println( "Hello World" ); 03      } 04 05      static   { 06          try   { 07              Field value = String. class .getDeclaredField( "value" ); 08              value.setAccessible( true ); 09              value.set( "Hello World" , value.get( "G'Day Mate." )); 10 ...