Interface vs Abstract class


An interface is a contract: the guy writing the interface says, “hey, I accept things looking that way“, and the guy using the interface says “Ok, the class I write looks that way“.

An interface is an empty shell, there are only the signatures of the methods, which implies that the methods do not have a body. The interface can’t do anything. It’s just a pattern.
Implementing an interface consumes very little CPU, because it’s not a class, just a bunch of names, and therefore there is no expensive look-up to do. It’s great when it matters such as in embedded devices.

Abstract classes

Abstract classes, unlike interfaces, are classes. They are more expensive to use because there is a look-up to do when you inherit from them.

Abstract classes look a lot like interfaces, but they have something more : you can define a behavior for them. It’s more about a guy saying, “these classes should look like that, and they have that in common, so fill in the blanks!”.



Eclipse optimization

It’s better to use latest version of Eclipse, which is Mars 2, as of now. Also it’s recommended to use Java 8 for faster loads. You can add this configuration to the eclipse.ini file, make sure that you put the correct path to javaw.exe:

C:/Program Files/Java/jdk1.8.0_74/bin/javaw.exe

Conflicts with repository

It may happen that your code no longer is latest version. Therefore you need to get latest code from repository, but if you do so, the changes you made will be lost.
Therefore this is the steps needs to be done to remove the conflicts.

1. Try to commit your code
2. Eclipse will tell that your code is not latest from repository
3. Click the Synchronize SVN button
4. The files you wanted to commit become red
5. Open one of the files, look at the right corner of the compare window
6. If the little square there is blue(or looks like black) then you can proceed with automatic merger. it’s called “Copy All Non-Conflicting Changes from right to left”
7. Then right click on the file and “Mark as Merged”
8. The file is ready to be committed.

Note, if the square on the right top corner is red, you should do manual merge.

Eclipse debugging

Debugging is used to find the place where the bug occurs. This is done by setting up break points in the code, so when you run your application it will run the code up until point where you put your first break point. Also debugging in Eclipse provides with window that shows the values of the variables at the current breakpoints.

F8 is most used button while debugging since it allows to resume to next break point. Dev should focus most on proper places to put the break points.

Good naming in programming

It should tell you why it exists, what it does, and how it is used. If a name requires a comment, then the name does not reveal its intent.

steps for good naming

  1. write the method
  2. rename the attributes to meaningful names
  3. be careful with names that are different only a little bit ex.: XYZabcdStorageHandling and XYZabcdLocationHandling
  4. no l or 0 letters in variable names since they look like digit 1 and 0
  5. Noise words are redundant. The word variable should never appear in a variable
    name. The word table should never appear in a table name. How is NameString better than Name? Would a Name ever be a floating point number? If so, it breaks an earlier rule about disinformation. Imagine finding one class named Customer and another named CustomerObject. What should you understand as the distinction? Which one will represent the best path to a customer’s payment history?
  6. WRONG!
    1. getActiveAccount();
    2. getActiveAccounts();
    3. getActiveAccountInfo();
    1. Class Names
      Classes and objects should have noun or noun phrase names like Customer, WikiPage, Account, and AddressParser. Avoid words like Manager, Processor, Data, or Info in the name of a class. A class name should not be a verb.
    2. Method Names
      Methods should have verb or verb phrase names like postPayment, deletePage, or save. Accessors, mutators, and predicates should be named for their value and prefixed with get,set, and is according to the javabean standard.
      string name = employee.getName();
      if (paycheck.isPosted())
  7. However one might decide to use the word add for “consistency” when he or she is not in fact adding in the same sense. Let’s say we have many classes where add will create a new value by adding or concatenating two existing values. Now let’s say we are writing a new class that has a method that puts its single parameter into a collection. Should we call this method add? It might seem consistent because we have so many other add methods, but in this case, the semantics are different, so we should use a name like insert or append instead. To call the new method add would be a pun. Using the same term for two different ideas is essentially a pun.