Home page

Most commented over the month

Removing element from list

May 14, 2014, 15:51

What is the result of this code?

List<Integer> integers = new ArrayList<Integer>();
integers.add(1);
integers.add(2);
integers.add(3);
integers.add(4);
integers.add(5);
for (Integer integer : integers) {
   if (integer % 2 == 0) {
      integers.remove(integer);
   }
}

When does the finally block not execute?

Apr 5, 2013, 20:37
try {
    System.exit(0);
} finally {
    System.out.println("finally");
}

How to start, restart, stop MySQL on MacOS from terminal

Jun 8, 2016, 12:53

Start
sudo /usr/local/mysql/support-files/mysql.server start

Stop
sudo /usr/local/mysql/support-files/mysql.server stop

Restart
sudo /usr/local/mysql/support-files/mysql.server restart

Exceptions in Java

Apr 2, 2013, 15:11

What is the result of this code?

Task 1.

public static void m() {
try {
    throw new Exception();
} catch (Exception e) {
    System.out.println("catch");
} finally {
    System.out.println("finally");
}

Task 2.

int i = 0;
try {
    throw new Exception();
} catch (Exception e) {
    i = 10;
    return i;
} finally {
    i = 20;
}

Task 3.

int i = 0;
try {
    throw new Exception();
} catch (Exception e) {
    i = 10;
    return i;
} finally {
    i = 20;
    return i;
}

List of practical project

Apr 17, 2016, 4:56

There is the list of practical project for those who want programming more and more.

https://github.com/karan/Projects