Programming task: Java Generics

Hi,
I am new to Java Generics.
Please suggest a programming task, which when implemented, let me study the features of Java Generics.
Thanks in advance.

Here are some same tasks
- Create a simple static method which returns its only parameter as the same type. Call it "runtime". (Can you suggest a use for it ;)
- Create a simple ArrayList with an add, size and get(int) method.
- Create a Comparator which wraps another Comparator which works in the opposite direction. i.e. it return -1 instead of 1 and visa-versa.

Similar Messages

  • Task programmed in java?

    hello friends!
    I want to my program in java try to create tasks programmed (of windows)
    I know a command : AT , in ms-dos , for creating task programming... my indecision is
    1) do a process executing the AT command (with parameters)
    Process p = Runtime.getRuntime().exec(cmd);2) I'm looking at google, any option, for do this programmed tasks from java , in easy form...
    Anybody knows a possible solution 2? Or .jar? I suposse i will must do the 1st option...

    If you do go with Runtime.getRuntime().exec(cmd), make sure you read the follow (if you have not already):
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How can I open a program using Java and then perform certain tasks with it?

    For example, and this is just an example, I want to write a Java program that opens MS Paint and then manipulates that program. This can be useful to automate certain tasks.
    My question is whether this can be done writing Java code and if so how? If not possible, would I need to use a scripting language instead?

    write a Java program that opens MS Paint and then
    manipulates that program. This can be useful to
    automate certain tasks."manipulates" is a too wide term. Let me narrow down:
    1. If you want to open (run) the program and then shut (kill) it down it is possible and fairly trivial to do in java. Look up Runtime and Process classes in java.lang package
    2. If you want to open the program and edit some image/document in the opened program. It is very difficult in java. May be possible... using some Java/COM bridge, assuming your native program is COM/Active-x compliant. Note: these things go beyond the boundary of JVM and needs to interact with host OS and involves shared memory, ipc and all "low level" stuffs.
    If you want to be able to play around with these COM/Activex apps- choose .NET instead :-)
    3) You can open the program from java and pass it some command line arg as in (1) above and then the program will load that document/image at startup automatically. You may then edit the doc/image thru that program itself. However, Java is not doing anything for you here, other than just starting off your native mspaint.exe ot notepad.exe.
    -BJ
    Message was edited by:
    Bimalesh

  • Is it possible to execute a program under a generic userid?

    Hi,
    I created a program that calls transaction SPAD and adds/deletes printers from SAP (via BDC calls).  We want the help desk to execute this new program when adding/deleting printers from SAP (instead of using SPAD). 
    Since we don't want to give the users access to transaction SPAD, would be possible to execute this new program under a generic ID that would have write-access in SPAD.
    Thanks in advance,
    Jen

    Might be possible via RFC. Try creating an RFC-enabled wrapper function module around your SPAD call, maintain an RFC connection to the same box with a technical user and password maintained, call the function in your program with addition STARTING NEW TASK (see ABAP help).
    Make sure the technical user has authorization only for SPAD and related as well as RFC calls to the function group where your function module resides.
    Thomas
    P.S. Marcin, authorization for tcode SPAD will not be enough, there is plenty of auth checks inside that transaction for the S_ADMI_FCD object.

  • I know how to program in java(Should I learn c, c++?)

    I know how to program in java. I want to be able to communicate with the hardware on my pc. I also hear that C, C++ is a lower level than java. Lower level meaning it can communicate with the hardware. I know java is very portable could do interfacing and could do so many things with the java programming language. I find the java programmig language cool. Now when I read about the JNI(java native interface) I think I could communicate with methods from java to functions in c++. I want to learn c++ and use it with JNI.
    Posting this topic because I want to be sure about what I'm doing.
    Thanks
    George

    in fact, memory management is the main pitfall in C++ programming. The following may give you a few headaches:
    - destructors
    - header files which try to include eachother
    - "memory access violation"
    - templates (upcoming java includes generics, which is similar)
    - pointers
    If you can overcome the above problems, you'll find that c++ is much like Java, only a bit more low-level. Accessing hardware directly however is quite a challenge (espescially under Windows which doesn't allow direct access for as far as I know), but not impossible. I don't know exactly, but I think it involves developing a small driver layer.
    It's to bad you learnt Java before C++, the other way around would have been much easier.

  • How to run and control any program by java

    hi everyone ,
    I wonder that how to execute and control some menus or how to use some property of any program by java, not for the whole program, it's just only a few features of program.
    Is there any idea?
    if it's impossible to do with java , how can I do it? which way?
    thanks a lot..

    No. Applications have to be specifically built to be able to be controlled by other programs; for example office applications allow you to communicate with them through a special protocol. To be able to communicate you need to know the protocol and write specific code for specific tasks.
    The software world is not as simple as they show in movies, where hackers just press two buttons and take control over entire buildings and applications.

  • Can someone help me understand this? (java generics wildcards)

    Hi all.
    First of all this is my first post on sun forums. Besides that i only used java for few weeks now and i think java is quit a nice language.
    I do have a question regarding java generics and wildcard casting (if you can call it that).
    Assume you have following code.
    public class Test <T extends Number> {
         private T x;
         Test(T x)
              this.x = x;
         T getX()
              return x;
         <U extends Number> void setX(U x)
              this.x = (T)x;
    public class Main {
         public static void main(String[] args) {
              Test<Integer> p = new Test <Integer>(5);
              System.out.println(p.getX());
              p.setX(53.32);
              System.out.println(p.getX());
    }This compiles with following results:
    5
    53.32
    Question:
    First: If I declared p to be of type Test<Integer> then why did x in Test class changed its type from Integer to Double?
    Second: Is this a possible unchecked casting behavior? and if so why does this work but doing something like this :
    Integer x = 5 ;
    Double y = 6.32;
    x=(Integer)y;fails with compile time error?

    Hello and welcome to the Sun Java forums.
    The behavior you describe would not occur if your setX(?) method used T instead of another type constraint.
    However, let's look at why it works!
    At line 1 in main, you create your Test with a type parameter of Integer; this becomes the type variable T for that particular instance of Test. The only constraint is that the type extends/implements Number, which Integer does.
    At line 2 you obtain a reference to a Number, which is what getX() is guaranteed to return. toString() is called on that object, etc.
    At line 3 you set the Number in the Test to a Double, which fits the type constraint U extends Number, as well as the type constraint T extends Number which is unused (!). Note that using a different type constraint for U, such as U extends Object or U super Number, could cause a compile-time error.
    At line 4 you obtain a reference to a Number, which is what getX() is guaranteed to return.
    The quirky behavior of setX is due to the second type constraint, which is obeyed separately; in this case, you probably want to use void setX(T x) {
    this.x = x;
    }edit: For the second part of your question, x = (Integer)y; fails because Integer and Double are distinct types; that is, Integer is not a subclass of Double and Double is not a subclass of Integer. This code would compile and work correctly: Number x = 5 ;
    Double y = 6.32;
    x=y;s
    Edited by: Looce on Nov 15, 2008 7:15 PM

  • When i click on the Firefox icon I get an error message, C:\Program Files\Java\jre6\lib\deploy\jqs\ff\..\..\..\..\bin\jqsnotify\.exe cannot be found. What is it? and how do i fix it? in English

    When i click on the icon to open Firefox an error message box appears with the following message, C:\Program Files\Java\jre6\lib\deploy\jqs\ff\..\..\..\..\bin\jqsnotify\.exe cannot be found. It then advises me to use the Search function, but the search function says it is unavailable.
    What is it? and how do I fix it? in English

    See:
    http://www.java.com/en/download/help/quickstarter.xml - What is Java Quick Starter (JQS)? What is the benefit of running JQS? - 6.0

  • How to execute external program in java?

    My question is how to execute an external program in java.
    I need to call a unix command in java.
    Thanks.

    it depends on what you are trying to do. Following are the two methods
    1. Runtime.exec() : this method allows you just to call an external program as a seperate process
    2. JNI (Native Interface) :- As of right now only C and C++ are supported by this method. This method allows you to directly call the C/C++ methods from JAVA

  • How Can I execute a java program using java code?

    {color:#000000}Hello,
    i am in great trouble someone please help me. i want to execute java program through java code i have compiled the java class using Compiler API now i want to execute this Class file through java code please help me, thanks in advance
    {color}

    Thanks Manko.
    i think my question was not clear enough.. actually i want to run this class using some java code . like any IDE would do i am making a text editor for java, as my term project i have been able to complie the code usign compiler api and it genertaes the class file but now i want to run this class file "THROUGH JAVA CODE" instead of using Java command. I want to achive it programatically. do you have any idea about it.. thanks in advance

  • How to create a  schedule program in java

    Hello Friends ,
    Can any one provide me with an example how to create a schedule program using java.util.timer etc . I am in need of a program which should run as a schedule job that searches for a file in a directory and read the latest files from that directory in every minute of time as a schedule job .
    Thanks
    mahesh

    I don't feel like writing my own example, but google will be happy to provide you with an example.

  • New "Windows Programming Using Java" Website

    Our newly created "Windows Programming Using Java" website (http://fivedots.coe.psu.ac.th/~ad/winJava/) is for programmers who want to extend Java's capabilities on Windows XP and/or Vista, but aren't sure where to start. One of the drawbacks of Java's portability is that many Java programmers have a rather sketchy knowledge of Windows-specific programming.
    We plan to explain how Java applications can utilize Windows application software, OS features, and hardware beyond the reach of Java's standard libraries. A variety of Java/Windows programming techniques will be explained, including:
    * Java's employment of the Win32 API via C, JNI, and J/Invoke.
    * Java's utilization of Window's Command Line Interface (CLI) and batch files, accessed through Java's Runtime, ProcessBuilder, and Process classes.
    * Java and Windows object-based scripting, centered around the use of VBScript, Windows Script Host (WSH), and Windows Management Instrumentation (WMI).
    * Java interoperability with COM, including hosting of ActiveX controls in Swing containers using jacoZoom.
    This website is a work in progress, with four chapters available for download at the moment. We'll be adding more regularly, and would love feedback on what we're doing.
    Thanks,
    Gayathri Singh and Andrew Davison
    [email protected] and [email protected]
    Edited by: AndrewDavison on Jun 20, 2008 1:36 AM

    Hi, I am looking the similar kind of requirement that you had done.. Do you have any more details on the code that is working for you . All i need is if the user logs in successfully in windows, the the app should be accessible. Please let me know if you have the code with you on this problem.
    Thanks in advance
    "what i meant is the we b applications running in my system, when i access the application iam able to to login automatically with windows authentication and now in case of other users following process happened:"

  • Asynchronous socket programming in Java?

    I am a C++ programmer, I just wonder how do I do asynchronous programming in Java?
    In VC++, you can hook an event handler to the socket and the system will fire an event whenever there is data coming in to the socket. The event handler can then spawn a thread and handle the network message.
    In Unix, you can use the select() function. This function will return whenever the indicated socket fires events. If nothing happens within the timeout period, the function simply returns.
    What about in Java? I don't see any methods that allows you to hook an event handler to it. Is there anything like select() function in Unix?
    Thanks so much.

    There is something very much like C's select: selectors. I don't immediately know where to read more about them but google for things like "java selector example", "java nio tutorial", etc (NIO = new I/O, the library where selectors live.)
    Another way to do async sockets in Java is by threading. That is the traditional way before New I/O. It's still a perfectly good and easy way, thanks to Java's easy threading. Downside is that it scales to only maybe 100-200 simultaneous connections per server (will depend on your operating system). For thread-based sockets check Sun's Java socket tutorial (first item when you google "java socket tutorial").

  • How Hard is it to program in Java.Swing

    Hi
    I wanted to program using java.swing component but i don't have any idea where i should start.
    I have been programming in java using java.Awt
    and i can do simple array programing.
    So how hard is it, and Where should i start learning java.swing. Ps I don't know anything about Swing, I don't even know what it is.
    Thanks you

    Hi
    As the previous guy said it is quite easy, and that link should teach you the basics. What I want to remind you of is that Swing uses up more memory when run. But it also have a few nicer extra goodies that make coding a little bit easier. Have fun with it.
    Here are a few more sites
    <http://manning.spindoczine.com/sbe/>
    <http://java.sun.com/docs/books/tutorial/uiswing/>
    Ciao

  • Can i create an exetutable (.exe) program with java???????

    I would like to learn how i can create an exetutable (.exe) program with java.
    Is there any additional package which i should download or buy it?
    Also i would like to write files into CD's direct from my application.
    Is there any library which i must download or buy?
    Thanks!

    check out the free open source GNU gcj native compiler for Java to see if it will do what you want.
    http://gcc.gnu.org/java/
    for writing data files you could use java.io.BufferedWriter. For sound files, look in the javax.sound package

Maybe you are looking for

  • SAP Business One 8.8 Developer License

    Hi, I am relatively new to SAP but has years of experience has a developer. I would like to develop competencies on SAP Business One 8.8 (or the latest version) to enable me deploy, consult and develop add ons for the platform. I would like to aquire

  • Premiere Elements 11 won't launch at all.

    I installed Premiere Elements 11 from a disk that also has Photoshop Elements. Photoshop Elements launches successfully. When I try to launch PE 11, either from the Start menu or the desktop icon, I get the round "swirl" for a moment, then it disappe

  • Designer repository question

    We currently have our designer repository at configuration 4.0.12.96.16. We were told that this version could be accessed by both Designer 6i and Designer 9i. The repository resides on an 8i database right now and we want to go to a 10g database. I'v

  • Refresh on logical database

    Hello Gurus, I need your help to solve one issue, please. I make a copy from RM07RESL report to one Z, this report get data with logical database. I need to create a button for user refresh data. I try to use the FM LDB_PROCESS, but return code 3, be

  • This is not unique to Firefox; Camino and Safari also have this problem. I cannot log into my student email online.

    I am using a 2005 model eMac computer with Airport Extreme card installed; when I try to log into the email site for the university, the computer does not prompt me for approval of their certificate. What is happening? This is not an issue with any o