EzDevInfo.com

java-ee interview questions

Top java-ee frequently asked interview questions

java.lang.UnsupportedClassVersionError Unsupported major.minor version 51.0 [duplicate]

Possible Duplicate:
unsupported major .minor version 51.0

I am trying to build an application, but it gives some error. My jdk version is given below:

java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) Client VM (build 20.5-b03, mixed mode, sharing)

Here is my Error Log:

Buildfile: build.xml

compile:
     [echo] Compiling the service....
     [echo]   ...mkdir for classes first....
     [echo]   ...java classes next....
     [echo]   ...mkdir for generated code next....
     [echo]  ...generate stubs/skeletons next....
[wscompile] command line: wscompile -d /home/vivekray/program/MTrans/WEB-INF/classes -features:wsi,documentliteral -gen:server -keep -model /home/vivekray/program/MTrans/WEB-INF/model.gz -verbose -Xprintstacktrace /home/vivekray/program/MTrans/src/config.xml -classpath /home/vivekray/program/MTrans/WEB-INF:/home/vivekray/program/MTrans/WEB-INF/classes:/home/vivekray/program/MTrans/lib/log4j-1.2.16.jar:/home/vivekray/jwsdp-2.0/jwsdp-shared/lib/mail.jar:/home/vivekray/jwsdp-2.0/jwsdp-shared/lib/activation.jar:/home/vivekray/jwsdp-2.0/jaxp/lib/jaxp-api.jar:/home/vivekray/jwsdp-2.0/jaxp/lib/endorsed/dom.jar:/home/vivekray/jwsdp-2.0/jaxp/lib/endorsed/sax.jar:/home/vivekray/jwsdp-2.0/jaxp/lib/endorsed/xalan.jar:/home/vivekray/jwsdp-2.0/jaxp/lib/endorsed/xercesImpl.jar:/home/vivekray/jwsdp-2.0/jaxrpc/lib/jaxrpc-api.jar:/home/vivekray/jwsdp-2.0/jaxrpc/lib/jaxrpc-spi.jar:/home/vivekray/jwsdp-2.0/jaxrpc/lib/jaxrpc-impl.jar:/home/vivekray/jwsdp-2.0/saaj/lib/saaj-api.jar:/home/vivekray/jwsdp-2.0/saaj/lib/saaj-impl.jar:/home/vivekray/jwsdp-2.0/jwsdp-shared/lib/relaxngDatatype.jar:/home/vivekray/jwsdp-2.0/jwsdp-shared/lib/xsdlib.jar:/home/vivekray/jwsdp-2.0/jwsdp-shared/lib/jax-qname.jar:/home/vivekray/jwsdp-2.0/apache-ant/lib/ant.jar:/home/vivekray/jwsdp-2.0/fastinfoset/lib/FastInfoset.jar:/home/vivekray/Softwares/apache-tomcat-7.0.27/lib/servlet-api.jar
[wscompile] [creating model: mtransservice]
[wscompile] [creating service: Mtransservice]

BUILD FAILED
java.lang.UnsupportedClassVersionError: in/cdac/mobile/computing/mtrans/MtransService : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at org.apache.tools.ant.AntClassLoader.defineClassFromData(AntClassLoader.java:1146)
    at org.apache.tools.ant.AntClassLoader.getClassFromStream(AntClassLoader.java:1324)
    at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1388)
    at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1341)
    at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1088)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:295)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at com.sun.xml.rpc.processor.modeler.rmi.RmiUtils.getLoadableClassName(RmiUtils.java:78)
    at com.sun.xml.rpc.processor.modeler.rmi.RmiUtils.getRealName(RmiUtils.java:54)
    at com.sun.xml.rpc.processor.modeler.rmi.RmiModeler.modelPort(RmiModeler.java:676)
    at com.sun.xml.rpc.processor.modeler.rmi.RmiModeler.buildLiteralModel(RmiModeler.java:603)
    at com.sun.xml.rpc.processor.modeler.rmi.RmiModeler.buildModel(RmiModeler.java:457)
    at com.sun.xml.rpc.processor.config.ModelInfo.buildModel(ModelInfo.java:88)
    at com.sun.xml.rpc.processor.Processor.runModeler(Processor.java:63)
    at com.sun.xml.rpc.tools.wscompile.CompileTool.run(CompileTool.java:714)
    at com.sun.xml.rpc.util.ToolBase.run(ToolBase.java:43)
    at com.sun.xml.rpc.tools.ant.Wscompile.execute(Wscompile.java:746)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    at org.apache.tools.ant.Main.runBuild(Main.java:758)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

Total time: 1 second

Source: (StackOverflow)

What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?

May I know what is the difference between:-

  1. Spring
  2. Struts
  3. Struts 2
  4. Hibernate
  5. JavaServer Faces
  6. JavaServer Pages
  7. Tapestry

Are these technologies/framework complementary to each other? Or they are alternatives to each other (after I use one of them, then I don't need to use the other)?

Thanks.


Source: (StackOverflow)

Advertisements

.war vs .ear file

What is the difference between a .war and .ear file?


Source: (StackOverflow)

Difference between Java SE/EE/ME?

Which one should I install when I want to start learning Java? I'm going to start with some basics, so I will write simple programs that create files, directories, edit XML files and so on, nothing too complex for now.

I guess Java SE (Standard Edition) is the one I should install on my Windows 7 desktop. I already have Komodo IDE which I will use to write the Java code.


Source: (StackOverflow)

Is "Java Concurrency In Practice" still valid?

Is Java Concurrency in Practice by Brian Goetz, David Holmes, Doug Lea, Tim Peierls, Joshua Bloch, Joseph still valid ? I ask because the latest edition seems to be done in 2006, ie, it was six years ago.

Can anybody who has the edition and know current Java(7) advise me ?

PS : By 'valid' I mean the ideas, concepts and implementation described in the book is still compliant with latest Java version.

Thanks.


Source: (StackOverflow)

Spring - How to call a method after bean initialization is complete?

I have a use case where I need to call a (non-static) method in the bean only-once at the ApplicationContext load up. Is it ok, if I use MethodInvokingFactoryBean for this? Or we have a some better solution?

As a side note, I use ConfigContextLoaderListener to load the Application Context in web application. And want, that if bean 'A' is instantiated just call methodA() once.

How can this be done nicely?


Source: (StackOverflow)

Why is spawning threads in Java EE container discouraged?

One of the first things I've learned about Java EE development is that I shouldn't spawn my own threads inside a Java EE container. But when I come to think about it, I don't know the reason.

Can you clearly explain why it is discouraged?

I am sure most enterprise applications need some kind of asynchronous jobs like mail daemons, idle sessions, cleanup jobs etc.

So, if indeed one shouldn't spawn threads, what is the correct way to do it when needed?


Source: (StackOverflow)

What is the difference between Eclipse for Java (EE) Developers and Eclipse Classic?

What is the difference between Eclipse for Java (EE) Developers and Eclipse Classic?

Both are marked as version 3.6.

Which one should I use?


Source: (StackOverflow)

Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved

org.apache.maven.plugin.PluginResolutionException: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
    at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve(DefaultPluginDependenciesResolver.java:129)
    at org.eclipse.m2e.core.internal.project.registry.EclipsePluginDependenciesResolver.resolve(EclipsePluginDependenciesResolver.java:48)
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getPluginDescriptor(DefaultMavenPluginManager.java:142)
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getMojoDescriptor(DefaultMavenPluginManager.java:261)
    at org.apache.maven.plugin.DefaultBuildPluginManager.getMojoDescriptor(DefaultBuildPluginManager.java:185)
    at org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator.setupMojoExecution(DefaultLifecycleExecutionPlanCalculator.java:152)
    at org.eclipse.m2e.core.internal.embedder.MavenImpl.setupMojoExecution(MavenImpl.java:386)
    at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.setupMojoExecution(ProjectRegistryManager.java:865)
    at org.eclipse.m2e.core.internal.project.registry.MavenProjectFacade.getMojoExecution(MavenProjectFacade.java:355)
    at org.eclipse.m2e.core.project.configurator.AbstractCustomizableLifecycleMapping.getBuildParticipants(AbstractCustomizableLifecycleMapping.java:66)
    at org.eclipse.m2e.core.project.configurator.AbstractLifecycleMapping.configure(AbstractLifecycleMapping.java:87)
    at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.updateProjectConfiguration(ProjectConfigurationManager.java:414)
    at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.updateProjectConfiguration(ProjectConfigurationManager.java:351)
    at org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob.runInWorkspace(UpdateMavenProjectJob.java:74)
    at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:38)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: org.sonatype.aether.resolution.ArtifactDescriptorException: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:296)
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:186)
    at org.sonatype.aether.impl.internal.DefaultRepositorySystem.readArtifactDescriptor(DefaultRepositorySystem.java:279)
    at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve(DefaultPluginDependenciesResolver.java:115)

I have read where many people were able to solve this by:

I am new to Maven so please excuse any of my ignorance

This project is working on another machine, and just pulled it down from the repository on this one, with the same version of eclipse and m2e plugin installed. I have been fooling with this for over 10 hours now and it is driving me nuts (Maven has been nothing but headaches for me so far...) Any help is tremendously appreciated! Thanks in advance!

EDIT

After looking closer I did notice that it is not downloading the .jar files into the local repository... I am not sure if that is something obvious...

EDIT

I am not given the option to add Maven Dependencies to the build path.


Source: (StackOverflow)

How to upload files to server using JSP/Servlet?

How can I upload files to server using JSP/Servlet? I tried this:

<form action="upload" method="post">
    <input type="text" name="description" />
    <input type="file" name="file" />
    <input type="submit" />
</form>

However, I only get the file name, not the file content. When I add enctype="multipart/form-data" to the <form>, then request.getParameter() returns null.

During research I stumbled upon Apache Common FileUpload. I tried this:

FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = upload.parseRequest(request); // This line is where it died.

Unfortunately, the servlet threw an exception without a clear message and cause. Here is the stacktrace:

SEVERE: Servlet.service() for servlet UploadServlet threw exception
javax.servlet.ServletException: Servlet execution threw an exception
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:313)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:637)

Source: (StackOverflow)

What's the difference between JPA and Hibernate?

I understand that JPA 2 is a specification and Hibernate is a tool for ORM. Also, I understand that Hibernate has more features than JPA 2. But from a practical point of view, what really is the difference?

I have experience using iBatis and now I'm trying to learn either Hibernate or JPA2. I picked up Pro JPA2 book and it keeps referring to "JPA provider". For example:

If you think a feature should be standardized, you should speak up and request it from your JPA provider

This confuses me so I have a few questions:

  • Using JPA2 alone can I fetch data from DB by simply annotating my POJO's
  • Is JPA2 supposed to be used with a "JPA Provider" e.g TopLink or Hibernate? If so, then what's the benefit of using JPA2 + Hibernate as compared to Hibernate alone?
  • Can you recommend a good practical JPA2 book. "Pro JPA2" seems more like a bible and reference on JPA2 (It doesn't get into Queries until the later half of the book). Is there a book that takes a problem/solution approach to JPA2?

Source: (StackOverflow)

Maven dependency for Servlet 3.0 API?

How can I tell Maven 2 to load the Servlet 3.0 API?

I tried:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>3.0</version>
    <scope>provided</scope>
</dependency>

I use http://repository.jboss.com/maven2/ but what repository would be correct?

Addendum:

It works with a dependency for the entire Java EE 6 API and the following settings:

<repository>
    <id>java.net</id>
    <url>http://download.java.net/maven/2</url>
</repository>

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
</dependency>

I'd prefer to only add the Servlet API as dependency, but "Brabster" may be right that separate dependencies have been replaced by Java EE 6 Profiles. Is there a source that confirms this assumption?


Source: (StackOverflow)

How can a JACC provider use the Principal-to-role mapping facilities of the server it's deployed on?

I am writing a JACC provider.

Along the way, this means implementing a PolicyConfiguration.

The PolicyConfiguration is responsible for accepting configuration information from the application server, such as which permissions accrue to which roles. This is so that a Policy later on can make authorization decisions when handed information about the current user and what he's trying to do.

However, it is not part of the PolicyConfiguration's (atrocious) contract to maintain a mapping between roles and their permissions, and Principals that are assigned to those roles.

Typically--always, really--an application server houses this mapping. For example, on Glassfish, you affect this mapping by supplying things like sun-web.xml and sun-ejb-jar.xml and so on with your Java EE modules. (These vendor-specific files are responsible for saying, e.g., superusers is a group that is to be assigned the application role of admins.)

I would like to reuse the functionality these files supply, and I would like to do so for as wide an array of application servers as possible.

Here is--totally arbitrarily--IBM's take on the matter, which appears to confirm my suspicion that what I want to do is essentially impossible. (More ammunition for my case that this particular Java EE contract is not worth the paper it's printed on.)

My question: how do I get at this principal-to-role-mapping information in--for starters--Glassfish and JBoss from within a PolicyConfiguration? If there's a standard way to do it that I'm unaware of, I'm all ears.


Source: (StackOverflow)

What is Java EE? [duplicate]

This question already has an answer here:

I realize that literally it translates to Java Enterprise Edition. But what I'm asking is what does this really mean? When a company requires Java EE experience, what are they really asking for? Experience with EJBs? Experience with Java web apps?

I suspect that this means something different to different people and the definition is subjective.


Source: (StackOverflow)

Choosing a Java Web Framework now? [closed]

we are in the planning stage of migrating a large website which is built on a custom developed mvc framework to a java based web framework which provides built-in support for ajax, rich media content, mashup, templates based layout, validation, maximum html/java code separation. Grails looked like a good choice, however, we do not want to use a scripting language. We want to continue using java. Template based layout is a primary concern as we intend to use this web application with multiple web sites with similar functionality but radically different look and feel.

Is portal based solution a good fit to this problem?

Any insights on using "Spring Roo" or "Play" will be very helpful.

I did find similar posts like this, but it is more than a year old. Things have surely changed in the mean time!

EDIT 1: Thanks for the great answers! This site is turning to be the best single source for in-the-trenches programmer info. However, I was expecting more info on using a portal-cms duo. Jahia looks goods. Anything similar?


Source: (StackOverflow)