This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Why does the code flow execute in the below order  RSS feed

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does the code flow execute in the below order, and what impact does the additional angular brackets have?

I do not understand why ac are output first? Any ideas? Thanks




 
Marshal
Posts: 60065
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please always tell us where such questions come from, to avoid copyright problems and to allow us to see the source. I presume the bad formatting was in the source; some cert book writers like to try and mislead their readers with bad formatting.
I presume you have compiled and executed that code. In which case you will have a corresponding .class file. Inspect the bytecode with javap -c _05_Question_ That will show you the order in which code is imputed as part of the constructor.

If that doesn't explain it, I shall come back later and give you some more hints.
 
Mark S.Raphael
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, sure. On this occasion, the source code has come from a mock exam for OCA which I acquired from a book that I have purchased.

Exam 1Z0-808

http://javarevisited.blogspot.ch/2015/11/5-free-ocajp8-ocpjp8-mock-exams-and-practice-questions.html#ixzz5EOf2MIzR



 
Campbell Ritchie
Marshal
Posts: 60065
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for telling us the source.

Have you worked out why you got acbd yet?
 
Mark S.Raphael
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, not yet.
I will try what you have suggested shortly.
 
Campbell Ritchie
Marshal
Posts: 60065
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mark S.Raphael wrote:. . . I will try what you have suggested shortly.

Good, but I probably can't reply until tomorrow, so you might have a wait.
 
Mark S.Raphael
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell,

The response from using the javap -c commands are as follows:

  Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>")V
       4: return

  public static void main(java.lang.String[]);
    Code:
       0: iconst_1
       1: istore_1
       2: iload_1
       3: aload_0
       4: arraylength
       5: if_icmpgt     23
       8: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
      11: aload_0
      12: iload_1
      13: aaload
      14: invokevirtual #3                  // Method java/io/PrintStream.printlnLjava/lang/String;)V
      17: iinc          1, 1
      20: goto          2
      23: return
 
Mark S.Raphael
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does the output in the previous post help me?
 
Campbell Ritchie
Marshal
Posts: 60065
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's something missing. I got different results when I tried it; I had more code for the constructor. Let's try again. Which version of Java® are you using?Tick the disable smilies box
Note that in bytecode the constructors are replaced by pseudo‑methods called <init>
I hope that printout will be more helpful to you.
 
Campbell Ritchie
Marshal
Posts: 60065
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had been using Java10; I got this result with Java5, whihc i sthe oldest version I appear to have installed:-That doesn't appear any different from the Java10 version, at least when you correct for the poor formatting.
 
Mark S.Raphael
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay thanks for that. I was using Java 10
 
Campbell Ritchie
Marshal
Posts: 60065
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a pleasure but has it helped answer your question?
 
Mark S.Raphael
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I can see how to use this utility to assist with the analysis
 
Campbell Ritchie
Marshal
Posts: 60065
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you worked it out yet?
 
Mark S.Raphael
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am clear on the code execution sequence. thanks; and thanks again for showing me the utility to debug the code
 
Campbell Ritchie
Marshal
Posts: 60065
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!