I FOUND : servlet-api.jar ...WHERE insert it to can compile SERVLETS
I FOUND : servlet-api.jar in TOMCAT 6
WHERE insert it to can compile SERVLETS ?
where added(directory), some folders follow...?
C:\Program Files\Java\jdk1.6.0_15\bin
C:\Sun\AppServer\lib
C:\Program Files\Java\jdk1.6.0_15\src\javax
You can use any of the following methods:
i) SET CLASSPATH variable with absolute path of your servlet-api.jar and then compile your servlet from any folder.
ii)you can use
C:\jdk\bin>javac -cp C:\tomcat\lib\servlet-api.jar SampleServlet.javaand after comilation put the compiled java class file to classes folder of you web application.
[Obviously if you have any package, then you need to maintaing that folder structure inside classes folder]
Here I assumed your javac is available at C:\jdk\bin folder and servlet-api.jar is available at C:\tomcat\lib folder
---Sujoy
Similar Messages
-
I need to install servlet-api.jar in the libext folder.
Hi I am doing a tutorial on struts 2.0.11.
i need to install servlet-api.jar in the libext folder which I have created inside WEB-INF
Now I have downloaded servlet.api which is in the zip form.
When I extract the files. Its giving me two folders
1. javax
2. META-INF
Inside javax there is a folder called servlet. Inside servlet folder there are
a) bunch of call files
b) http folder
c) resources folder
Inside http folder there are
a) class files
b) properties files
Inside the resources folder there are
a) dtd files
b) xsd files
Inside the META-INF folder there is the manifest.mf file
I just need servlet-api.jar
I think that I have extracted the contents of servlet-api.jar by using the extract feature of winzip.
Do you think that by just changing the extension of the file from servlet-api.zip to servlet-api.jar it will do the trick or do i need to do something else.
Please guidepksingh79 wrote:
Hi ^^,
your replies were very helpful. I did try to check the lib folder of the webserver and there was not servlet-api.jar. However I downloaded a dummy project and it did have servlet-api.jar in it, so I am ok for now.
thanks and regards,
PrashantYou should not be doing that. Always use the one from the application server which you're going to use. Otherwise you will possibly get in runtime trouble due to version differences.
The actual location and filename of the servlet API might differ per application server implementation. If it was for example Tomcat 6, it is the servlet-api.jar in the /lib directory. If it was for example Glassfish (the current release), then it is the javaee.jar in the /lib directory. -
Once i set classpath to servlet-api.jar, it doesnt Instantiate DbBean.
I am using notepad editor. I am trying to instantiate a DbBean class inside the servlet's init() method.
once i set (C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar) this path to compile the Controller servlet.
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\WEB-INF\classes>set classpath=C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\WEB-INF\classes>javac Controller.java
Controller.java:5: package bean does not exist
import bean.DbBean;
^
Controller.java:14: cannot find symbol
symbol : class DbBean
location: class Controller
DbBean dbbean = new DbBean();
^
Controller.java:14: cannot find symbol
symbol : class DbBean
location: class Controller
DbBean dbbean = new DbBean();
^
3 errors
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\WEB-INF\classes>
this is my servlet
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import bean.DbBean;
public class Controller extends HttpServlet
public void init(ServletConfig config)throws ServletException
ServletContext context = config.getServletContext();
context.setAttribute("base_url",config.getInitParameter("base_url"));
{color:#ff0000}DbBean dbbean = new DbBean();{color} {color:#0000ff}error showing in this line
{color}dbbean.setDburl(config.getInitParameter("dburl"));
dbbean.setUserName(config.getInitParameter("username"));
dbbean.setPassward(config.getInitParameter("pwd"));
/// database bean can be access from jsp page
context.setAttribute("dbbean",dbbean);
/// Load the data base driver
try{
Class.forName(config.getInitParameter("jdbcDriver"));
catch(ClassNotFoundException e)
System.out.println(e.toString());
super.init(config);
public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
doPost(req,res);
public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
String base = "/onlinetest1/";
String url = base + "login.jsp";
String action = req.getParameter("action");
if(action!=null)
if(action.equals("successlogin.jsp"));
url = base + "successlogin.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(req,res);
public void destroy()
System.out.println("Servlet stopped");
This below class can be put inside bean folder( (ie)sub dir of controller servlet)
package bean;
import java.sql.*;
import java.util.*;
import java.io.*;
public class DbBean
String dburl="";
String dbuser="";
String dbpass="";
public void setDburl(String url)
dburl = url;
public void setUserName(String uname)
dbuser = uname;
public void setPassward(String pwd)
dbpass = pwd;
What to do to rectify this, please help me why this error coming,hi,
Actually i did my ordinary package compilation example below, its run correctly, but after set classpath to %tomcat-home%\common\lib\servlet-api.jar(for same programs its not working) this kinds of error coming.
F:\shyam\test>javac first.java
F:\shyam\test>java first
main class
DB Set Correctly
F:\shyam\test>set classpath=C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar
F:\shyam\test>javac first.java
first.java:1: package bean does not exist
import bean.DbBean;
^
first.java:10: cannot find symbol
symbol : class DbBean
location: class first
DbBean dbbean = new DbBean();
^
first.java:10: cannot find symbol
symbol : class DbBean
location: class first
DbBean dbbean = new DbBean();
^
3 errors
F:\shyam\test>
In compilation it wont take DbBean class, please help me.
thanks in advance,
S.Shyam -
hi
i'm trying to compile a simple servlet
my directory structure is as follows
c:\pr1
|
|____src
|
|______chservlet.java
|
|____classes
|
|____etc
|
|______web.xml
c:\Tomcat5.0
|
|____webapps
|
|______ch1
|
|____WEB-INF
|
|____classes
and the list of variables is as follows
TOMCAT_HOME=c:\Tomcat 5.0\bin
JAVA_HOME=c:\jsdk1.4
classpath = %CLASSPATH%;c:\Tomcat 5.0\common\lib\servlet-api.jar
now when i'm trying to compile the servlet by giving the following command
javac -classpath ".;c:\Tomcat5.0\common\lib\servlet-api.ajr" -d classes c:\pr1\src\chservlet.java
i'm getting the error package..
javax.servlet.* doesnt exist
can anybody help me at the earliest
Regards
jaismeensorry guys..for starting each time new thread..just registered myself to the site yesterday after facing this problem..so cudnt get familiar with its working..
i have given the commands as follows..
set classpath=c:\Tomcat5.0\common\lib\servlet-api.jar,%classpath%
set path=c:\jsdk1.4\bin;%path%
javac c:\pr1\src\chservlet.java
getting the following errors
C:\>javac c:\pr1\src\chservlet.java
c:\pr1\src\chservlet.java:1: package javax.servlet does not exist
import javax.servlet.*;
^
c:\pr1\src\chservlet.java:2: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
c:\pr1\src\chservlet.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class chservlet
public class chservlet extends HttpServlet
^
c:\pr1\src\chservlet.java:7: cannot resolve symbol
symbol : class HttpServletRequest
location: class chservlet
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOExcep
tion
^
c:\pr1\src\chservlet.java:7: cannot resolve symbol
symbol : class HttpServletResponse
location: class chservlet
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOExcep
tion
^
5 errors
was just wondering.ihave windows xp..so does it effect in anyway(it shud not)
and if name of the servlet is given wrong then it shudnt give these set of errors..it shud give kind a"cudnt find the file name"
and i have checked the classpath..servlet-api.jar is present and is in this location
c:\Tomcat 5.0\common\lib
and i had tried giving the command
jar -tvf servlet-api.jar..
it gives the list of classes..which shows..its present in the directory
jdk is present in c:\jsdk1.4
location of servlet is c:\pr1\src\chservlet.java
servlet code is as follows
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class chservlet extends HttpServlet
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException
PrintWriter out =res.getWriter();
java.util.Date today= new java.util.Date();
out.println("<html>"+
"<body>"+
"<h1 align=center>HF\'s Chapter1 Servlet<h1>"
+"<br>"+today+"</body>"+"</html>");
even i tried copynig servlet-api.jar in the same directory as the servlet and compiling it..
it gives the same set of errors
am just wondering what cud be the problem.sure..must b very smal..but i m not progressing much
regards -
Hi
iam new to use jstl.i wrote on tag handler (java) class when i am compiling it is not identifying any of javax.jspexception ,java.jsp.tagext.
please help me what are all the jar files i have to have in class path or at any place and from where can i download them. i searched for servlet-jsp.jar,servlet-api.jar but i could not find anywhere in java.sun.com.any help is greatly appreciated
thankshi thanks for the reply. iam using tomcat 5.0
server. from where can i down load those jar files
please let me know
what jar files are needed if iam using tomcat 5.0 Like I said, Tomcat 5 uses Tomcat 5: servlet-api.jar jsp-api.jar. They will be in the server's classpath someplace. Look around were you installed TC. I am away from my machine at the moment so I can't say for sure, but it might be common/lib or shared/lib, something like that...
and
if weblogic 8.0Dunno. Look around the file structure.
Thanks for the help -
Compiling servet.error wrong version of servet-api.jar
hi,
I try to compile the following servlet
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletTemplate extends HttpServlet
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
PrintWriter out=response.getWriter();
But I got the follwing error.
D:\apache-tomcat-6.0.14\webapps\Raju\WEB-INF\classes>javac SevletTemplate.java
SevletTemplate.java:5: class ServletTemplate is public, should be declared in a
file named ServletTemplate.java
public class ServletTemplate extends HttpServlet
^
SevletTemplate.java:5: cannot access javax.servlet.http.HttpServlet
bad class file: D:\apache-tomcat-6.0.14\lib\servlet-api.jar(javax/servlet/http/H
ttpServlet.class)
class file has wrong version 49.0, should be 48.0
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
public class ServletTemplate extends HttpServlet
^
2 errors
I have set CLASSPATH with servelt-api.jar.
Please help merajuchinu wrote:
class file has wrong version 49.0, should be 48.0You have compiled it with a newer javac version than the JRE version with which you're running it.
Check java -version and javac -version and align them both out to the same version. -
Strict servlet API: cannot call getOutputStream() after getWriter()
i have an applet which will communicate with a servet , but got following error in the servlet
java.lang.IllegalStateException: strict servlet API: cannot call getOutputStream() after getWriter()
at weblogic.servlet.internal.ServletResponseImpl.getOutputStream(ServletResponseImpl.java:280)
at oracle.osl.lt.web.servlets.AudioServlet._processGetPlayList(AudioServlet.java:235)
at oracle.osl.lt.web.servlets.AudioServlet.doPost(AudioServlet.java:91)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.wls.filter.SSOSessionSynchronizationFilter.doFilter(SSOSessionSynchronizationFilter.java:276)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)
at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
SUBSYSTEM = HTTP USERID = <WLS Kernel> SEVERITY = Error THREAD = [ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)' MSGID = BEA-101020 MACHINE = p1dvosl02 TXID = CONTEXTID = TIMESTAMP = 1318836952580
WatchAlarmType: AutomaticReset
WatchAlarmResetPeriod: 30000
>
*below _processGetPlayList() is called by doPost() of the servlet.*
seems the exception is thrown due to response.getOutputStream()?
any idea? thanks!!
private void _processGetPlayList(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
try {
ObjectOutputStream objectOut =
new ObjectOutputStream(new BufferedOutputStream(response.getOutputStream()));
try {
RichDataDTOExt richData = _getRichData(request);
if (richData == null) {
Log.web().debug(s7);
throw new ServletException(s7);
objectOut.writeObject(richData.getAudioRecordings().getAll(new ContentRefDTO[0]));
finally {
objectOut.close();
catch (IOException e) {
Log.web().error(e.getMessage());
throw new ServletException();
}thanks for you reply. but seems we don't call getWriter() at all in our code.
actually this error only happen in our customer's env, no this issue in our development env.
besides using getOutputStream() and getWriter() simultaneously for same response, is this maybe related with some web server configuration? -
Strict servlet API: cannot call getWriter() after getOutputStream()
Hi,
Am getting below exception when i click on create report button.
It was successfully running in development machine, when we deploy the same application into the testing server.
what could be problem..
am using JSF 2.0, Primefaces 3.5, Jdeveloper and Weblogic 12 C server..
java.lang.IllegalStateException: strict servlet API: cannot call getWriter() after getOutputStream()
at weblogic.servlet.internal.ServletResponseImpl.getWriter(ServletResponseImpl.java:299)
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:362)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:155)Issue resolved, because testing machine doesn't have specified font in font directory.
recompiled the jrxml file with arial font its working both the env machine.. -
Weblogic 6.1 and Servlet API 2.3
Dears All,
could you confirm weblogic v6.1 can support J2EE v1.3 and especially Servlet API v2.3 ?
Our war deployment is fine (v2.3 seems supported) but queries about major/minor versions in Web application Context return v2.2.
Are some upgrade or deployments specifications required ?
Thanks,
BrunoAFAIK 2.2.
Peace,
Cameron Purdy
Tangosol, Inc.
http://www.tangosol.com
+1.617.623.5782
WebLogic Consulting Available
"Tajdar Siddiqui" <[email protected]> wrote in message
news:3b043919$[email protected]..
>
> I read somewhere that Weblogic 6.0 supports Servlet Api 2.3 ( which in
turn support
> http Filters etc.).
>
> I searched the Weblogic docs site for 6.0 and there is no mention of
Servlet Api
> 2.3 over there. Can someone pls. validate this.
>
> Thanx,
> Tajdar
-
Weblogic 6.0 and Servlet Api
I read somewhere that Weblogic 6.0 supports Servlet Api 2.3 ( which in turn support
http Filters etc.).
I searched the Weblogic docs site for 6.0 and there is no mention of Servlet Api
2.3 over there. Can someone pls. validate this.
Thanx,
Tajdar
AFAIK 2.2.
Peace,
Cameron Purdy
Tangosol, Inc.
http://www.tangosol.com
+1.617.623.5782
WebLogic Consulting Available
"Tajdar Siddiqui" <[email protected]> wrote in message
news:3b043919$[email protected]..
>
> I read somewhere that Weblogic 6.0 supports Servlet Api 2.3 ( which in
turn support
> http Filters etc.).
>
> I searched the Weblogic docs site for 6.0 and there is no mention of
Servlet Api
> 2.3 over there. Can someone pls. validate this.
>
> Thanx,
> Tajdar
-
Problem in compiling servlet class - using Tomcat
Hi,
I have a servlet pgm that I'm trying to compile.I using Tomcat application server.I have my servlet class in D:\servlet_wrk\project1\src
and my deployment descriptor in D:\servlet_wrk\project1\etc
my CLASSPATH var is set to C:\Sun\AppServer\jdk\bin
and
my PATH var is set to C:\Sun\AppServer\bin.
When I compile my servlet class Ch1Servlet.java in the command line from the directory
D:\servlet_wrk\project1 using the command
javac -classpath D:\applications\tomcat-5.5.12\common\lib\servlet-api.jar -d classes src/Ch1Servlet.java,
it says error:cannot read: src/Ch1Servlet.java
Can somebody help me to solve this problem and help me to compile my servlet class.
Thanks.Thanks...as u said I tried putting dir & found that
my file was saved as Ch1Servlet.java.txt instead for
Ch1Servlet.java......So that was a problem.Now I'm
able to compile.Oh, yeah. Notepad will do that to you. I think when you save in Notepad if you put quotes around the name "Whatever.java" then it won't add the .txt.
But on compiling I'm getting the following error
package java.servlet.* does not exist
package java.servlet.http.* does not exist
package java.io.* does not exist
Do u the reason for this??? The servlet stuff is java[b]x.servlet. For the io stuff, I don't know, I'd have to see your code. Either you have a typo or a corrupt installation. -
Not able to compile servlet pgm - using Tomcat
Hi,
I have a servlet pgm that I'm trying to compile.I using Tomcat application server.I have my servlet class in D:\servlet_wrk\project1\src
and my deployment descriptor in D:\servlet_wrk\project1\etc
my CLASSPATH var is set to C:\Sun\AppServer\jdk\bin
and
my PATH var is set to C:\Sun\AppServer\bin.
When I compile my servlet class Ch1Servlet.java in the command line from the directory
D:\servlet_wrk\project1 using the command
javac -classpath D:\applications\tomcat-5.5.12\common\lib\servlet-api.jar -d classes src/Ch1Servlet.java,
it says error:cannot read: src/Ch1Servlet.java
Can somebody help me to solve this problem and help me to compile my servlet class.
Thanks.**MAJOR SPAMMING SCUM BAG ALERT**
I was puzzled in that you asked a SQL Server question in one post and then in another thread asked a Oracle related question... and then I noticed you had cross posted one of your questions at JavaRanch and I was more annoyed....
and then I found this....
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=10&t=002447
You sir -> Michael Byrd -> are a scum sucking dirtbag.
To quickly explain. Mr. Byrd posts his messages (which he copies wholesale from other posters) so that he can get better google caching for the website listed in his profile.
This is such scummy behaviour I don't even know what to say. Other than basically everyone that has ever helped you had totally wasted their time.
You are scum. Your company is scum. I hope you rot in hell. -
Hi,
Now i create my first servlet, I want to compile and run it.
I downloaded J2EE SDK but I don't know where is the jar file which contain servlet classes.
thanks,
ShimaaMy friend , From your post it seems you have kickstarted your career in JSP and Servlet Technology. Compiling a Servlet is as simple as mud if you are using Tomcat [Best Server for Beginners in this field]
For Tomcat :
If you downloaded the tomcat server from Apache website and if you extracted to your c:\ , then following things have to setted up in the environmental variables of your machine (Right click Mycomputer ->Advanced->Environmental Variables)
1: CATALINA_HOME : C:\jakarta-tomcat-5.0.16
2:CLASSPATH : C:\jakarta-tomcat-5.0.16\common\lib\servlet-api.jar;C:\jakarta-tomcat-5.0.16\common\lib\jsp-api.jar
3:JAVA_HOME : C:\j2sdk1.4.0
4:path : c:\j2sdk1.4.0\bin;C:\jakarta-tomcat-5.0.16\bin..
Hope this helps... -
Help: Compiling servlets
Hi,
I have created a servlet java file.
and when i compile the servlet java file, I am getting error,
HelloWorld.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
HelloWorld.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
HelloWorld.java:5: cannot find symbol
symbol: class HttpServlet
public class HelloWorld extends HttpServlet {
^
HelloWorld.java:7: cannot find symbol
symbol : class HttpServletRequest
location: class HelloWorld
public void doGet(HttpServletRequest req, HttpServletResponse res)
^
HelloWorld.java:7: cannot find symbol
symbol : class HttpServletResponse
location: class HelloWorld
public void doGet(HttpServletRequest req, HttpServletResponse res)
^
HelloWorld.java:8: cannot find symbol
symbol : class ServletException
location: class HelloWorld
throws ServletException, IOException {
^
6 errors
where can i get the missing javax classes?
Thanks and Regards,
Rashmy.Hi Sreekanth,
Yes, I am using Tomcat server.
I have java SDK 6 and J2EE 5.
I am setting up the path to jdk6 and compiling it.
is this the correct way?
and i tried settingup calss path to the servlet-api.jar. but getting the same error.
Thanks,
Rashmy. -
Can't get Eclipse 3.3 to compile servlets
Hi,
This is my first time tyring to compile a servlet in Eclipse 3.3. I have serveral errors like "Can not resolve import javax.servlet..." I did include the location of the servlet-api.jar file in my classpath. And not just classpath but I included the location to variables PATH, JAVA_HOME just in case but still no luck. I have browsed the web enough, and tried all the tricks of the trade. I am using jdk1.6_02 and tomcat 5.5.25.
Can anybody help,
Thanks in advance!
Codesingh!Okay, let's start simple: An instance of Comparable<T> can be compared to instances of T (for any type T). Lets assume Numbers were Comparable:
class Number implements Comparable<Number> { /* ... */ }
class Integer extends Number { /* ... */ }
class Float extends Number { /* ... */ }This means an Integer can be compared to any Number, such as a Float or another Integer:
Integer ten = 10;
Integer five = 5;
ten.compareTo(five);Now let's write a generic function that can sort lists of items that are comparable with each other:
public static <T extends Comparable<T>> void sort(List<T> list) { /* ... */ }If you tried to pass a List<Integer> to sort, you would essentially substitute Integer for T, however Integer does not satisfy the upper bound of Comparable<Integer>. If we substitute Integer in the declaration you provided in reply 2
public static <T extends Comparable<? super T>> void sort(List<T> list) { /* ... */ }we get an upper bound of Comparable<? super Integer>. You're free to substitute "? super Integer" with a supertype[1] of Integer, such as Number and since Integer implements Comparable<Number> the substitution is valid and the call is legal.
Generics are all about substituting.. ;)
To answer the question of what does T extends Comparable<? super T> mean: It means you may substitute any type U for T where U is comparable to a supertype[1] of U.
With kind regards
Ben
[1] the super- and subtype relations are reflexive, in other words Integer is a supertype and a subtype of Integer.
Maybe you are looking for
-
I hit delete on a download which was still downloading when I meant to hit pause and now I can't find it in purchases to continue downloading it and its not in my recycle bin. What can i do?
-
OnSort event in ABAP WebDynpro
Dear All, Can you please help me on as how and where to program the onSort event? In my application I am fetching bukrs, butxt, ort01 and spras. I want to have an ascending sort on any of these fields. Please help. Regards, Prosenjit.
-
Copying iDVD back to computer from DVD
I recently burned iDVD to a DVD because I had hardly any space on my hard drive. Now i've put a new hard drive in my ibook and I'm ready to copy iDVD back to my computer. The problem I am having is that when I try to copy it back, it comes up with an
-
Last GR Date & Last GI Date of stock in inventory
Hi Gurus, How can I get last GR date & last GI date from stock in Inventory if i don't have information on batch ? Is there any standard report in SAP which provide that information ? Please kindly give advice on this. Regards, Gunawan
-
Hello, Can you tell if there is a standard Pickling list output type for a Sales Order Outbound delivery for a WM activated plant.(EK00 is no longer in application V2) How can a Transfer Order creation trigger this Picking List (output type?) Please