This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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: 63391
205
  • 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.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!