Posts

Showing posts from September, 2014

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 Types The 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. C

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

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

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 sort   List   collections 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 a   List   you do this: List list = new ArrayList(); //add elements to the list Collections.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 interface   java.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); } The   compareTo()   me

Resolving Excel Export I/O Stream Error/Fatal Error Issue

Problem:     Fatal Application Error while exporting search results data into an excel sheet. Root Cause for the Issue is: The Root Cause of the issue is Because of using the global (Instance) variables instead of using the method variables inside the class for writing the data to the excel file. In Struts 1.1/1.2 the Action class behaves like singleton. There will be only one instance of the action for all the incoming requests. So whenever we try to build our logic using the instance variables (The variables which we are defining at the top of the class outside the method area) instead of local variables (or method variables), we will face data inconsistency issues. If we are using this kind of variables for IO operations then we will be ending with Stream errors (like the one we faced in one of our application recently). In the case of our (XYZ) application, there was a call to flushRows(100) function on

Disabled Form Fields Strange Behavior

Disabled form fields of html will not get the values (or will get null) after submitting the Form:  Code like below for the input form fields in HTML will generate the disabled field. Disabled field is the one which is not editable, not focusable, won’t get tab navigation, and can’t select the field. These are the characteristics of the disabled form field. We can apply this attribute on all input fields, buttons, select box, etc.  Please find the code below: <input type=”text” name=”accountNumber” value=”123455” disabled=”disabled”   /> The above code will generate the disabled text field where we can’t be able to edit and select the field. Characteristics of Disabled form fields: 1)    Disabled form field cannot be focusable, i.e. you cannot focus the field. 2)    Disabled fields are non-editable. 3)    Disabled fields will not be submitted when submission of form happens or when we will click on ‘Submit’ button. 4)    Disabled fields will give n

Top 15 Java Web sites

http://www.mkyong.com/ https://www.java.net/ https://www.ibm.com/developerworks/java/ http://www.devx.com/Java/ http://java-source.net/ http://java.dzone.com/ http://www.jdocs.com/ http://www.java-tips.org/ http://www.java4s.com/ http://javabrains.koushik.org/ http://www.derekashmore.com/ http://www.sitenol.com/ http://www.developer.com/java http://www.javaworld.com/ http://www.java-j2ee-by-shidram.blogspot.com/

Useful Java Debugging Tips with Eclipse

Image
In this tutorial we will see about debugging java applications using Eclipse. Debugging helps us to identify and fix defects in the application. We will focus on run-time issues and not compile time errors. There are command line debuggers like gdb available. In this tutorial we will focus on GUI based debugger and we take our favorite IDE Eclipse to run through the tutorial. Though we say Eclipse, the points are mostly generic and is suitable for debugging using most of the IDEs like NetBeans too. Do not use  System.out.println  as a tool to debug. Enable detailed log level of all the components involved. Use a log analyzer to read logs. 1. Conditional Breakpoint Hope we know how to add a breakpoint. If not, just click on the left pane (just before the line number) and a breakpoint will be created. In debug perspective, ‘Breakpoints’ view will list the breakpoint created. We can add a boolean condition to it. That is, the breakpoint will be activated an