Two code examples

Hi,
Look below, what is the difference between these two code examples? I always use the first one, but is it right to use the second one to get the same result?
Ex.
public void Hello(int i, Vector vec)
int j;
Vector vector;
j=i;
vector=vec;
j++;
vector[c]=8;
public void Hello(int i, Vector vec)
i++;
vec[c]=8;
/A

The code is much the same but the second one performs better.
You should also keep in mind that primitive datatypes like int, char, ... are call-by-value and objects are call-by-reference.
call-by-value:
Means that the only the value of the integer is copied to the function.
call-by-reference:
Means that the only the reference is given to the function and so you can manipulate the object. ==> the changes are also in the object in the calling fkt.

Similar Messages

  • Can't see any difference between two code examples

    Hi,
    I wonder, what is the difference between these two code examples?
    In my eyes they do the same thing, or?
    protected void processWindowEvent(WindowEvent e) {
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    dispose();
    super.processWindowEvent(e);
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == button1) {
    dispose();
    /A

    Where did you learn Swedish? You wrote it right but this sentence: "Mig sj�lv, jag kommer fr�n....." is not quite right. You have to write it like this: "Sj�lv s� kommer jag fr�n ...." or "Jag kommer fr�n....".
    When I wrote "or" before, I meant or like in "right or wrong" not like in "eller hur".
    I'm born in Poland but i moved to Sweden when I was 6,5 years old.
    I have one more question about the window-closing-thing:
    In an other file it looks like this:
    private class SymWindow extends java.awt.event.WindowAdapter
              public SymWindow(){}
                        public void windowClosing(java.awt.event.WindowEvent event)
    jMenuFileExit_actionPerformed();
    ////////this comes after that one above//////////
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING){
    jMenuFileExit_actionPerformed();
    In this file you can choose to exit the program by choosing exit from a menu or just click in the upper right corner (the cross). If you have a file open, don't save it and want to exit, a message will appear with a question if you want to save. This worked fine from the beginning but to this message I added a cancel button (before it was only yes and no). This didn't work. I took away the second code example and and added this: "setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)" to the first one and everything works fine. The three buttons work if I choose exit from the menu or if I click the cross. Is it right?
    By the way, thanks for your help
    /A

  • How to integrate two codes  ?

    A.java
    class A
         public static void main(String args[])
    System.out.println("hello");
         // code
    Format.java
    import java.util.*;
    class Format
    public static void main(String args[])
    System.out.println("hi");
    // code
    how to integrate two codes ?

    Please be a little more explicit about what you're doing, what you expect to happen, and what you actually observe - "integrate two codes" isn't very clear.
    Please post a short, concise, executable example of what you're trying to do. This does not have to be the actual code you are using. Write a small example that demonstrates your intent, and only that. Wrap the code in a class and give it a main method that runs it - if we can just copy and paste the code into a text file, compile it and run it without any changes, then we can be sure that we haven't made incorrect assumptions about how you are using it.
    Post your code between [code] and [/code] tags as described in Formatting Help on the message entry page. Cut and paste the code, rather than re-typing it (re-typing often introduces subtle errors that make your problem difficult to troubleshoot). Please preview your post when posting code.
    If you don't know where to start, here are some excellent resources:
    http://java.sun.com/docs/books/tutorial/
    http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/compile.html
    http://java.sun.com/learning/new2java/index.html
    http://javaalmanac.com
    http://www.jguru.com
    http://www.javaranch.com
    Bruce Eckel's Thinking in Java
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java

  • C# Code Example for Configuring SQL 2005 Reporting Services?

    I have found the MSDN articles describing the classes, public methods, etc. for configuring SQL Server 2005 Reporting Services via WMI. I need to initially configure them and just do this:
    - Report Server Virtual Directory
    - Windows Service Identity
    - Web Service Identity
    - Database Setup
    - Email Settings
    - Execution Account
    Is there a C# code example that already exists putting together all of this? I didn't want to reinvent the wheel if I didn't need to.
    -Ed

    Jin,
    Thanks so much! This is great! Your work is awesome!
    I have a couple of issues that came up...
    1) CreateVirtualDirectory.vbs creates the virtual directory for the Report Server just fine. Now how do I distinguish a script to create the virtual directory for the Report Manager?
    2) I decided to go ahead and use what you did for scripting CreateApplicationPool (using http://msdn.microsoft.com/en-us/library/ms155349(SQL.90).aspx). I found the syntax is wrong here when I kept getting an error, so I put PowerShell on the server and pulled the following info:
    Name       : CreateApplicationPool
    MemberType : Method
    Definition : System.Management.ManagementBaseObject CreateApplicationPool(System.String Name, System.Boolean UseBuiltIn
                 Account, System.String Account, System.String Password)
    However, I'd like to use "NT Authority\NetworkService" or "Network Service" as the account (which is an option for the Builtin accounts when I us RSConfigTool.exe). This is the syntax I used:
    objInParam.Properties_.Item(
    "Name") = "ReportServer"
    objInParam.Properties_.Item("UseBuiltInAccount") = true
    objInParam.Properties_.Item("Account") = "NT Authority\NetworkService"
    objInParam.Properties_.Item("Password") = ""
    But I always get an error with a negative number for the HRESULT.
    Any ideas?-Ed

  • [code] does not work correctly, cannot post code example.

    Hi, I tried to do a code example, but HTML tags inside java quoted strings were intereperted. Like the <IMG> tag and the <H1> tag..
    How do I prevent this????
    Re: How to post an audio file in JSP or servlet

    OK, it was the IMG and H1 tags....
    Looks like I can embed an image though <img src="http://www.oracle.com/admin/images/ocom/oralogo_small.gif">

  • Beginner Question | The use of modulus in this simple code example.

    Hello everyone,
    I am just beginning to learn Java and have started reading "Java Programming for the absolute beginner". It is quite a old book but seems to be doing the trick, mainly.
    There is a code example which I follow mostly but the use of the modulus operator in the switch condition doesn't make sense to me, why is it used? Could someone shed some light on this for me?
    import java.util.Random;
    public class FortuneTeller {
      public static void main(String args[]) {
        Random randini = new Random();
        int fortuneIndex;
        String day;
        String[] fortunes = { "The world is going to end :-(.",
          "You will have a HORRIBLE day!",
          "You will stub your toe.",
          "You will find a shiny new nickel.",
          "You will talk to someone who has bad breath.",
          "You will get a hug from someone you love.",
          "You will remember that day for the rest of your life!",
          "You will get an unexpected phone call.",
          "Nothing significant will happen.",
          "You will bump into someone you haven't seen in a while.",
          "You will be publicly humiliated.",
          "You will find forty dollars.",
          "The stars will appear in the sky.",
          "The proper authorities will discover your secret.",
          "You will be mistaken for a god by a small country.",
          "You will win the lottery!",
          "You will change your name to \"Bob\" and move to Alaska.",
          "You will discover first hand that Bigfoot is real.",
          "You will succeed at everything you do.",
          "You will learn something new.",
          "Your friends will treat you to lunch.",
          "You will meet someone famous.",
          "You will be very bored.",
          "You will hear your new favorite song.",
          "Tomorrow... is too difficult to predict" };
        System.out.println("\nYou have awakened the Great Randini...");
        fortuneIndex = randini.nextInt(fortunes.length);
        switch (randini.nextInt(7) % 7) {   
          case 0:
            day = "Sunday";
            break;
          case 1:
            day = "Monday";
            break;
          case 2:
            day = "Tuesday";
            break;
          case 3:
            day = "Wednesday";
            break;
          case 4:
            day = "Thursday";
            break;
          case 5:
            day = "Friday";
            break;
          case 6:
            day = "Saturday";
            break;
          default:
            day = "Tomorrow";
        System.out.println("I, the Great Randini, know all!");
        System.out.println("I see that on " + day);
        System.out.println("\n" + fortunes[fortuneIndex]);
        System.out.println("\nNow, I must sleep...");
    }

    randini.nextInt(7) % 7randini.nextInt(7) returns a value in the range 0 <= x < 7, right? (Check the API!) And:
    0 % 7 == 0
    1 % 7 == 1
    2 % 7 == 2
    3 % 7 == 3
    4 % 7 == 4
    5 % 7 == 5
    6 % 7 == 6Looks like superfluous code to me. Maybe originally they wrote:
    randini.nextInt() % 7Note this code has problems, because, for example -1 % 7 == -1

  • Need code example for dynamicly changing UI Propertey

    Hello,
    Can someone show me a simple code example that does the following:
    A view which contains a button and a label.
    Each press on the button changes the color (or other visible property) of the label.
    But note: Don't bind the property to the Context for that, I want to do it through the doModifyView method.

    hi Roy Cohen,
    I think u r not looking for the visibility property they have mentioned.
    I think u r looking for a procedure to change the way the element looks..is it..
    The problem is if u want any change to be visible when the button is pressed u can only change the length or the width.There is no option to change the semantic color or whatever.
    To change the size u can try this code
    IWDInputField in = (IWDInputField)view.getElement("<element name>");
    in.setWidth(some value which is set when the button is pressed);
    Is this wat u r looking for?
    Jus mention it if there is something  else.
    Regards
    Bharathwaj

  • I need code example for server act as client and vice versa

    Hi all,
    I want code example for performing both server and clients using RMI. I mean Server will act as client and client will act as server. So a single program will act as both client and server .
    Please give example, it will helpful to complete my project. I am struggling in this stage. Its like peer to peer action.
    Thanks & Regards
    R.Ragupathi

    1. The tutorial shows you how to do cleint/server.
    2. Search on the topic "callback" to see how cleint and server roles can be reversed.

  • HT3678 quicktime pro doesn't accept my registration code.  I have paid for two codes and neither one works.

    quicktime pro doesn't accept my registration code.  I have paid for two codes and neither one works.

    Ensure that you're following these steps.

  • Embedding images in excel cells-please provide code examples

    I need to create excel worksheet and embed an image in a cell. After looking at the POI javadoc and examples, I cannot figure out how to embed the image in a cell, only in the sheet. Does POI support this? I have also been looking a using Jexcel and would like to know if Jexcel supports this? If anyone has answers, please provide code examples.
    thanks

    I need to create excel worksheet and embed an image in a cell. After looking at the POI javadoc and examples, I cannot figure out how to embed the image in a cell, only in the sheet. Does POI support this? I have also been looking a using Jexcel and would like to know if Jexcel supports this? If anyone has answers, please provide code examples.
    thanks

  • Differnence between two codes of event handling

    hello i am learning event handling in swing but confused between two codes :-
    the first code of event handling is given in book "head first java " and working fine
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Swingdemo implements ActionListener {
        JButton jbut = new JButton("Click me");
          public void go(){
            JFrame jfrm = new JFrame(" sample swing");
            JLabel jlab = new JLabel("hello Swing");
            jfrm.add(BorderLayout.NORTH,jlab);
            jfrm.add(BorderLayout.CENTER,jbut);
            jfrm.setVisible(true);
            jbut.addActionListener(this); 
            jfrm.setSize(100,100);
            jfrm.setDefaultCloseOperation(jfrm.EXIT_ON_CLOSE);
       public static void main(String[] args) {
            Swingdemo obj = new Swingdemo();
            obj.go();
    public void actionPerformed(ActionEvent e)
        jbut.setText("i have been clicked");
    }}THe second code which i think is fine is giving the following error :-
    C:\java\iodemo\src\Swingdemo.java:26: non-static variable jbut cannot be referenced from a static context
            jfrm.add(BorderLayout.CENTER,jbut);
    C:\java\iodemo\src\Swingdemo.java:28: non-static variable this cannot be referenced from a static context
            jbut.addActionListener(this); 
    C:\java\iodemo\src\Swingdemo.java:28: non-static variable jbut cannot be referenced from a static context
            jbut.addActionListener(this);  the second code is as follows :-
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Swingdemo implements ActionListener {
    public static void main(String[] args) {
    JFrame jfrm = new JFrame(" sample swing");
    JLabel jlab = new JLabel("hello Swing");
    jfrm.add(BorderLayout.NORTH,jlab);
    jfrm.add(BorderLayout.CENTER,jbut);
    jfrm.setVisible(true);
    jbut.addActionListener(this);
    jfrm.setSize(100,100);
    jfrm.setDefaultCloseOperation(jfrm.EXIT_ON_CLOSE);
    JButton jbut = new JButton("Click me");
    public void actionPerformed(ActionEvent e)
    jbut.setText("i have been clicked");
    Plz help me wat this error means that not static variable cannot be reffered from static context .
    thanks

    There are multiple problems in your 2nd set of code. You call this:
    jfrm.add(BorderLayout.CENTER,jbut);
    Before you actually create the jbut button:
    JButton jbut = new JButton("Click me");
    But based on the error message, you have another 'jbut' variable somewhere that's not included in the code you posted, and that's the one it's complaining about being referenced in a static context.
    The problem with the static context is because all your code is in the static void main method. In that method, a Swingdemo instance doesn't exist yet, therefore any non-static variables won't exist yet either. If you move all that code into the Swingdemo constructor, and just have main create a new Swingdemo instance, that should do it.

  • How do the two codes work ?

    i came across the following code in socket programming in the net,could anyone please tell me that how do the following codes work together? there is no main class in ChatHandler programme but there seems that it is a separate programme.. being new to java i am unable to understand it, please someone help
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    public class ChatServer {
        public static final int DEFAULT_PORT = 9800;
        public static void main(String[] args) {
         int port = DEFAULT_PORT;
         ServerSocket serverSocket = null;
         Socket socket = null;
         try {
             if(args.length > 0)
                 port = Integer.parseInt(args[0]);
         } catch(NumberFormatException nfe) {
             System.err.println("Usage: java ChatServer [port]");
             System.err.println("Where options include:");
             System.err.println("\tport the port on which to listen.");
             System.exit(0);
         try {
             serverSocket = new ServerSocket(port);
             while(true) {
                 socket = serverSocket.accept();
                 ChatHandler handler = new ChatHandler(socket);
                 handler.start();
         } catch(IOException ioe) {
             ioe.printStackTrace();
         } finally {
             try {
                 serverSocket.close();
             } catch(IOException ioe) {
              ioe.printStackTrace();
    }// ChatHandler.java
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    import java.io.OutputStreamWriter;
    import java.io.PrintWriter;
    import java.net.Socket;
    import java.util.Vector;
    public class ChatHandler extends Thread {
      static Vector handlers = new Vector( 10 );
      private Socket socket;
      private BufferedReader in;
      private PrintWriter out;
        public ChatHandler(Socket socket) throws IOException {
            this.socket = socket;
         in = new BufferedReader(
             new InputStreamReader(socket.getInputStream()));
         out = new PrintWriter(
             new OutputStreamWriter(socket.getOutputStream()));
        public void run() {
            String line;
         synchronized(handlers) {
             handlers.addElement(this);
    // add() not found in Vector class
         try {
             while(!(line = in.readLine()).equalsIgnoreCase("/quit")) {
              for(int i = 0; i < handlers.size(); i++) {     
                   synchronized(handlers) {
                          ChatHandler handler =
                           (ChatHandler)handlers.elementAt(i);
                      handler.out.println(line + "\r");
                   handler.out.flush();
         } catch(IOException ioe) {
             ioe.printStackTrace();
         } finally {
             try {
              in.close();
              out.close();
              socket.close();
             } catch(IOException ioe) {
             } finally {
              synchronized(handlers) {
                  handlers.removeElement(this);
    }

    pranay09 wrote:
    ok, but when i am compiling the two codes, then for the second one i get the error that no main class found:No, you will never get that when compiling.You will get that when running, if the class you try to run is not on your classpath.
    main() is simply the entry point into your program for the JVM. When you say
    java MyClassYou're telling hte JVM to execute public static void main(String[] args) in the class MyClass. That class must be on your classpath and it must have that method. That class is then free to use any other classes, in its own package or in other packages (provided they are accessible and on the classpath), regardless of whether those classes have a main method.

  • ABAP Code example using "GENERATE DYNPRO"

    I am looking for ABAP code example who use the "Generate dynpro" dynamic generation of dynpro at runtime under SAP 4.6C version.
    Best regards,

    We have some programs that do:
    form %view.
    data: anz type i,
          prog like sy-repid.
      prog = sy-repid.
      perform init_download(rsaqexce).
      case %tab.
      when 'G00'.
        perform generate_view_dynpro(rsaqexce)
                using prog text-grl.
        describe table %g00 lines anz.
        tview100-lines = anz.
        perform init_view(rsaqexce) tables %g00 using tview100.
        call screen 100.
        perform reset_view_dynpro(rsaqexce).
      when others.
        message s860(aq).
      endcase.
    endform.
    I think they were copied from existing SAP programs. In any event, look at the relevant forms in program rsaqexce.
    And as Rich noted, SAP doesn't recommend this.
    Rob

  • Code Example connection to MS Exchange

    Hi
    Has anyone got a link to a code example showing how to log into an account on MS Exchange server
    I am trying to log in and read emails from my student account that is on a ms exchange server but am having little luck.
    Could someone give me a couple of good links where i can get some helpful information.
    Thanks very much

    hi
    i am sitting with the same problem, if you find anything please let me know. thanx

  • Need Code Example

    Can someone please show me a code example of how to use RS_EXTERNAL_SELSCREEN_STATUS function.
    I want to delete "Create delivery in background" pushbutton from report vl10h.

    This is the example given in the FM documentation.
    Example
    Example for calling RS_EXTERNAL_SELSCREEN_STATUS:
    PROGRAM SAPDBxyz DEFINING DATABASE xyz.
    FORM INIT.
    CALL FUNCTION 'RS_EXTERNAL_SELSCREEN_STATUS'
    EXPORTING P_FB = 'TEST_EXTERNAL_STATUS'.
    ENDFORM.
    Example for function module that sets the status:
    FUNCTION TEST_EXTERNAL_STATUS.
    ""Local interface:
    *" IMPORTING
    *" P_SUBMIT_MODE
    *" TABLES
    *" P_EXCLUDE STRUCTURE RSEXFCODE
    *" EXCEPTIONS
    *" NO_ACTION
    IF P_SUBMIT_MODE NE SPACE.
    RAISE NO_ACTION.
    ENDIF.
    SET PF-STATUS 'TEST' EXCLUDING P_EXCLUDE.
    SET TITLEBAR 'TST'.
    ENDFUNCTION.
    INITIALIZATION.
    CUA *
    IMPORT T185V FROM MEMORY
    ID SD_COND_MEM_01. "JAY
    RV13B-KVEWE = 'B'.
    RV13B-KOTABNR = '001'.
    CALL FUNCTION 'RS_SUBMIT_INFO'
    IMPORTING
    P_SUBMIT_INFO = RSSUBINFO.
    IF NOT RSSUBINFO-MODE_NORML IS INITIAL.
    TITEL = T185V-CTITEL.
    CALL FUNCTION 'RV_CONDITION_GET_CUA_REPO'
    EXPORTING
    PFKEY_I = 'BSELE'
    TITLE_I = TITEL
    PAR1_I = T185V-PARA1
    PAR2_I = T185V-PARA2
    PAR3_I = T185V-PARA3
    PAR4_I = T185V-PARA4
    TABLES
    EXCL_I = AUSSCHLUSS.
    CALL FUNCTION 'RS_EXTERNAL_SELSCREEN_STATUS'
    EXPORTING
    P_FB = 'RV_CONDITION_SET_CUA_REPO'.
    ENDIF.

Maybe you are looking for

  • Red color not printed on hp 2115 All-in-one

    Hi, Since a few years I have a HP PSC 2115 all-in-one printer that has been working fine up till now. I don't use it very often, especially not for colour printing and now it seems I have a prolem with clogged up contacts or something. The blue and y

  • BAPI  or  IDOC

    Hi friends,                   We have the Requirement of taking customer data from Legacy to ECC through PI. The Client has 167 fields in his customer database . But ECC needs Only 25-30 fields . BI needs all fields. So my PI consultant has create on

  • Conversion from 11 to 10

    Hello, can you please convert these VIs from version 11 to 10? I found them in community docs: https://decibel.ni.com/content/docs/DOC-19955 Many thanks, Dan Attachments: log into Hotmail ActiveX.zip ‏27 KB

  • SAP Netweaver 2004s Sneak Preview - Partner not reached

    Hi all, I've tried to search the forum for similar message but couln't find it so I post a new one, hopefully someone able to give some help. I've installed the SAPNW sneak preview ABAP on XP, right after installation I'm able to logon to NSP system.

  • Travel Back In Time????

    I screwed something up in IPhoto and can't seem to figure out how it happened or how to remedy it.... Is there a way to reset my computer to an earlier activity history (i.e. before the screw up...like yesterday?)- I remember being able to do this on