Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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
  #81 (permalink)  
Old 05-08-2008, 02:43 PM
Member
 
Join Date: May 2008
Posts: 1
ani548 is on a distinguished road
Hi
Hi All,

I am really cherished to be a part of this community.

Thank You.
Anish George
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #82 (permalink)  
Old 05-08-2008, 02:43 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 514
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Here is another one.. it is compilable.

Code:
public class Change { public static void main(String args[]) { System.out.println(1.00 - 0.60); } }
What should be the specific output?
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
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
  #83 (permalink)  
Old 05-08-2008, 02:45 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 514
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Hello ani548,

Welcome to Java Forums.
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
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
  #84 (permalink)  
Old 05-08-2008, 02:50 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 354
Zosden is on a distinguished road
Try to guess what this would print out

Code:
/** * @(#)Quiz.java * * * @author * @version 1.00 2008/5/8 */ public class Quiz { Rectangle rectangle1; Rectangle rectangle2; Rectangle rectangle3; Rectangle rectangle4; public Quiz() { rectangle1 = new Rectangle(); rectangle2 = new Rectangle(); rectangle3 = new Rectangle(); rectangle4 = new Rectangle(); System.out.println("Test 1"); System.out.println(this.toString()); rectangle1.setLength(10); rectangle1.setWidth(5); System.out.println("Test 2"); System.out.println(this.toString()); rectangle2 = rectangle1; rectangle2.setWidth(6); rectangle2.setLength(6); System.out.println("Test 3"); System.out.println(this.toString()); rectangle3 = (Rectangle)rectangle2.clone(); rectangle3.setWidth(10); rectangle3.setLength(14); System.out.println("Test 4"); System.out.println(this.toString()); rectangle4 = (Rectangle)rectangle3.clone(); rectangle3 = rectangle2; System.out.println("Test 5"); System.out.println(this.toString()); } public String toString() { String temp = "Rectangle 1: " + "\n" + rectangle1.toString() + "\n" + "\n"; temp += "Rectangle 2: " + "\n" + rectangle2.toString() + "\n" + "\n"; temp += "Rectangle 3: " + "\n" + rectangle3.toString() + "\n" + "\n"; temp += "Rectangle 4: " + "\n" + rectangle4.toString() + "\n" + "\n"; return temp; } public static void main(String[] args) { Quiz quiz = new Quiz(); } }
Code:
/** * @(#)Rectangle.java * * * @author * @version 1.00 2008/5/8 */ public class Rectangle { private int length; private int width; private int area; public Rectangle() { length = 1; width = 1; this.calcArea(); } private void calcArea() { area = length * width; } public int getLength() { return length; } public void setLength(int aLength) { length = aLength; this.calcArea(); } public int getWidth() { return width; } public void setWidth(int aWidth) { width = aWidth; this.calcArea(); } public Object clone() { Rectangle rectangle = new Rectangle(); rectangle.setLength(length); rectangle.setWidth(width); return rectangle; } public String toString() { String temp = "Area = " + area; temp += "\n" + "length = " + length; temp += "\n" + "width = " + width; return temp; } }
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #85 (permalink)  
Old 05-08-2008, 02:53 PM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
rjuyal is on a distinguished road
@
Code:
public class Change { public static void main(String args[]) { System.out.println(1.00 - 0.60); } }

0.39999999999999999999
Post if the answer is Correct


@ani

What about introducing yourself
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
Bookmark Post in Technorati
Reply With Quote
  #86 (permalink)  
Old 05-08-2008, 02:57 PM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
rjuyal is on a distinguished road
@Zosden
please split your question

keep the catching part only, please
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
Bookmark Post in Technorati
Reply With Quote
  #87 (permalink)  
Old 05-08-2008, 03:02 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 514
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
@ rjuyal... actually it is acceptable. but try to compile and run. it should be .4

I expect that one, but that maybe at

System.out.println(2.00 - 1.10);

It is something about the rules for converting double values to strings, which are specified by the documentation for Double.toString.
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
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
  #88 (permalink)  
Old 05-08-2008, 03:29 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 514
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Here is another one,

Code:
public class test{ private test(Object o) { System.out.println("Noob"); } private test(double[] dArray) { System.out.println("Java Programmer"); } public static void main(String[] args) { System.out.print("I am a "); new test(null); } }
Before you attempt to compile and run it, just guess what should be the output.....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
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
  #89 (permalink)  
Old 05-08-2008, 03:41 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 354
Zosden is on a distinguished road
I am a noob
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #90 (permalink)  
Old 05-08-2008, 03:52 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 514
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Now, try to compile it,.....

I really don't know what's the real/most specific reason for that it prints

Quote:
I am a Java Programmer.
For me, it seeks first to the most specific constructor that fits to the values passed. since Object is the most used in every built-In class, that one may (for me) first be compared.
Now, it tries to seek the other constructor that may fit the value passed, since an array can be set as null, that constructor was choosen to receive such value. (null)

If there is another explanation, please let me know....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
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
  #91 (permalink)  
Old 05-08-2008, 07:27 PM
Member
 
Join Date: Apr 2008
Posts: 28
fireball2008 is on a distinguished road
Send a message via AIM to fireball2008
YES for sure
Bookmark Post in Technorati
Reply With Quote
  #92 (permalink)  
Old 05-08-2008, 08:58 PM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 160
rjuyal is on a distinguished road
@fireball
what is YES for?
__________________
Newton said Gravitaion, Rakesh says Earth Sucks
Bookmark Post in Technorati
Reply With Quote
  #93 (permalink)  
Old 05-08-2008, 10:34 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 354
Zosden is on a distinguished road
Don't forget guys about my quiz.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #94 (permalink)  
Old 05-09-2008, 02:59 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 514
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
@ Zosden

I can't exactly predict what should be the output for that....

BIG LOL im running out of RAM

Just a piece of code from it. or a method.
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
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
  #95 (permalink)  
Old 05-09-2008, 04:18 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yes Zosden, keep your question short and sweet.
__________________
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.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
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.
(Close on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
  #96 (permalink)  
Old 05-09-2008, 05:29 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by sukatoa View Post
If there is another explanation, please let me know....
Basically Object is the root of the class hierarchy. Every class has a Object as a superclass. So any objects implements the method of this class. So why we get the output as,

Code:
I am a Java Programmer
arrays also included in this way, and array can be initialized as null.

See the difference with the following code.

Code:
public class test{ private test(Object o) { System.out.println("Noob"); } private test(int value) { System.out.println("Java Programmer"); } public static void main(String[] args) { System.out.print("I am a "); new test(null); } }
__________________
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.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
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.
(Close on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
  #97 (permalink)  
Old 05-09-2008, 05:31 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Here is a simple one again.

What's the output of the following line of code.

Code:
System.out.println((String)'Java');
__________________
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.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
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.
(Close on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
  #98 (permalink)  
Old 05-09-2008, 07:09 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
Hello All,
----------------

Compile time error......
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #99 (permalink)  
Old 05-09-2008, 07:26 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,532
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
What type of? and what the reason?
__________________
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.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
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.
(Close on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
  #100 (permalink)  
Old 05-09-2008, 07:29 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
Quote:
Originally Posted by Eranga View Post
What type of? and what the reason?
Because you can put only single character in '......', you are putting string into '......'.
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply