checkout my new app under development:
Category: Java EE
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
.
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:
- Frontend: jQuery, AJAX and JavaScript
- 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.
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
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:
1 2 |
<span class="typ">String</span><span class="pln"> a </span><span class="pun">=</span> <span class="str">"hello"</span><span class="pun">;</span> <span class="kwd">int</span><span class="pln"> len </span><span class="pun">=</span><span class="pln"> a</span><span class="pun">.</span><span class="pln">length</span><span class="pun">();</span> |
In contrast, valueOf
cannot operate on an object; moreover, it creates a new object when called:
1 |
<span class="typ">String</span><span class="pln"> x </span><span class="pun">=</span> <span class="typ">String</span><span class="pun">.</span><span class="pln">valueOf</span><span class="pun">(</span><span class="lit">123.45</span><span class="pun">);</span> |
Note how instance methods are called using <objectName>
followed by a dot .
, while static methods are accessed using <className>
followed by a dot .
.
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(){}
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.
In case of conflicts,
1. copy Current changes from Right to left
2. right click on the file, Mark as merged.
One rule-of-thumb: ask yourself “does it make sense to call this method, even if no Obj has been constructed yet?” If so, it should definitely be static.
So in a class Car you might have a method double convertMpgToKpl(double mpg) which would be static, because one might want to know what 35mpg converts to, even if nobody has ever built a Car. But void setMileage(double mpg) (which sets the efficiency of one particular Car) can’t be static since it’s inconceivable to call the method before any Car has been constructed.