This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How This Java Program Executes ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How This Java Program Executes ?" Watch "How This Java Program Executes ?" New topic
Author

How This Java Program Executes ?

Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787

Hello to All My JavaRanch Friends

I created the following code when I worked with the java coding
I found following type of code
after editting, compiling and running the code.



When I try to compile and run the following output produced

i = 256 and j = 128

Also note down one thing by observation the value of i is exactly two times greater than value of j

When you reduce the number of i's and j's in the Line 1 above you get same result that is the value of i is exactly two times greater than value of j

How java code executes in the above program?
Please Help on this


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Patel Chintan
Ranch Hand

Joined: Mar 01, 2007
Posts: 80
Originally posted by Ninad Kulkarni:
Hello to All My JavaRanch Friends

I created the following code when I worked with the java coding
I found following type of code
after editting, compiling and running the code.



When I try to compile and run the following output produced

i = 256 and j = 128

Also note down one thing by observation the value of i is exactly two times greater than value of j

When you reduce the number of i's and j's in the Line 1 above you get same result that is the value of i is exactly two times greater than value of j

How java code executes in the above program?
Please Help on this


You can simplyfy Line 1 to:
i *= j *= i *= j *= i *= j *= i *= j;
i = I * (j *= i *= j *= i *= j *= i *= j)
1=i*(j*( i *= j *= i *= j *= i *= j))
I= i*(j*(i*( j *= i *= j *= i *= j)))
I= i*(j*(i*( j*( i *= j *= i *= j))))
I= i*(j*(i*( j*( i *( j *= i *= j))))
I= i*(j*(i*( j*( i *( j *( i *= j)))))
I= i*(j*(i*( j*( i *( j *( i * j))))))

And so J=j*(i*( j*( i *( j *( i * j)))))
That means = I= 2*(2*(2*( 2*( 2 *( 2 *( 2 * 2))))) = 256

and j = 2*(2*( 2*( 2 *( 2 *( 2 * 2)))) =128


Chintan Patel, SCJP1.5, http://datewithjava.blogspot.com
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787

Thanks a lot Patel Chintan
now I got it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How This Java Program Executes ?
 
Similar Threads
volatile example
Control Loop
JLS 8.3.1.4 Volatile Fields.
Please explain to me a line of code in a method that converts bytes to Hex-Values?
I am not getting the required output...