• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Operator

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Q 1.
Could anybody help me in understanding the execution order in the following code ?
class Test
{
public static void main(String[] args)
{
int[] a={11,12,13,14};
int[] b={0,1,2,3};
System.out.println(a[(a=b)[3]]);
}
}
Program will compile correctly and print 14 when executed.
Q 2.
What is a Daemon Thread ?
 
Ranch Hand
Posts: 1245
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Mamta Swain:
Hi,
Q 1.
Could anybody help me in understanding the execution order in the following code ?
class Test
{
public static void main(String[] args)
{
int[] a={11,12,13,14};
int[] b={0,1,2,3};
System.out.println(a[(a=b)[3]]);
}
}
Program will compile correctly and print 14 when executed.
Q 2.
What is a Daemon Thread ?


Q1. True
Q2. Daemon Thread exist only to serve user threads. it is stopped
if there are no more user threads running.
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mamta,
Q1 is explained in JLS 15.13.2. http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html
This thread discussed this question. http://www.javaranch.com/ubb/Forum24/HTML/003831.html
Though it's not related to your question, I think you will find this thread helpful. http://www.javaranch.com/ubb/Forum24/HTML/000775.html

[This message has been edited by Nain Hwu (edited October 26, 2001).]
 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mamta,
When you execute
System.out.println(a[(a=b)[3]]);
here is what happens
1. first b[3] is evaluated which is equal to 3
2. next value of b which is 3 is assigned to a.
3. a[3] which is 14 is printed out.
From what I understand assignment operator has low precedence .
so the expression is actually evaluated as
a[a=(b[3])]..
Anybody correct me if I am wrong..

Originally posted by Mamta Swain:
Hi,
Q 1.
Could anybody help me in understanding the execution order in the following code ?
class Test
{
public static void main(String[] args)
{
int[] a={11,12,13,14};
int[] b={0,1,2,3};
System.out.println(a[(a=b)[3]]);
}
}
Program will compile correctly and print 14 when executed.
Q 2.
What is a Daemon Thread ?


 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Anybody correct me if I am wrong"
You are wrong.
Braces "()" have higher precedence.
 
Nain Hwu
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roopa,


From what I understand assignment operator has low precedence .
so the expression is actually evaluated as a[a=(b[3])]..


No. a[(a=b)[3]] is not the same as a[a=(b[3])]. The latter
is not a valid expression (it will cause compilation error)
I suggest you read the threads I mentioned earlier.
 
Mamta Swain
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Nain for your reference threads.
It did helped me in understanding the actual order of operation.
- Mamta
 
What a show! What atmosphere! What fun! What a tiny ad!
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!