Saturday, 22 June 2013

java.lang.classnotfoundexception org.hibernate.annotations.entity

java.lang.classnotfoundexception org.hibernate.annotations.entity
 
Add this jar file
 
hibernate-annotations.jar  

Sunday, 16 June 2013

java.lang.IllegalStateException: Failed to load ApplicationContext

TRY this 
@ContextConfiguration(locations = { "/applicationContext.xml",
                                    "/applicationContext-test.xml"})

The attribute value is undefined for the annotation type ContextConfiguration

try this

@ContextConfiguration(locations = {"/applicationContext.xml"})

ROMANTIC GUITAR MUSIC Relaxing Instrumental

http://www.youtube.com/watch?v=njBOWJwTHvY

The import org.springframework.test cannot be resolved

The import org.springframework.test cannot be resolved

 

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.ContextConfiguration;

 

 

Add this to resloved this 

 

spring-test-2.5.4.jar

 

 

http://www.jarfinder.com/index.php/java/info/org.springframework.test.context.ContextConfiguration

import org.custommonkey.xmlunit.XMLAssert;

add this jar file

MAVEN2
 http://mirrors.ibiblio.org/pub/mirrors/maven2/xmlunit/xmlunit/1.0/xmlunit-1.0.jar
OR
 http://www.findjar.com/jar/xmlunit/xmlunit/1.0/xmlunit-1.0.jar.html?all=true

Choose unique values for the 'webAppRootKey' context-param in your web.xml files!

Sovled this err by using
 Add this in web.xml file
<context-param>
<param-name>WEBAPPROOTKEY</param-name>
<param-value> Unique ID </param-value>
</context-param>

 

 For this kind of error


java.lang.IllegalStateException: Web app root system property already set to different value: 'webapp.root' = ....... instead of .....................- Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
    at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(WebUtils.java:144)
    at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:117)
    at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:45)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 60

org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 60 Solved Using this Adding metadata-complete="true" to your web.xml should sort the issue Example Like this


<web-app version="3.0"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         metadata-complete="true">

Saturday, 15 June 2013

ArrayList vs LinkedList in Java

1) Both ArrayList and LinkedList are implementation of List interface, which means you can pass either ArrayList or LinkedList if a method accepts Listinterface.

2) Both ArrayList and LinkedList are not synchronized, which means you can not shared them between multiple threads without external synchronization.

3) ArrayList and LinkedList are ordered collection e.g. they maintain insertion order of elements i.e. first element will be added on first position.

4) ArrayList and LinkedList also allows duplicates and null unlike any other List implementation e.g. Vector.

5) Iterator of both LinkedList and ArrayList are fail-fast which means they will throw ConcurrentModificationExceptionif collection is modified structurally once Iterator is created. They  are different than CopyOnWriteArrayList whose Iterator is fail-safe.

What Is an Interface?

an interface is a group of related methods with empty bodies. A bicycle's behavior, if specified as an interface, might appear as follows:
interface Bicycle {

    //  wheel revolutions per minute
    void changeCadence(int newValue);

    void changeGear(int newValue);

    void speedUp(int increment);

    void applyBrakes(int decrement);
}
To implement this interface, the name of your class would change (to a particular brand of bicycle, for example, such asACMEBicycle), and you'd use the implements keyword in the class declaration:
class ACMEBicycle implements Bicycle {

    // remainder of this class 
    // implemented as before
}
Implementing an interface allows a class to become more formal about the behavior it promises to provide. Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile.

What is base class of applet?

java.applet.Applet class is based class in applet

what is method signature in java

Definition:
A method signature is part of the method declaration. It is the combination of the method name and the parameter list.
The reason for the emphasis on just the method name and parameter list is because of overloading. It's the ability to write methods that have the same name but accept different parameters. The Java compiler is able to discern the difference between the methods through their method signatures.
Examples:
public void setEmpReference(int xCoordinate, int yCoordinate) 
{
  //method code
}
The method signature is setEmpReference(int, int) – i.e., the method name and the parameter list of two integers. The Java compiler will let us add another method like so:
public void setEmpReference(Point position) 
{
  //method code
}
because it's method signature is different – setEmpReference(Point).

Friday, 14 June 2013

core java

1 What is a transient variable?
Ans: A transient variable is a variable that may not be serialized.
2 Which containers use a border Layout as their default layout?
Ans: The window, Frame and Dialog classes use a border layout as their default layout.
3 Why do threads block on I/O?
Ans: Threads block on I/O (that is enters the waiting state) so that other threads may execute while the I/O Operation is performed.
4 How are Observer and Observable used?
Ans: Objects that subclass the Observable class maintain a list of observers. When an  Observable object is updated it invokes the update () method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.
5 What is synchronization and why is it important?
Ans: With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object’s value. This often leads to significant errors.
6 Can a lock be acquired on a class?
Ans: Yes, a lock can be acquired on a class. This lock is acquired on the class’s Class object.
7 What’s new with the stop (), suspend () and resume () methods in JDK 1.2?
Ans: The stop (), suspend () and resume () methods have been deprecated in JDK 1.2.

8 Is null a keyword?
Ans: The null value is not a keyword.
9 What is the preferred size of a component?
Ans: The preferred size of a component is the minimum component size that will allow the component to display normally.
10 What method is used to specify a container’s layout?
Ans: The set Layout () method is used to specify a container’s layout.
11 Which containers use a Flow Layout as their default layout?
Ans: The Panel and Applet classes use the Flow Layout as their default layout.
12 What state does a thread enter when it terminates its processing?
Ans: When a thread terminates its processing, it enters the dead state.
13 What is the Collections API?
Ans: The Collections API is a set of classes and interfaces that support operations on collections of objects.

14 Which characters may be used as the second character of an identifier, but not as the first character of an identifier?
Ans: The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.
15 What is the List interface?
Ans: The List interface provides support for ordered collections of objects.
16 How does Java handle integer overflows and underflow?
Ans: It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.
17 What is the Vector class?
Ans: The Vector class provides the capability to implement a grow able array of objects
18  What modifiers may be used with an inner class that is a member of an outer class?
Ans: A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.

19 What is an Iterator interface?
Ans: The Iterator interface is used to step through the elements of a Collection.
20 What is the difference between the >> and >>> operators?
Ans: The >> operator carries the sign bit when shifting right. The >>> zero-fills bits that have been shifted out.

Hibernate Data types

Hibernate Data Types :
Hibernate data type plays an important roll as it acts like a bridge between java types and DB data types.
It is necessary to choose correct data type during table creation. Hibernate data types are used when we write 
hibernate mapping files(*.hbm.xml) . This is also known as mapping types.
Here we are categorizing the mapping types in  Hibernate -
1. Primitive Types :
Java TypeHibernate TypeSQL Type
int/java.lang.Integerinteger INTEGER
long/java.lang.LonglongBIGINT
short/java.lang.ShortshortSMALLINT
float/java.lang.FloatfloatFloat
double/java.lang.DoubledoubleDOUBLE
java.math.BigDecimalbig_decimalNUMERIC
java.lang.StringcharacterCHAR(1)
java.lang.StringstringVARCHAR
byte/java.lang.BytebyteTINYINT
boolean/java.lang.BooleanbooleanBIT
boolean/java.lang.Booleanyes_noCHAR(1)('Y' or 'N')
boolean/java.lang.Booleantrue/falseCHAR(1)('T' or 'F')
2.Date and Time Type :
Java TypeHibernate TypeSQL Type
java.util.Date/java.sql.DatedateDATE
java.util.Date/java.sql.TimetimeTIME
java.util.Date/java.sql.TimestamptimestampTIMESTAMP
java.util.CalendercalenderTIMESTAMP
java.util.Calendercalender_dateDATE
3.Binary and Large Object Type :
Java TypeHibernate TypeSQL Type
byte[]binaryVARBINARY/BLOB
java.lang.StringtextCLOB
any java class that implements java.io.SerializableserializableVARBINARY/BLOB
java.sql.ClobclobCLOB
java.sql.BlobblobBLOB
4.Other JDK-related Type :
Java TypeHibernate TypeSQL Type
java.lang.ClassclassVARCHAR
java.util.LocalelocaleVARCHAR
java.util.TimeZonetimezoneVARCHAR
java.util.CurrencycurrencyVARCHAR

The import org.springframework.stereotype cannot be resolved

java faq

Thread's stop( ), suspend( ), and resume( ) methods.?
What are Wrapper classes?
Primitive data type Wrapper class byte Byte short Short int Integer long Long float Float double Double char Character boolean Boolean

  transient object in hibernate
object finalize method

A new instance of a a persistent class which is not associated with a Session, has no representation in the database and no identifier value is considered transient by Hibernate:
Person person = new Person();
person.setName("Foobar");
// person is in a transient state
A persistent instance has a representation in the database, an identifier value and is associated with a Session. You can make a transient instance persistent by associating it with a Session:
Long id = (Long) session.save(person);
// person is now in a persistent state
Now, if we close the Hibernate Session, the persistent instance will become a detached instance: it isn't attached to a Session anymore (but can still be modified and reattached to a new Session later though).

Thursday, 13 June 2013

Chnage focus to next field when the value reaches to maximum length. javascript example


<html>
<head>
<script language="javascript">
function jumpNext(x,y){
  if (y.length==x.maxLength){
    var next=x.tabIndex;
    if (next<document.getElementById("myForm").length){
      document.getElementById("myForm").elements[next].focus();
    }
  }
}
</script>
</head>
<body>
<center>
<b>Enter your date of birth in DD MM
and YYYY formate such as 24 11 2001</b>
<br>
<br>
<form id="myForm" >
  <input size="3" tabindex="1" maxlength="2"
    onkeyup="jumpNext(this,this.value)">
  <input size="2" tabindex="2" maxlength="2"
    onkeyup="jumpNext(this,this.value)">
  <input size="3" tabindex="3" maxlength="4"
    onkeyup="jumpNext(this,this.value)">
</form>
</center>
</body>
</html>




Wednesday, 12 June 2013

alphanumeric characters validation regular expression


^[0-9]+(\.[0-9]{1,2})?$

regular expression for two decimal number

And since regular expressions are horrible to read, much less understand, here is the verbose equivalent:

^                   # Start of string.
[0-9]+              # Must have one or more numbers.
(                   # Begin optional group.
    \.              # The decimal point, . must be escaped,
                    # or it is treated as "any character".
    [0-9]{1,2}      # One or two numbers.
)?                  # End group, signify it's optional with ?
$                   # End of string.


Test here

 http://www.regular-expressions.info/javascriptexample.html

Creating a JAR File


The basic format of the command for creating a JAR file is:
jar cf jar-file input-file(s)
The options and arguments used in this command are:
  • The c option indicates that you want to create a JAR file.
  • The f option indicates that you want the output to go to a file rather than to stdout.
  • jar-file is the name that you want the resulting JAR file to have. You can use any filename for a JAR file. By convention, JAR filenames are given a .jar extension, though this is not required.
  • The input-file(s) argument is a space-separated list of one or more files that you want to include in your JAR file. The input-file(s) argument can contain the wildcard * symbol. If any of the "input-files" are directories, the contents of those directories are added to the JAR archive recursively.
The c and f options can appear in either order, but there must not be any space between them.

An Example

Let us look at an example. A simple TicTacToe applet. You can see the source code of this applet by downloading the JDK Demos and Samples bundle from Java SE Downloads. This demo contains class files, audio files, and images having this structure:

TicTacToe folder Hierarchy
The audio and images subdirectories contain sound files and GIF images used by the applet.
You can obtain all these files from jar/examples directory when you download the entire Tutorial online. To package this demo into a single JAR file named TicTacToe.jar, you would run this command from inside the TicTacToe directory:

jar cvf TicTacToe.jar TicTacToe.class audio images

Tuesday, 11 June 2013

how to convert long to string in java

for this type of Err ==> Type mismatch: cannot convert from long to String.

public class LongToString {

  public static void main(String q[]){
   
    long lDateTime = new Date().getTime();
        System.out.println("Date() - Time in milliseconds: " + lDateTime);

        Calendar lCDateTime = Calendar.getInstance();
        System.out.println("Calender - Time in milliseconds :" + lCDateTime.getTimeInMillis());
        String s = String.valueOf(lCDateTime.getTimeInMillis());
        System.out.println("Long to Sting  :" + s);
       
}

    }