Return Type of Applet's getParameter() method

Hello
I am having win7 machine with a jre 6 update 24 on it .
I tried to execute method getParameter("DOCBASE") on Ie8(32bit) as well on IE8(64) bit.
I am amazed to see DIFFERENT return value (NULL for 32 bit and Empty String for 64 bit)for both configuration.
This happens only for DOCBASE parameter if i name XDOCBASE then everything is fine.
Can anyone help me to understand why this different behaviour?

JoachimSauer wrote:
A somewhat stricter approach is the following (also called self typing):
public interface AnInterface<T extends AnInterface<T>> { /* ... */ }
I knew that there was another trick hidden behind my suggestion, but I couldn't remember which one.
That's what Comparable does, isn't it?You'd think that it does, but when I bring it up in eclipse it looks like this (comments removed):
public interface Comparable<T> {
    public int compareTo(T o);
java.lang.Enum does do it though.
With kind regards
Ben

Similar Messages

  • How to create a webservice with return type File

    Hi All,
    I have a class Letter and I am trying to expose viewReport as webservice.
    In Jdeveloper -> Business teir -> webservices -> Java web service and I have selected my method i.e. viewReport
    Now it throws error "The return type java.io.File of method viewReport can not be serialized into XML"
    I unserstood the issue but How can I achive this in JDeveloper
    public class Letter {
    public Letter() {
    super();
    public File viewReport(String name) {
    File folder = new File("C:\\APPS\\root\\pdf\\10052011");
    File[] listOfFiles = folder.listFiles();
    return listOfFiles[0];
    }

    You can't as File is nor serializable. It won't make sense as you would try to give a handle to a file on the server hosting the service to a remote system.
    Can you explain the use case in more detail?
    Timo

  • Getting an Annotation for a Return Type (Java 1.5 Beta)

    Hi
    I am trying to access the annoation information on a class using reflection. I can't find any way to get access to an annotation on the return type of a method. For example the code below complies however there is no method on the "java.lang.reflect.Method" class (that I can see) that gives me access to the annoation.
    Could someone point me to something I may have misses.
    example:
    import java.lang.annotation.*;
    @Retention(value=RetentionPolicy.RUNTIME)
    @Target(value=ElementType.ANNOTATION_TYPE)
    public @interface MyAnnotation {
    String value();
    public class TestClass {
    public static @MyAnnotation("hello")void myMethod() {
    Thank
    Raymond McCrae

    The annotation isn't on the return type, it is on the method.
    You want the method
        public <T extends Annotation> T getAnnotation(Class<T> annotationClass);It is used like this
      MyAnnotation m = TestClass.getMethod("myMethod").getAnnotation(MyAnnotation.class);Note that it is typesafe!

  • Why Constructor has not return type ?

    Please tell me why constructor has not return type ?

    Constructor is a method which basically called for creating instances of an object. 
    It should return an instance of the class whose constructor we are calling.
    So basically the return type is implicit.
    If the syntax allows to specify return type, users may put some other return types other than the containing class type, which is not relevant.
    Muthukrishnan Ramasamy
    net4.rmkrishnan.net
    Use only what you need, Reduce global warming

  • About return type and parameter type in IDL

    I don't know how to define return type and parameter type in
    operations in a module which are not listed in predefined in
    IDL. can I define these types as java class?
    can someone help me where a tutorial about this in detail can
    be found?
    thanks a lot

    My understanding is that if something is not in the IDL definition, then as far as the CORBA system is concerned it doesn't exist.
    Therefore any methods you create in a class that implements an IDL defined interface, that are outside that interface, are completely free and outside the CORBA system.
    The parameters and return types of these 'local native' methods should be java classes. All methods and variables outside the IDL spec will only be visible to the local JVM.
    ciao
    Jim
    PS - there is a zip file containing a very long and fairly messy demo of this behaviour at http://clio.mit.csu.edu.au/subjects/itc327/Asg2Demo.zip
    it has an html file which describes using additional non-IDL 'local native' methods for implementing a save/load function

  • Two methods with same name but different return type?

    Can I have two methods with same name but different return type in Java? I used to do this in C++ (method overloading or function overloading)
    Here is my code:
    import java.io.*;
    public class Test{
    public static void main(String ar[]){
    try{          
    //I give an invalid file name to throw IO error.
    File file = new File("c:/invalid file name becasue of spaces");
    FileWriter writer = new FileWriter(file ,true);
    writer.write("Test");
    writer.close();     
    } catch (IOException IOe){
         System.out.println("Failure");
    //call first method - displays stack trace on screen
         showerr(NPe);
    //call second method - returns stack trace as string
            String msg = showerr(NPe);
            System.out.println(msg);
    } // end of main
    public static void showerr(Exception e){
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         e.printStackTrace(pw);
         try{
         pw.close();
         sw.close();
         catch (IOException IOe){
         IOe.printStackTrace();     
         String stackTrace = sw.toString();
         System.out.println("Null Ptr\n" +  stackTrace );
    }//end of first showerr
    public static String showerr(Exception e){
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         e.printStackTrace(pw);
         try{
         pw.close();
         sw.close();
         catch (IOException IOe){
         IOe.printStackTrace();     
         return sw.toString();
    }//end of second showerr
    } // end of class
    [\code]

    Overloading is when you have multiple methods that have the same name and the same return type but take different parameters. See example
    public class Overloader {
         public String buildError(Exception e){
              java.util.Date now = new java.util.Date() ;
              java.text.DateFormat format = java.text.DateFormat.getInstance() ;
              StringBuffer buffer = new StringBuffer() ;
              buffer.append(format.format(now))
                   .append( " : " )
                   .append( e.getClass().getName() )
                   .append( " : " )
                   .append( e.getMessage() ) ;
              return buffer.toString() ;
         public String buildError(String msg){
              java.util.Date now = new java.util.Date() ;
              java.text.DateFormat format = java.text.DateFormat.getInstance() ;
              StringBuffer buffer = new StringBuffer() ;
              buffer.append(format.format(now))
                   .append( " : " )
                   .append( msg ) ;
              return buffer.toString() ;
         public String buildErrors(int errCount){
              java.util.Date now = new java.util.Date() ;
              java.text.DateFormat format = java.text.DateFormat.getInstance() ;
              StringBuffer buffer = new StringBuffer() ;
              buffer.append(format.format(now))
                   .append( " : " )
                   .append( "There have been " )
                   .append( errCount )
                   .append( " errors encountered.")  ;
              return buffer.toString() ;
    }Make sense ???
    Regards,

  • The class of the deferred-methods return type "{0}" can not be found.

    I am developing a multilingual portal application.
    I have the method that changes the locale based on user's choice in the bean and the method is being referred to as below.
    <af:selectOneChoice label="Select Language" autoSubmit="true"
    value="#{localeBean.locale}"
    valueChangeListener="localeBean.changeLocale">
    <af:selectItem label="English" value="en" id="si1"/>
    <af:selectItem label="French" value="fr" id="si2"/>
    <af:selectItem label="Dutch" value="nl" id="si3"/>
    </af:selectOneChoice>
    when i try to run the application, i am getting compile time errors as below,
    The class of the deferred-methods return type "{0}" can not be found.
    No property editor found for the bean "javax.el.MethodExpression".
    After going through the discussion forums i learned that the compilation errors can be resolved by setting the <jsp:directive.page deferredSyntaxAllowedAsLiteral="false> at the starting of the page.
    Even after that i am getting the compilation error.
    Any solutions, suggestions or possible approaches would be helpful as i am new to Webcenter Portal development.
    Thanks,

    The error you get points to a problem on the page (somewhere). Switch to source mode and check the right margin if you see orange or red marks. These are pointing to problems (not all are show stoppers, but they give you hints that something is not according to the standard for jsf, jsff, jsp or jspx pages.
    Have you checked that the bean is correctly defined and that it's reachable?
    Start a fresh page and isolate the problem, e.g. build a selectOneChoiuce on the new page (don't copy it as you might copy the error too) and make it work on the new page. Once you have it running you can compare the solution to your not running page.
    Timo

  • Is there a way to end a method that has no return type?

    Without using an exception, as they are costly I am told, and without using may if then statements, is it possible to end a method if some criteria isn't met.
    example.
    public void doThis(){
      // the method relies on the state of some
      // other things.
      if(!someBoolean) endHere
      // then following is the rest of the method.
      // I'd like to be able to do this so that the "meat"
      // of the method is located under the conditions
      // that must be met.
    }... Any thoughts?
    Thank You

    No need to hide or commit ritual suicide, the "void" keyword could lead you to think that your method can't use the return statement. At least you wrote code to investigate and didn't spend 10 or 20 posts asking for verification. Be aware, some folk will tell you that there should be only one exit point from the method, often this is true. In large methods you can get lost in the execution path if there are multiple exit points. I think it's a judgement call.
    As for returning a bogus boolean, but, from a design point of view, if your method really doesn't have anything to return to its caller then the signature should reflect that with a return type of void (I know you are suggesting returning the bogus boolean for a different reason, and you've abandoned the idea anyway, I'm just being pedantic here)(indulge me). Returning a bogus boolean makes the class method more difficult to understand from a design and JavaDoc point of view because I, as the user of your method, will see it returing a boolean and expect to be able to use that value, and it might color my view of what the method does.
    Lee

  • Invalid method declaration; return type required

    The code:
              public Reminder(int seconds) {
            timer = new Timer();
            timer.schedule(new RemindTask(), seconds*1000);
        class RemindTask extends TimerTask {
            public void run() {
                System.out.format("Time's up!%n");
                timer.cancel(); //Terminate the timer thread
    public static void main(String[] args)
              JFrame.setDefaultLookAndFeelDecorated(true);
              JDialog.setDefaultLookAndFeelDecorated(true);
              try
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              catch (Exception ex)
                   System.out.println("Failed loading L&F: ");
                   System.out.println(ex);
           new superball();
                    new Reminder(5);
            System.out.format("Task scheduled.%n");
    //= End of Testing =
        }Gives:
    "invalid method declaration; return type required"
    If i add void to public Reminder(int seconds) {It prints:
    cannot find symbol
    symbol : class Reminder
    location: class superball
    new Reminder(5);
    Is it because of the public class?
    public class superball extends JFrameHere is the FULL code:
    /*                      superball                                 */
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.regex.Pattern;
    import java.util.Timer;
    import java.util.TimerTask;
    import java.util.*;
    import java.io.*;
    * Summary description for superball
    public class superball extends JFrame
         // Variables declaration
         int ballx;
      int bally;
         int jumpstop;
         int stopper;
         int coin;
         int coinx;
         int coiny;
         int coinvaluex;
         int coinvaluey;
      Timer timer;
      private int value = 0;
         private static Random r = new Random();
         private JLabel jLabel1;
         private JLabel jLabel2;
         private JLabel jLabel4;
         private JLabel jLabel5;
         private JLabel jLabel7;
         private JLabel jLabel9;
         private JLabel jLabel10;
         private JPanel contentPane;
         private JPanel jPanel1;
         // End of variables declaration
         public superball()
              super();
              initializeComponent();
              // TODO: Add any constructor code after initializeComponent call
              this.setVisible(true);
          * This method is called from within the constructor to initialize the form.
          * WARNING: Do NOT modify this code. The content of this method is always regenerated
          * by the Windows Form Designer. Otherwise, retrieving design might not work properly.
          * Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
          * to retrieve your design properly in future, before revising this method.
         private void initializeComponent()
              jLabel1 = new JLabel();
              jLabel2 = new JLabel();
              jLabel4 = new JLabel();
              jLabel5 = new JLabel();
              jLabel7 = new JLabel();
              jLabel9 = new JLabel();
              jLabel10 = new JLabel();
              coin = 1;
              coinx = Math.abs(r.nextInt()) % 460 + 100;
              coiny = Math.abs(r.nextInt()) % 200 + 100;
              ballx = 342;
              bally = 338;
              jumpstop = 0;
              stopper = 13;
              contentPane = (JPanel)this.getContentPane();
              jPanel1 = new JPanel();
              // jLabel1
              jLabel1.setIcon(new ImageIcon("IMG\\coin.gif"));
              jLabel1.setText("0");
              // jLabel2
              jLabel2.setIcon(new ImageIcon("IMG\\logo.PNG"));
              // jLabel4
              jLabel4.setIcon(new ImageIcon("IMG\\black.GIF"));
              // jLabel5
              jLabel5.setIcon(new ImageIcon("IMG\\ballstanding2.gif"));
              // jLabel7
              jLabel7.setIcon(new ImageIcon("IMG\\star-heart.gif"));
              jLabel7.setText(" 100");
              // jLabel9
              jLabel9.setIcon(new ImageIcon("IMG\\coin.gif"));
              // jLabel10
              jLabel10.setIcon(new ImageIcon("IMG\\stage1.GIF"));
              // contentPane
              contentPane.setLayout(null);
              contentPane.setBackground(new Color(255, 254, 254));
              addComponent(contentPane, jLabel5, 342,338,60,18);
              addComponent(contentPane, jLabel1, 561,4,100,18);
              addComponent(contentPane, jLabel2, 2,3,208,24);
              addComponent(contentPane, jLabel7, 495,4,60,18);
              addComponent(contentPane, jLabel9, coinx,coiny,19,18);
              addComponent(contentPane, jLabel2, 2,3,208,24);
              addComponent(contentPane, jLabel10, -2,29,738,412);
              addComponent(contentPane, jPanel1, 79,209,200,100);
              // jPanel1
              jPanel1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
              jPanel1.setFocusable(true);
              jPanel1.addKeyListener(new KeyAdapter() {
                   public void keyPressed(KeyEvent e)
                        jPanel1_keyPressed(e);
                   public void keyReleased(KeyEvent e)
                        jPanel1_keyReleased(e);
                   public void keyTyped(KeyEvent e)
                        jPanel1_keyTyped(e);
              // superball
              this.setTitle("Superball created by Hannes Karlsson");
              this.setLocation(new Point(0, 0));
              this.setSize(new Dimension(617, 450));
              this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              this.setResizable(false);
         /** Add Component Without a Layout Manager (Absolute Positioning) */
         private void addComponent(Container container,Component c,int x,int y,int width,int height)
              c.setBounds(x,y,width,height);
              container.add(c);
         // TODO: Add any appropriate code in the following Event Handling Methods
         private void jPanel1_keyPressed(KeyEvent e)
              System.out.println("\njPanel1_keyPressed(KeyEvent e) called.");
              // TODO: Add any handling code here
              if(e.getKeyCode()==e.VK_LEFT) // when the user enters left
                  jLabel5.setLocation(new Point(ballx--, bally));
                        jLabel5.setLocation(new Point(ballx--, bally));
                        jLabel5.setLocation(new Point(ballx--, bally));
                        jLabel5.setLocation(new Point(ballx--, bally));
                        jLabel5.setIcon(new ImageIcon("IMG\\ballroll.gif"));
                        } // equalling PLAIN_SPEED
                                            if(e.getKeyCode()==e.VK_RIGHT) // when the user enters right
                  jLabel5.setLocation(new Point(ballx++, bally));
                        jLabel5.setLocation(new Point(ballx++, bally));
                        jLabel5.setLocation(new Point(ballx++, bally));
                        jLabel5.setLocation(new Point(ballx++, bally));
                        jLabel5.setIcon(new ImageIcon("IMG\\ballroll.gif"));
                        } // equalling PLAIN_SPEED
                                                                if(e.getKeyCode()==e.VK_UP) // when the user enters up
                  jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setIcon(new ImageIcon("IMG\\balljetpack.gif"));
                        } // equalling PLAIN_SPEED
                                                                                    if(e.getKeyCode()==e.VK_DOWN) // when the user enters up
                  jLabel5.setLocation(new Point(ballx, bally++));
                        jLabel5.setLocation(new Point(ballx, bally++));
                        jLabel5.setLocation(new Point(ballx, bally++));
                        jLabel5.setLocation(new Point(ballx, bally++));
                        jLabel5.setIcon(new ImageIcon("IMG\\ballroll.gif"));
                        } // equalling PLAIN_SPEED     
                        if(bally>=340)
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                                  System.out.println("LOW!!!");
                        if(bally<=-2)
                        jLabel5.setLocation(new Point(ballx, bally++));
                        jLabel5.setLocation(new Point(ballx, bally++));
                        jLabel5.setLocation(new Point(ballx, bally++));
                        jLabel5.setLocation(new Point(ballx, bally++));
                                  System.out.println("HIGH!!!");
                                            if(ballx>=594)
                        jLabel5.setLocation(new Point(ballx--, bally));
                        jLabel5.setLocation(new Point(ballx--, bally));
                        jLabel5.setLocation(new Point(ballx--, bally));
                        jLabel5.setLocation(new Point(ballx--, bally));
                                  System.out.println("RIGHT!!!");
                                                                if(ballx<=-3)
                        jLabel5.setLocation(new Point(ballx++, bally));
                        jLabel5.setLocation(new Point(ballx++, bally));
                        jLabel5.setLocation(new Point(ballx++, bally));
                        jLabel5.setLocation(new Point(ballx++, bally));
                                  System.out.println("LEFT!!!");
                                                                           if (bally==294 && (ballx > 218 && ballx < 274))
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                                                                           if (bally==262 && (ballx > 246 && ballx < 306))
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                                                       if (bally==230 && (ballx > 486 && ballx < 562))
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                                        if (bally==310 && (ballx > 486 && ballx < 594))
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                         if (bally==262 && (ballx > 442 && ballx < 514))
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
          if (bally==294 && (ballx > 378 && ballx < 466))
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                        jLabel5.setLocation(new Point(ballx, bally--));
                   // COIN
                         if ((bally > coiny-10 && bally < coiny+10) && (ballx > coinx-10 && ballx < coinx+10))
                coinx = Math.abs(r.nextInt()) % 617 + 1;
                coiny = Math.abs(r.nextInt()) % 300 + 1;
                   jLabel9.setLocation(new Point(coinx, coiny));
                        System.out.println("Coinx:"+coinx+"");
                        System.out.println("Coiny:"+coiny+"");
                        jLabel1.setText(""+ coin++ +"");
                        System.out.println("Ballx:"+ballx+"");
                        System.out.println("Bally:"+bally+"");
         private void jPanel1_keyReleased(KeyEvent e)
              System.out.println("\njPanel1_keyReleased(KeyEvent e) called.");
              // TODO: Add any handling code here
              jLabel5.setIcon(new ImageIcon("IMG\\ballstanding2.gif"));
         private void jPanel1_keyTyped(KeyEvent e)
              System.out.println("\njPanel1_keyTyped(KeyEvent e) called.");
              // TODO: Add any handling code here
         // TODO: Add any method code to meet your needs in the following area
    //============================= Testing ================================//
    //=                                                                    =//
    //= The following main method is just for testing this class you built.=//
    //= After testing,you may simply delete it.                            =//
    //======================================================================//
              public void Reminder(int seconds) {
            timer = new Timer();
            timer.schedule(new RemindTask(), seconds*1000);
        class RemindTask extends TimerTask {
            public void run() {
                System.out.format("Time's up!%n");
                timer.cancel(); //Terminate the timer thread
         public static void main(String[] args)
              JFrame.setDefaultLookAndFeelDecorated(true);
              JDialog.setDefaultLookAndFeelDecorated(true);
              try
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              catch (Exception ex)
                   System.out.println("Failed loading L&F: ");
                   System.out.println(ex);
           new superball();
                    new Reminder(5);
            System.out.format("Task scheduled.%n");
    //= End of Testing =
    }

    No, it's because you can't have a constructor called Reminder if you don't have a class named Reminder.

  • Have an object as return type in a method in the WebDynproComponent

    Hello together.
    I've wrote an EJB in which is a method that read out a DB Table XYZ. In this EJB also are methods to search a single entry.
    In my WebDynpro applixcation i have a method in the Component that access the EJB and retrive the single entry for example. In the View implemantation i call the method from the "WEbDynPro component" which have a string as return type.
    Is it possible to have an object as return type?
    public java.lang.String sr( int KVNR )
        //@@begin sr()
        KVNummerDTO kvnrObject = new KVNummerDTO();
        String Kasse = "";
          try
              KVNRSessionLocal kVNummerSessionLocal = kVNRSessionLocalHome.create();
              kvnrObject = kVNummerSessionLocal.getKVNummer(KVNR);
              Kasse = kvnrObject.getKasse();
          catch (Exception e)
               e.printStackTrace();
               wdComponentAPI.getMessageManager().reportException(e.getMessage(), true);
          return Kasse;
        //@@end
    I want to return kvnrObject  and not only a string!

    Hello Micheal,
    While Creating a method in front of the return type click on the browse and select Java Native Type Radio Button and again click on the browse button available there. Type the name of the class in the class in it and you can select the return type. If it is a user made class then first the required Java files under the path Resources>src>packages><create a folder>java file. Then build the project so that the class name is visible in list while selecting the return type.
    Regards,
    Ardhendu

  • Native method with String return type

    Hi
    i am implementing a Native method with String Return type.
    i am able call the respective C++ method and my C++ method is printing the String (jstring in c++ code ) correctly
    i but i am getting nullpointerexcepti while loading the string in to my Java String .
    i am sure my java code calling the C++ code beacause my C++ code is printing the value and one more wonder is after the NPE my c++ code able to print the value
    the code follows
    HelloWorld.java
    public class HelloWorld {
         private native String print();
         static {
             System.loadLibrary("HelloWorld");
         public static void main(String[] args) throws InterruptedException,NullPointerException{
              HelloWorld hW= new HelloWorld();
              for(int i=0;;i++){
                   String str= new HelloWorld().print();
                   System.out.println(str);
                   Thread.sleep(10000);
    }and HelloWorld.cpp
    // HelloWorld.cpp : Defines the entry point for the DLL application.
    #include "stdafx.h"
    #include "jni.h"
    #include <stdio.h>
    #include "HelloWorld.h"
    #include <windows.h>
    #include "tchar.h"
    #include "string.h"
    #ifdef _MANAGED
    #pragma managed(push, off)
    #endif
    CHAR cpuusage(void);
    typedef BOOL ( __stdcall * pfnGetSystemTimes)( LPFILETIME lpIdleTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime );
    static pfnGetSystemTimes s_pfnGetSystemTimes = NULL;
    static HMODULE s_hKernel = NULL;
    void GetSystemTimesAddress()
         if( s_hKernel == NULL )
              s_hKernel = LoadLibrary(_T("Kernel32.dll"));
              if( s_hKernel != NULL )
                   s_pfnGetSystemTimes = (pfnGetSystemTimes)GetProcAddress( s_hKernel, "GetSystemTimes" );
                   if( s_pfnGetSystemTimes == NULL )
                        FreeLibrary( s_hKernel ); s_hKernel = NULL;
    // cpuusage(void)
    // ==============
    // Return a CHAR value in the range 0 - 100 representing actual CPU usage in percent.
    CHAR cpuusage()
         FILETIME               ft_sys_idle;
         FILETIME               ft_sys_kernel;
         FILETIME               ft_sys_user;
         ULARGE_INTEGER         ul_sys_idle;
         ULARGE_INTEGER         ul_sys_kernel;
         ULARGE_INTEGER         ul_sys_user;
         static ULARGE_INTEGER      ul_sys_idle_old;
         static ULARGE_INTEGER  ul_sys_kernel_old;
         static ULARGE_INTEGER  ul_sys_user_old;
         CHAR  usage = 0;
         // we cannot directly use GetSystemTimes on C language
         /* add this line :: pfnGetSystemTimes */
         s_pfnGetSystemTimes(&ft_sys_idle,    /* System idle time */
              &ft_sys_kernel,  /* system kernel time */
              &ft_sys_user);   /* System user time */
         CopyMemory(&ul_sys_idle  , &ft_sys_idle  , sizeof(FILETIME)); // Could been optimized away...
         CopyMemory(&ul_sys_kernel, &ft_sys_kernel, sizeof(FILETIME)); // Could been optimized away...
         CopyMemory(&ul_sys_user  , &ft_sys_user  , sizeof(FILETIME)); // Could been optimized away...
         usage  =
              (ul_sys_kernel.QuadPart - ul_sys_kernel_old.QuadPart)+
              (ul_sys_user.QuadPart   - ul_sys_user_old.QuadPart)
              (ul_sys_idle.QuadPart-ul_sys_idle_old.QuadPart)
              (100)
              (ul_sys_kernel.QuadPart - ul_sys_kernel_old.QuadPart)+
              (ul_sys_user.QuadPart   - ul_sys_user_old.QuadPart)
         ul_sys_idle_old.QuadPart   = ul_sys_idle.QuadPart;
         ul_sys_user_old.QuadPart   = ul_sys_user.QuadPart;
         ul_sys_kernel_old.QuadPart = ul_sys_kernel.QuadPart;
         return usage;
    BOOL APIENTRY DllMain( HMODULE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved
        return TRUE;
    #ifdef _MANAGED
    #pragma managed(pop)
    #endif
    JNIEXPORT jstring JNICALL
    Java_HelloWorld_print(JNIEnv *env, jobject obj)
           int n;
         GetSystemTimesAddress();
         jstring s=(jstring)cpuusage();
         printf("CPU Usage from C++: %3d%%\r",s);
         return s;
    }actually in the above code below part does that all, in the below code the printf statement printing correctly
    JNIEXPORT jstring JNICALL
    Java_HelloWorld_print(JNIEnv *env, jobject obj)
           int n;
         GetSystemTimesAddress();
         jstring s=(jstring)cpuusage();
         printf("CPU Usage from C++: %3d%%\r",s);
         return s;
    }and the NPE i get is
    Exception in thread "main" java.lang.NullPointerException
         at HelloWorld.print(Native Method)
         at HelloWorld.main(HelloWorld.java:10)
    CPU Usage from C++:   6%any solution?
    Thanks
    R
    Edited by: LoveOpensource on Apr 28, 2008 12:38 AM

    See the function you wrote:
    JNIEXPORT jstring JNICALL Java_HelloWorld_print(JNIEnv *env, jobject obj)
           int n;
         GetSystemTimesAddress();
         _jstring s=(jstring)cpuusage();_
         printf("CPU Usage from C++: %3d%%\r",s);
         return s;
    }Here you try to cast from char to jstring, this is your problem, jstring Object should be created:
    char str[20];
    sprintf(str, "%3d", (int)cpuusage());
    printf("CPU Usage from C++: %s%%\r",str);
    jstring s=env->NewStringUTF(str);
    return s;

  • Guideline for deciding method return type

    Hi All,
    I have some concerns in deciding the return type of some specific methods in the application (web service application to be specific).
    Concern: There are methods like 'deleteData', 'cancelProcess', 'uploadData' etc. Ideally these methods don't require server to perform complex business logic. Now there are 2 views to decide the return type of these methods. The first approach could be to return a boolean indicating whether the operation is successful or not and the other apporach is to return void but throw an exception if anything goes wrong.
    Both approaches have their own advantages and drawbacks. Sending a boolean seems to be cleaner but in case of unsuccess caller won't get the exact exception but just a flag. In second apporach, the caller has to rely on try/catch to decide the logical flow.
    I know, there can't be any generic answer to this question but I just wanted to know comments from experts on this or probably some guidelines.
    Thanks and Regards,
    Ashish Arya

    If there is a legitimate reason why your method might not actually do what it should, then use the boolean return value.
    Example: someList.remove("foo") will return false if "foo" is not actually in the list (because remove() simply specifies that it will make sure that the element is not in the list after the call. Since this is fulfilled in this case, there's no case to throw an exception, even if it didn't actually remove anything).
    If the only reason for not doing what it should is some error condition, then throw an exception:
    Example: someList.get(100) will throw an exception, when the list has less than 101 elements.

  • Applet with 2 methods with the same name in ie

    Hi,
    I have a problem with the Java 1.5 plugin for Internet Explorer .
    When my Applet contains 2 methods with the same name but not the same return type, ie does not take the good return type.
    Here is an exemple :
    * Class TestApplet
    package test.applet;
    import java.applet.Applet;
    public class TestApplet extends Applet {
         public void init() {
              System.out.println("init()");
         public void start() {
              System.out.println("start()");
         public String test(String s) {
              System.out.println("test(String) :" + s);
              return s;
         public boolean test(int i) {
              System.out.println("test(int) :" + i);
              return true;
    }I have 2 methods test(), one returns a String and the other a boolean.
    I use the following html code :
    <html>
    <head>
    <script>
    function test() {
         alert(document.DataAccess.test("hello"));
    </script>
    </head>
    <body>
    <applet WIDTH="500" HEIGHT="200" ID="DataAccess" NAME="DataAccess" CODE="test.applet.TestApplet">
    </applet>
    <div onclick="test()">test</div>
    </body>
    </html>
    When I click on "test", the alert show "true" instead of "hello".
    The problem only occurs with a JVM 1.5. It work fine with JVM 1.4.
    Any idea ? Is it a bug ?
    Thanks.

    In your javascript method:
    function test() {
    alert(new String(document.DataAccess.test("hello")));
    MSJVM and SUN jre use different conversion from javaScript objects to Java.
    if you call from javaScript:
    document.getElementById("myApplet").myMethod(22);
    The method in MSJVM should look like this:
    public whatever myMethod(Double d);
    and SUN jre:
    public whatever myMethod(Integer i);
    The best thing to do is this:
    public whatever myMethod(Object o);
                   int col = 0;
                   if (o.getClass().getName().toLowerCase().indexOf("integer") != -1) {
                        col = ((Integer) o).intValue();
                   } else {
                        col = ((Double) o).intValue();
                   }

  • Multiple Return Types

    haven't been around in a while, so I thought I'd stir up some comments with a suggestion for a new feature in Java, which I'm sure has been suggested at some point, but I can't remember seeing it talked about, so here goes:
    Multiple Return Types:
    public String, int getStateInfo(String abbrev) {
       if("nj".equalsIgnoreCase(abbrev)) {
          return "New Jersey", 11408042;
       // ... and other states...
       return null, -1;
    String name, int population = getStateInfo("nj");
    System.out.println("The population of " + name + " is " + population + ".");Yes yes, I know. Create a StateInfo object with the fields needed. Still, I think that could be interesting.

    apart from it getting ugly with more than twoparameters
    What? How is this ugly? ;-)
    public String, int, String, Color, String, String
    getStateInfo(String abbrev) {
    return name, population, stateFlower, stateColor,
    or, stateAnimal, governorsName;
    there no indication on what the return valuesrepresent.
    Well, I guees the API docs would have to speak for
    themselves. Or better method naming... In that
    sense, it's no different then now. I could write a
    method "getStateName()" and return totally different.
    public String, int getStateNameAndPopulation(String
    abbrev) {...
    I used to like "tuples" when I studied The Tom Programming Language (that's how he calls them), as every CS student is a bit of a "featurist"... Now that I came to develop 40 hours a week and to love Java's simple and powerful expressiveness, I tend to find such constructs overly ugly to be avoided as possible... a matter of personal taste, too, I suppose...

  • How can I get rid of a type generated by the Data/Services return type wizard?

    Hi All,
    I have a JSON service that returns an object called "error".  The Data/Services "Configure Return Type" wizard automatically turned this into a class "Error".
    However, this caused over a hundred errors to show up inside the generated classes, "Call to a possibly undefined method Error."  That's because of lines like this:
    throw new Error(propertyName + " is not a data property of entity Agreements"); 
    It's trying to throw a regular "Error" object, but now that there's an "Error" class in the same package, that is taking precedence--and that Error object doesn't have a constructor with a single parameter.  At least, that's what I think is going on.
    I tried to fix it by deleting _ErrorEntityMetadata.as, _Super_Error.as, and Error.as from the valueObjects package.  I then opened the FML file and deleted the definition for the entity "Error" and every reference to the Error entity (class) in my FML file.
    I then changed my JSON service so that it returns an object called "serviceError" instead of just "error".
    But, whenever I re-run the "Configure Return Type" wizard, it regenerates the Error class, even though I've deleted it from everywhere I can find it.  That breaks my project completely!  How can I end this and get Flash Builder to *stop* generating this type!
    In the "Configure Return Type" wizard I very carefully inspected the type of every bit of data coming back to make sure none of them show up as type "Error."  And they don't (as expected, since I changed the object's name to serviceError--now the type of that object is ServiceError.
      -Josh

    I think you are facing this known issue https://bugs.adobe.com/jira/browse/FB-29770
    Please vote it.
    Thanks for the link--I just voted for it.
    To avoid this, in the last page of "Configure Return Type", edit return type name to something else (You can also edit subnodes's name too in the wizard).
    Actually, that's exactly what I saw doing; I apologize if that wasn't clear in my post.
    I closed and restarted Flash Builder, and once I did that Flash Builder stopped generating the Error class.  My guess is that the FML file, even though I had updated it (by deleting all references to the Error class), was cached in some fashion by Flash Builder, and restarting Flash Builder forced it to reread the FML file?
    Additional point of clarification: my understanding is that the FML file stores all the metadata about the services that Flash Builder has been able to figure out so far, and when you run the Configure Return Type wizard, it will regenerate *every* type in the FML file, even if that type is not mentioned anywhere in the particular return value that you are working with.
    Edited to provide additional thoughts on FML file.

Maybe you are looking for