• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 49
Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 49
Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();?
 
author & internet detective
Posts: 41605
883
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 49
Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

yogesh doshi wrote:Why Line 17 returns false and Line 18 returns True ??

 
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic