|
||||||
| 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. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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");
}
}
and this is another code Code:
if (new String("true")==new String("true"))
System.out.println("true");
else
System.out.println("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. |
| Sponsored Links |
|
|
|
|||||
|
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 |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |
| John | ........ | 223.00000 |
| dargueta | ........ | 168.00000 |
| Xav | ........ | 164.00000 |
| gaylo565 | ........ | 18.00000 |
| WingedPanther | ........ | 15.00000 |
| |pH| | ........ | 15.00000 |
| Johnnyboy | ........ | 3.00000 |
| navghost | ........ | 1.00000 |
Goal: 100,000 Posts
Complete: 65%