• 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Methods  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone
I have a trouble because i don't understand the following question

class Test{
  public static int[] getArray() {  return null;  }
  public static void main(String[] args){
     int index = 1;
     try{
        getArray() [index=2]++;
     }
     catch (Exception e){  }  //empty catch
     System.out.println("index = " + index);
  }
}

Especially this sentence ( getArray() [index=2]++; ) confuse me . Deeply [index=2]++; i don't understand this . What is the benefit or necessary is use it ?
An anyone can  help me ?
Thanks in advance .
 
Marshal
Posts: 62231
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Darya Naghiyev wrote:. . . . Deeply [index=2]++; . . . What is the benefit or necessary is use it ? . . . .

The only benefit of that code is that it confuses people reading practice questions for their cert exams. You should only use it in real life if you want to get sacked immediately The empty catch block won't get you sacked quite as quickly.
Pease start by telling us where the code comes from.

It is all about order of execution. I suggest you put something in the catch block to find out what sort of exception you might catch. Then go back to the code and work out the order of execution, remembering the rules are
  • 1: Go left to right.
  • 2: Evaluate subexpressions with higher precedence operators or in brackets before the whole expression can be completed.
  • Write down al the stages.
     
    You may have just won ten million dollars! Or, maybe a tiny ad.
    RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
    https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!