When you go for compilation of a simple class, what happens? A .class file is generated for that class. Yes. But what the -verbose switch tells us is appealing. I mean by javac -verbose HelloWorld.java. Obviously you do not have anything to do with the information other than to learn for yourself the happenings, and also have some idea about the application's performance, if it's big. Let's go with a demo.
Thursday, February 21, 2013
Wednesday, January 30, 2013
Removing unnecessary methods with inline code
Note: This holds only for smaller or restricted applications wherein the method logic is called at exactly one place or so. This is strict violation of object-oriented programming principles which advocate that each task or purpose should be served upon by an individual method as it warrants easy extensibility, and maintenance, apart from giving a clean picture of its job.
So, in any application, if we see that there might be future implementation change possibilities or the method is being called or may be called from multiple places in the application, then, even though if the current implementation has it that the method will be called from only one place, we have to put the logic in a separate method with an appropriate name and also mention in comment about the usage, if any.
Objective: "Put a method's logic into the body of its caller and remove the method”.
Friday, January 11, 2013
Exception in thread "main" java.lang.ExceptionInInitializerError
Documentation: java.lang.ExceptionInInitializerError
The API says:
Signals that an unexpected exception has occurred in a static initializer. An ExceptionInInitializerError is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable.
Lets take an example and see what is it exactly:
Tuesday, January 8, 2013
Time taken by various string concatenation methods
As the title goes, the objective of the folowing program will be to find out the time difference or performance various string concatenation methods:
i) + operator
ii) String class' concat() method
iii) StringBuffer class' append() method
iv) StringBuilder class' append() method
The program is followed by results in nanoseconds.
Labels:
+,
concat,
Java,
performance,
String,
StringBuffer,
StringBuilder
Saturday, January 5, 2013
Java Keywords
As of Java 7, there are 50 keywords. I have compiled them for convenience by grouping them into different categories.
> The static keyword has been mentioned twice just for the sake of completing the category.
> In data types, all keywords but void may be used as data type as well as return type of methods, void can be used only as return type.
Subscribe to:
Posts (Atom)