Skip to main content

Posts

Showing posts from 2014

How To Resolve "Java compiler level does not match the version of the installed Java project facet." Issue in Eclipse, STS tool or Eclipse Based Tools

I have faced this issue during the Java 7 upgrade from Java 6 into one of our application. You will face this issue suppose if your application or project built on lower versions of Java (in my case it is Java 1.6) and you are trying to upgrade it to the Higher versions of Java (in My case it is Java 1.7), then Eclipse will throw this error in the tool. You will face this error even after changing the compiler version from build path. To fix this issue Follow the Below Mentioned Steps.


1.  Open the 'Markers' Tab at the bottom of the eclipse or STS tool beside the 'Properties' Tab. (as shown in the below figure)



2. Right Click on the Error as mentioned in the below figure. in The context menu click on the 'Quick Fix' item as shown below in the figure.


3. Select the correct Java Project Facet from the 'Quick Fix' Window. and click on the 'Finish' Button.


4.  After Clicking on 'Finish' button you cannot see the error. Please check the figure b…

Java Important Links

Java Performance Checklist

Specify the required performance. Ensure performance objectives are clear.Specify target response times for as much of the system as possible.Specify all variations in benchmarks, including expected response ranges (e.g., 80% of responses for X must fall within 3 seconds).Include benchmarks for the full range of scaling expected (e.g., low to high numbers of users, data, files, file sizes, objects, etc.).Specify and use a benchmark suite based on real user behavior. This is particularly important for multi-user benchmarks.Agree on all target times with users, customers, managers, etc., before tuning.

Make your benchmarks long enough: over five seconds is a good target. Use elapsed time (wall-clock time) for the primary time measurements.Ensure the benchmark harness does not interfere with the performance of the application.Run benchmarks before starting tuning, and again after each tuning exercise.Take care that you are not measuring artificial situations, such as full caches contain…

Be-Aware of the Performance of the String Concatenation...

The string concatenation operator (+) is a convenient way to combine a few strings into one. It is fine for generating a single line of output or for constructing the string representation of a small, fixed-size object, but it does not scale. Using the string concatenation operator repeatedly to concatenate n strings requires time quadratic in n. It is an unfortunate consequence of the fact that strings are immutable. When two strings are concatenated, the contents of both are copied.

For example, consider the following method that constructs a string representation of a billing statement by repeatedly concatenating a line for each item:

// In-appropriate use of string concatenation - Hits Performance drastically!

public String statement() {
     String res = "";
     for (int i = 0; i < numOfItems(); i++)
      res += lineOfItem(i); // String concatenation
      return res;
}

This method performs very slow if the number of items is large. To achieve acceptable performance, use a …

Some Important Facts About Core Java

There are 4 important OOPS concepts in Java : Inheritance, Abstraction, Encapsulation and Polymorphism.There are two types of variables in Java : Primitive types and Object TypesThe default value of Boolean is false (the same applies for the Wrapper class too).Marker interface is the one which doesn't contains any methods, it is like empty interface.You cannot override the 'main' method of the Java, even-though if you try to do so it will not give any exception, program compiles and executes fine. The reason is : 'main' method is of type static. Static methods are class level methods. Even-though it looks like method overriding, it is not overriding. These are two different method with respect to the corresponding class.You can Overload the 'main' method of Java, it is valid in Java.You can have only one 'Public' class and any number of non-public classes in any java source file.Inheritance is an example for IS-A relationship.Composition is an examp…

Rules for Overloading the Method in Java

You can overload a method by changing its signature. method signature is made of number of arguments, type of arguments and order of arguments.Return type is not a part of method signature, so changing method return type means no overloading unless you change argument with return type.A method can be overloaded in the same class or in a subclass. if class A defines a display(float i) method, the subclass B could define a display(String s) method without overriding the super-class version that takes an int. So two methods with the same name but in different classes can still be considered overloaded, if the subclass inherits one version of the method and then declares another overloaded version in its class definition.

Rules for Overriding the Method in Java

The argument list must exactly same that of the overridden method. If they don't match, you can end up with an overloaded method.The return type must be the same as, or a sub-type of, the return type declared in the original overridden method in the super-class (also called co-variant return type).Instance methods can be overridden only if they are inherited by the subclass.A subclass within the same package as the instance's super-class can override any super-class method that is not marked private or final. A subclass in a different package can override only those non-final methods marked public or protected (since protected methods are inherited by the subclass).The overriding method can throw any unchecked (run-time) exception, regardless of whether the overridden method declares the exception.The overriding method must not throw checked exceptions that are new or broader than those declared by the overridden method. For example, a method that declares a…

How To Increase PermGenSpace Of Eclipse ?

If you see java.lang.OutOfMemoryError: PermGen space errors, you need to increase the permanent generation space available to Eclipse. PermGen is the permanent generation of objects in the VM (Class names, internalized strings, objects that will never get garbage-collected). An easy, if somewhat memory-hungry fix is to enlarge the maximum space for these objects by adding,
“-XX:MaxPermSize=128M”
as an argument to the JVM when starting Eclipse. The recommended way to do this is via your eclipse.ini file. Alternatively, you can invoke the Eclipse executable with command-line arguments directly, as in
“eclipse [normal arguments] -vmargs -XX:PermSize=64M -XX:MaxPermSize=128M [more VM args]”
Note: The arguments after -vmargs are directly passed to the VM. Run java -X for the list of options your VM accepts. Options starting with -X are implementation-specific and may not be applicable to all JVMs (although they do work with the Sun/Oracle JVMs).
Eclipse and Sun VMs on Windows
Eclipse 3.3 and above…

Sorting the list of objects in Java

This article will explain about sorting the collection of objects. The document will explain how to sort list or set of objects placed in a collection and also what are the pre-requisites to sort any list or set which is having the list of objects.
You can sortListcollections using the java.util.Collections.sort()method. You can sort these two types of List's.
1.List 2.LinkedList
Sorting Objects by their Natural Order
To sort aListyou do this:


List list = new ArrayList();//add elements to the listCollections.sort(list);
When sorting a list like this the elements are ordered according to their "natural order". For objects to have a natural order they must implement the interfacejava.lang.Comparable. In other words, the objects must be comparable to determine their order. Here is how the Comparable interface looks:
public interface Comparable<T> {  int compareTo(T o);}