Interesting Java code

View previous topic View next topic Go down

Interesting Java code

Post by BIT0112-Rokon on Sun Jun 05, 2011 9:53 am

Compile and run, you will understand Smile

Code:

public class HelloWorld {
    public static void main(String[] args) {
        new Object() {
            public void sayHello(){
                System.out.println("hello guys,");
            }
        };
       
        Long value = new Long(0);
        System.out.println(value.equals(0));

    }
}


_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী
avatar
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Re: Interesting Java code

Post by BIT0102-Mohaimin on Mon Jun 06, 2011 12:40 pm

Code:

        System.out.println(value.equals(0L));
will give you true.
However, I have checked that 1==1L gives true. The problem is possibly with the equals methods' implementation in Long.

By the way, was that anonymous Object necessary?
avatar
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

View user profile

Back to top Go down

Re: Interesting Java code

Post by BIT0112-Rokon on Tue Jun 07, 2011 7:39 am

nope, that was another interesting part. I just wanted to show how we can use Anonymous Object. May be some of us don't know about it, that was my thought.

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী
avatar
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Re: Interesting Java code

Post by jeniferjohn on Fri Jul 29, 2011 2:59 pm

Code:

for (int i=0; i<mName.length()-1; i++)
{
    for (int j=i+1; j<fName.length()-1;j++)
      if (mName.charAt[i] == fName.charAt[j])
          ok = true;
     
      if (ok == true)
        ++nr;
}

allChars = fName.length() + mName.length();
percentage = (nr*100)/allChars;


Last edited by BIT0102-Mohaimin on Tue Aug 02, 2011 7:48 pm; edited 1 time in total (Reason for editing : Added code tag)

jeniferjohn
Pre-Alpha Release
Pre-Alpha Release

Course(s) :
  • N/A

Blood Group : NULL
Posts : 3
Points : 3

View user profile

Back to top Go down

Re: Interesting Java code

Post by BIT0122-Amit on Fri Jul 29, 2011 3:14 pm

Now, that is an interesting piece of code JeniferJohn Very Happy

I wonder though, I have seen your posts and they are intriguing. There are two things I would like to request.

One is, please use the code tag when you are sharing codes with us, like this!

Code:

[code]Hello world[/code]

The second one, please introduce yourself to us. We will certainly like to get familiar with you.

_________________________________________________________________
Adminship / Moderatorship is not about power, it is about Responsibility.

|About me|My Blog|
avatar
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

View user profile http://iitdu.forumsmotion.com

Back to top Go down

Re: Interesting Java code

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum