Monday 29 September 2014

Automated Browser Compatibility Testing

This is excellent website for ..testing the all browser compatibility ....Testing
either by. Developer or Testing Team Can Utilize it
http://www.browsera.com/

Thursday 25 September 2014

Annotation vs xml

I have taken some of the useful comment from people..we can ..consider the points ..

There are benefits and drawbacks to using both XML and annotation based Spring configuration files. However, it doesn't have to be an 'either-or' type of decision.
There is a wider issue here, that of XML vs Annotation If your object model is only ever going to persisted in one way, then inlined meta-data (i.e. annotations) are more compact and readable.
If, however, your object model was reused in different applications in such a way that each application wanted to persist the model in different ways, then externalising the meta-data (i.e. XML descriptors) becomes more appropriate.
Neither one is better, and so both are supported, although annotations are more fashionable. More mature APIs like native Hibernate offer both, because it's known that neither one is enough.
--------------------------------------------------------------------------------------------------------------
Basically, there are pros and cons to all forms of configuration. Annotations, xml or Java Based Configuration. All the pros and cons are 100% valid. The main goal them becomes consistency. Making sure everyone on your project follows the same rules.
It is also NOT a question of either or, which one over the other. Because you can use any combination of configuration options in your application. One or all three combined. You just have to make your rules and stick to them
So my personal opinion is. Remember this is all my opinion and not fact.
1) Annotations over all other because I can configure and code much faster
2) Java Based configuration for those beans I can't annotate (They aren't my classes so I don't have the source to add an Annotation)
3) xml with what is left, or I need it complete externalized outside the package of my classes and I don't want to recompile and repackage. (Extremely rare, like it has never happened to me yet that I needed this)
--------------------------------------------------------------------------------------------------------------
First of all we use annotations for many more things, than just configuration.
Now: Some adventages of using annotations for configuration
Readability. For example in JPA configuration its much more cleaner to declare new entities by Annotations instead of hbm.xml files. These things change only in development stage so there is no problem with recompiling code. When You use xml files You have to often open both- entity and hbm file to make changes.. That can cause some erros.
Flexibility. In XML files you have to write all configs in "only one proper way". It is adventage and disadventage at the same time.
Length. XML-based configs are often very long (like pom's, or hbm's). Annotations are much simplier to use

Wednesday 24 September 2014

Difference Between ClassNotFoundException & NoClassDefFoundError

Assume the following classesprogram
|——–>Test.java
|———>Demo.java
Test.java
———-
public class Test{}
Demo.java
————-
?
1
2
3
4
5
6
7
public class Demo {
          public static void main(String s[])throws Exception {
 
              Class.forName("Test");  //line 1
              Test t=new Test();  //line 2
        }
 }
Observation
ClassNotFoundException
———————————
You keep only line 1(comment line 2),and compile and execute Demo.java,(Donot compile Test.java)it will give you ClassNotFoundException
What ever String you are passing in Class.forName(“—”) is a class name,and it should be there
solution:  Compile both the java files and then execute Demo class
NoClassDefFoundError
————————————–
Keep Only line 2(comment line 1),and compile and Execute Demo.java.The program successfully compiles &     Executes.It is because,when ur class Demo is using class Test,then No need to compile Test.java,when you compile Demo.java,it auto compiles Test.java
So when will I get Error?  Just remove . from ur classpath & recompile
In classpath generally we add  ;.  at last.
This is because,when the JVM looks for the classes,it looks in classpath and when it sees .  , it  understands that it has to look in the current working directory also.
But if you remove . from classpath,then here auto-compilation will not take place,means you have to compile all the classfiles using javac *.java.
Even after you have compiled both the classes,if u try to execute it,it will still show you NoClassDefFoundError,because u have removed . from classpath variable


Now comment both line1 & line 2,and again recompile only Demo.java
Compilation will be successful,but While execution it will give you sameNoClassDefFoundError


Solution:  include ;.  at your classpath

Can We Running javaProgram without main()? is it possible in JDK1.7 latest Version

it is not possible in in JDK1.7...gone are the days now.

Running Java Program without main() has become an old story now.
So far we used to write the program like this
StaticDemo.java
?
1
2
3
4
5
6
7
8
public class StaticDemo
{
   static
    {
        System.out.println("Hello");
        System.out.exit(0);
     }
}
And then >javac *.java>java StaticDemo
It compiles and runs successfully,printing Hello
This works well in JDK1.7 old versions(build 1.7.0-ea-b19)
But From jdk 1.7(build1.7.0-ea-b85),It gives run time Exception
Error: Main method not found in class StaticDemo, please define the main method
public static void main(String[] args)
The latest version while writing this article was build  jdk 1.7(build 1.7.0_03-b05),which also doesnot allow running java program without main();
So the Concept is:
When we say
java StaticDemo
Compiler understands that we are trying to execute the program,so before executing the static block,it first checks whether main() is there or not.If not,throws Exception