Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Java Help

Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-07-2008, 03:51 PM
simpatico simpatico is offline
Newbie
 
Join Date: May 2007
Posts: 8
Rep Power: 0
simpatico is on a distinguished road
Default help me with this code pllz

Code:
public class Q10{
public static void main(String [] args)
{
int i =10;
int j =10;
boolean b =false ;
if (b=i==j)
System.out.printLn("true");
else
System.out.println("false");
}
}
this code print true why i dont understand .any one plz explain to me

and this is another code
Code:
if (new String("true")==new String("true"))
System.out.println("true");
else
System.out.println("false");
why this code will print ((false))
wts the different between the first new string and the second
plz explain to me

Last edited by simpatico; 04-07-2008 at 03:57 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-08-2008, 10:46 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,034
Last Blog:
NaNoWriMo Day 23 The...
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: help me with this code pllz

b=i==j compares i and j first (returns true). Now you have b=true, which assigns b the value true and evaluates to true.

The new operator returns a pointer to the string that has been created. The two new pointers are not equal, so the output is false.

The key to both is understanding the order of operations and what the operators/functions return.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hi5 tiny slideshow code crap... Godiva983 General Programming 1 06-23-2008 04:46 PM
help me with this code pllz simpatico C and C++ 2 03-11-2008 01:57 AM
Basic Calculator AfTriX VB Tutorials 3 02-29-2008 08:53 AM
Generating executable machine code steffanp General Programming 5 02-03-2008 10:01 AM


All times are GMT -5. The time now is 04:10 PM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 65%

Ads