Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #201 (permalink)  
Old 06-30-2008, 09:37 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 187
rjuyal is on a distinguished road
correct!


long variable cannot be used as array index, only integer is accepted
__________________
i am the future
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #202 (permalink)  
Old 06-30-2008, 09:40 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 252
sanjeevtarar is on a distinguished road
Will not compile....i think so
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #203 (permalink)  
Old 06-30-2008, 09:42 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 252
sanjeevtarar is on a distinguished road
One from my side
Will this compile..??if yes...Output
Code:
public class TestQue { public static void main(String[] args) { int j; for(int i=0;i<14;i++) { if(i<10) { j = 2 + i; } } System.out.println("j: " + j + " i: " + i); } }
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #204 (permalink)  
Old 06-30-2008, 09:42 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by rjuyal View Post
correct!


long variable cannot be used as array index, only integer is accepted


I have to use the correct word too. INDEX.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #205 (permalink)  
Old 06-30-2008, 09:45 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by sanjeevtarar View Post
One from my side
Will this compile..??if yes...Output
Code:
public class TestQue { public static void main(String[] args) { int j; for(int i=0;i<14;i++) { if(i<10) { j = 2 + i; } } System.out.println("j: " + j + " i: " + i); } }
Out of bound

You have exceed the variable scope. How lucky I'm to find it. You can't use variable 'i' in println(). It's valid only within the for loop.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #206 (permalink)  
Old 06-30-2008, 09:50 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 252
sanjeevtarar is on a distinguished road
Very good.....if we remove i from SOP....??
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #207 (permalink)  
Old 06-30-2008, 10:15 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 252
sanjeevtarar is on a distinguished road
Output..??..or..??
Code:
public static void main(String args[]) { int total = 0; int[] i = new int[3]; for(int j=1;j<= i.length; j++) total += (i[j] = j); System.out.println(total); }
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #208 (permalink)  
Old 06-30-2008, 10:25 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
<=

ArrayOutOfBoundException at run time. Compiled is ok, runtime failed. Right?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #209 (permalink)  
Old 06-30-2008, 10:34 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 252
sanjeevtarar is on a distinguished road
yes.............
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #210 (permalink)  
Old 06-30-2008, 10:52 AM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 299
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
Code:
public class TestQue { public static void main(String[] args) { int j; for(int i=0;i<14;i++) { if(i<10) { j = 2 + i; } } System.out.println("j: " + j + " i: " + i); } }
Quote:
Very good.....if we remove i from SOP....??
Compilation Error: "j" not initialized correct?
__________________
To finish sooner, take your own time....
Nivedithaaaa
Bookmark Post in Technorati
Reply With Quote
  #211 (permalink)  
Old 06-30-2008, 11:03 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yep, that's right. But compile and try, that error get if the scope error is fix.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #212 (permalink)  
Old 07-21-2008, 01:09 PM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 187
rjuyal is on a distinguished road
once more!!!
xcuse to wake you again..

will it compile, if yes then what will be the output.

--

Code:
public class InheritanceTest { public static void main(String[] args) { Base base = new Child(); base.fun(); base.fun2(); } } class Base{ public void fun(){ System.out.println("Fun in Base"); } public static void fun2(){ System.out.println("Fun2 in Base"); } } class Child extends Base{ public void fun(){ System.out.println("Fun in Child"); } public static void fun2(){ System.out.println("Fun2 in Child"); } }
---------
__________________
i am the future
Bookmark Post in Technorati
Reply With Quote
  #213 (permalink)  
Old 07-22-2008, 02:08 AM
Member
 
Join Date: Jun 2008
Posts: 7
dlorde is on a distinguished road
When the same is different...
If you like Java puzzles, this'll kill you ;-)

What's the output ?
Code:
public static void main(String[] args) { Integer i1a = Integer.valueOf(124); Integer i1b = Integer.valueOf(124); Integer i2a = Integer.valueOf(133); Integer i2b = Integer.valueOf(133); System.out.println("i1a == i1b : " + (i1a == i1b)); System.out.println("i2a == i2b : " + (i2a == i2b)); }
Bookmark Post in Technorati
Reply With Quote
  #214 (permalink)  
Old 07-22-2008, 02:12 AM
Member
 
Join Date: Jun 2008
Posts: 7
dlorde is on a distinguished road
rjuyal, static methods belong to the reference type, non-static methods belong to the instance type.
Bookmark Post in Technorati
Reply With Quote
  #215 (permalink)  
Old 07-22-2008, 06:40 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by rjuyal View Post
xcuse to wake you again..

will it compile, if yes then what will be the output.

--

Code:
public class InheritanceTest { public static void main(String[] args) { Base base = new Child(); base.fun(); base.fun2(); } } class Base{ public void fun(){ System.out.println("Fun in Base"); } public static void fun2(){ System.out.println("Fun2 in Base"); } } class Child extends Base{ public void fun(){ System.out.println("Fun in Child"); } public static void fun2(){ System.out.println("Fun2 in Child"); } }
---------

Nice to see that we are moving with this again after a long time.

Ok, for me this code segment is compiling and the output is,

Quote:
Fun in child
Fun2 in base
What you say pal,
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #216 (permalink)  
Old 07-22-2008, 06:46 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by dlorde View Post
If you like Java puzzles, this'll kill you ;-)

What's the output ?
Code:
public static void main(String[] args) { Integer i1a = Integer.valueOf(124); Integer i1b = Integer.valueOf(124); Integer i2a = Integer.valueOf(133); Integer i2b = Integer.valueOf(133); System.out.println("i1a == i1b : " + (i1a == i1b)); System.out.println("i2a == i2b : " + (i2a == i2b)); }
True/false validation with wrapper classes. So the output is,

Quote:
i1a == i1b : true
i2a == i2b : false
Because you exceed the NUMBER 127 there. Hops you got the point.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #217 (permalink)  
Old 07-22-2008, 09:37 AM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 187
rjuyal is on a distinguished road
@Eranga ,
correct answer of my question.

can you elaborate the answer of previous question

Quote:
Because you exceed the NUMBER 127 there. Hops you got the point.
__________________
i am the future
Bookmark Post in Technorati
Reply With Quote
  #218 (permalink)  
Old 07-22-2008, 08:05 PM
Member
 
Join Date: Jul 2008
Posts: 32
Engineeringserver.com is on a distinguished road
After reading the thread i'm itching to write my own test quiz and test if anyone can solve it =) Anyway, you could also read the book "java puzzlers" it contains many questions and some of the answers might be what you wouldn't expect.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

<--
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Java developer
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #219 (permalink)  
Old 07-23-2008, 01:32 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Nice code to have a fun to all of us......
Quote:
Originally Posted by rjuyal View Post
@Eranga ,
correct answer of my question.

can you elaborate the answer of previous question
First of all sorry for the late replay. So here we got a nice thread to discuss. Lets have a fun pal.

At the time, change 124 to 127 and, 133 to 128 and run the code. What you get? Confusing?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or imag