Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can anyone help me with Java 8 question (Java OCA 8 Programmer I Study Guide, Sybex)

 
yogesh doshi
Ranch Hand
Posts: 35
Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The answer is four error when I run this on Java 8 environment I found that 3 error were displayed.....The error at declaration of bench variable was not displayed..
Untitled.png
[Thumbnail for Untitled.png]
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yogesh doshi wrote:The answer is four error when I run this on Java 8 environment I found that 3 error were displayed.....The error at declaration of bench variable was not displayed..

This topic discusses exactly the same question. So it's definitely worth reading

Hope it helps!
Kind regards,
Roel

PS. I wonder why you have posted the javac commands as a screenshot and not simply as a plain code snippet (don't forget to UseCodeTags )? If I want to compile (and execute) your code snippets, I know have to type them myself. And yes, I am (very) lazy So I'll be losing precious time which I could otherwise be spending on typing a nice reply... And another reason: attached images are not searchable using the search engine, some text or a code snippet definitely is.
 
yogesh doshi
Ranch Hand
Posts: 35
Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the result of the following?
code=java]
1: public class Order {
2: static String result = "";
3: { result += "c"; }
4: static
5: { result += "u"; }
6: { result += "r"; }
7: }
1: public class OrderDriver {
2: public static void main(String[] args) {
3: System.out.print(Order.result + " ");
4: System.out.print(Order.result + " ");
5: new Order();
6: new Order();
7: System.out.print(Order.result + " ");
8: }
9: }
[/code]
I am not able to understand the flow of the code .....why ucer is coming for first new Test(); and not for second new Test();?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yogesh,
Watch what is static and not. The static parts will only be run once.
 
yogesh doshi
Ranch Hand
Posts: 35
Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yogesh doshi wrote:Why Line 17 returns false and Line 18 returns True ??
 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
== compares references of objects and .equals compares contents of that String objects.

Each time you used + operator, String concatination is done which creates new String object so variable a refers to an object of String having "2cfalse" which has different object reference than reference of object created by Sting literal "2cfalse" so == returns false but .equals() returns true.

This might help you understand It, click here --->Strings, Literally by Corey McGlone

Note: Please don't add line numbers in codes. Line numbers are automatically added when you use code tags. Use only code tags, don't use quote tag when posting code.
Go through this ---> Use Code Tags
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic