Must read: Java interfaces

http://www.javaworld.com/article/3171300/java-language/java-101-interfaces-in-java.html

When client code interacts with names, it will invoke those methods that are declared by List, and which are implemented by ArrayList.

Advertisements

Action time: Let’s start some project

Dear readers and me, I’ve decided that I should start developing my own application. Only this action can justify my accumulation of knowledge. Therefore, let’s decide on couple things:

  1. Frontend: jQuery, AJAX and JavaScript
  2. Backend: Spring framework

As for app idea, I’ve decided that I will be making clone of project which I’m working on now. But I won’t reuse any materials from it, only the knowledge I’ve acquired. I want my project to be opensource so all the codes will be available on my GitHub account. The link I will put once I got anything to show.

Thank you.

For the better Enterprise solutions!

I’ve decided to slightly divert from my Java SE certification preparation and research more about Spring framework. SF is chosen because it fits to be enterprise engine and it’s has good support among the developers. Beside that Oracle is borrowed the concept of Dependency injection from the Spring and implemented it in it’s own EJB.

Since I’m looking for job now, I might as well start building the web app on SF so that I can show the working prototype to employers.

I’ve completed couple spring started guides and uploaded one to the cloud:

http://ec2-54-169-251-194.ap-southeast-1.compute.amazonaws.com:8080/greeting

My other rest services, not Spring though:

Rest Post service via Jersey:

http://ec2-54-169-58-9.ap-southeast-1.compute.amazonaws.com:8080/RestServices/fileUpload.html

Rest Get service that returns JSON via Jackson and data taken using Hibernate:

http://ec2-54-169-58-9.ap-southeast-1.compute.amazonaws.com:8080/ServiceGetMenu/rest/menu/get

 

Static method and static variable

In Java, static denotes class methods and class variables (as opposed to instance methods and instance variables). These methods and variables can be accessed without an instance present.

Contrast this to instance methods and instance variables: they must be accessed through an object. For example, length() operates on an object:

String a = "hello";
int len = a.length();

In contrast, valueOf cannot operate on an object; moreover, it creates a new object when called:

String x = String.valueOf(123.45);

Note how instance methods are called using <objectName> followed by a dot ., while static methods are accessed using <className> followed by a dot ..

JUnit: Unit Testing

JUnit is used for unit testing. The unit testing is one of the testing methodologies that tests module or method that was written.

Writing the test is done by creating normal java class, except we use special annotations for it.

Note: best practice in unit testing is to have multiple tests for single method.

Let’s say you have method calculateMinAge(), it’s good idea to create multiple test methods

Unlike other java classes, JUnit test class has different structure:

@Suit or @TestRetention <– this annotation helps to include the current class file into larger test group, containing other test files

@Before <– this annotation can be used to initialize the objects that are used in different methods. Also the method name should be called setUp(). Ex:

@Before

public void setUp(){}

 

 

Inline If statement

In order to save the lines of code instead of using the typical if else we can use inline if statment:

skeleton is (a condition b ? do this() : do that())

ex1:

a=5;

(a>3 ? peal() : leave())

In above example a will be checked if it’s bigger than 3 if so run peal() if not run leave()

ex2:

getAge(a>3 ? a=10: null)

in above example if a more than 3 then a will be assigned to 10 if not then get will run with value null.