SImple but important java question

hello all,
just been revising for an exam and just have come across this bit where my notes are trying to explain that arguments passed to java methods are PASSED BY VALUE, and the example is this:
public class TestSwap {
   public static void swap( int x, int y )
      int temp;
      temp = x; x = y; y = temp;
      return;
   public static void main( String [] args )
      int a = 4;
      int b = 5;
      swap( a, b );
      System.out.println( "a=" + a ); // 4
      System.out.println( "b=" + b ); // 5
}Isn't this obvious since when a and b are printed out they are already 4 and 5 because of this:
      int a = 4;
      int b = 5;And the method swap(a,b) method might not just as well be there. because it won't have an affect on when a and b are pinted out???!!!!
Am I jumping the gun, if so can some please explain, i know its important but i cant see it!
Thanks :)

Ok, we are proving, got it.
What the, i cant work out how this works! The example
you gave?
Is it because of the arrays referencing
a[0]...a[1]..etc????!!!Note the difference between swapping a and b vs. swapping a[0] and b[0]. Also, if there were a member variable, swapping a.thing and b.thing would be reflected in the caller.
With your initial example, we're changing the values of the variables, and since the method and the caller each have their own copies of those variables, the caller is not affected. (Note that only a primitive, a reference or null, can be a variable's value in Java, never an object.)
With array elements and member variables of parameters, we're changing the contents of the objects pointed to by those variables. Since there's only a single object for each parameter, and the method's variable and caller's variable both point to that same object, both see the change.
References are passed by value, so changing the reference's value (which object it points to) doesn't affect the caller. But only the reference is copied, not the object, so changing the state of the object will be seen by the caller.

Similar Messages

  • A simple, but slightly stupid, question...

    Hi all
    How do I copy from my IPOD to my computer hard drive.
    Thought it was just a drag and drop, but that doesn't seem to be doing the trick.
    Thanks for the help.

    Remember there are no stupid questions, only stupid answers.
    I use Yamipod to do this. There are other programs but I think Yamipod is best
    http://www.yamipod.com/main/modules/home/

  • Simple but wierd java.lang.NoClassDefFoundError with jar file

    I'm using ant to jar my .class files. My final objective is to create an executable jar. When I run my jar file - "java -jar PM.jar" - I get:
    Exception in thread "main" java.lang.NoClassDefFoundError: pm/PMApp
    This at least tells me that java found my MANIFEST.MF class and that is the correct class it should be looking for, but it doesn't seem to find the class. But when I do - "jar -tf PM.jar" - I get:
    C:\mike\pm\execs>jar -tf PM.jar
    META-INF/
    META-INF/MANIFEST.MF
    pm/
    pm/EasterEgg.class
    pm/JMSMessageListener.class
    pm/PMApp.class
    pm/ReleasePlanTest.class
    pm/SystemArchitectureFrame$1.class
    pm/SystemArchitectureFrame$2.class
    pm/SystemArchitectureFrame$3.class
    pm/SystemArchitectureFrame$4.class
    pm/SystemArchitectureFrame$5.class
    pm/SystemArchitectureFrame$6.class
    pm/SystemArchitectureFrame$7.class
    pm/SystemArchitectureFrame$8.class
    pm/SystemArchitectureFrame.class
    pm/SystemArchitecturePanel.class
    Which shows me that the class is there. I suspected that it might have something to do with CLASSPATH at first because of the java.lang.NoClassDefFoundError, but now I am skeptical that that could be the problem. I even build a new jar file out of different classes to make sure my method was OK and that worked fine. Any ideas? Thanks for your help in advance.

    Here is my Manifest:
    Main-Class: pm.PMApp<carriage return>
    Class-Path: C:/j2sdkee1.3.1/lib/j2ee.jar<carriage return>
    I noticed that if I leave the Class-Path variable unset it has no problem finding the class pm/PMApp, but I then get a class loader error concerning J2EE stuff. Am I missing something in my Class-Path? I tried to even specify the jar file I'm running here, but that didn't work either? I have also tried '.' and './', space delimited in my Class-Path, like this:
    Class-Path: . ./ C:/j2sdkee1.3.1/lib/j2ee.jar<carriage return>
    Thanks for the replies, do you have any more suggestions?

  • OT but important monitor question

    Hi all......
    I'll apologise from the start as this is off
    topic..............but
    I'm sure that many designers are using tft screens to design
    with but i've
    tried them and i'm not a big fan.
    I'm in the process of looking for a new CRT 21" pure flat
    screen monitor and
    would like to ask for other designers to give their opinions
    on the best crt
    screen to use.
    At present i'm using a Hitachi SuperScan 813 21" but it's
    getting a little
    old now.
    I'd appreciate all replies with recommendations, reviews,
    links etc.
    Thanks in advance
    Andy

    Print work. I do websites.....
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Andy" <[email protected]> wrote in
    message
    news:[email protected]...
    > Thanks Murray
    > Brochure??
    >
    > Ady
    >
    >
    > "Murray *ACE*" <[email protected]>
    wrote in message
    > news:[email protected]...
    >> NEC - LCD1912; Dell UltraSharp FP1800; Samsung
    SyncMaster 915N; NEC
    > LCD1515;
    >> NEC MultiSync LCD1530V.
    >>
    >> I wouldn't touch a brochure with a 10' pole!
    >>
    >> --
    >> Murray --- ICQ 71997575
    >> Adobe Community Expert
    >> (If you *MUST* email me, don't LAUGH when you do
    so!)
    >> ==================
    >>
    http://www.dreamweavermx-templates.com
    - Template Triage!
    >>
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    >>
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    >>
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    >> ==================
    >>
    >>
    >> "Andy" <[email protected]>
    wrote in message
    >> news:[email protected]...
    >> > Hi Murray
    >> >
    >> > Could you tell me what make and model they are?
    >> >
    >> > Cheers
    >> > Andy
    >> >
    >> > "Murray *ACE*"
    <[email protected]> wrote in message
    >> > news:[email protected]...
    >> >> I have 5 LCD screens in my immediate
    vision. I have never found fault
    >> > with
    >> >> any of them.
    >> >>
    >> >> --
    >> >> Murray --- ICQ 71997575
    >> >> Adobe Community Expert
    >> >> (If you *MUST* email me, don't LAUGH when
    you do so!)
    >> >> ==================
    >> >>
    http://www.dreamweavermx-templates.com
    - Template Triage!
    >> >>
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    >> >>
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    >> >>
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    >> >> ==================
    >> >>
    >> >>
    >> >> "Andy"
    <[email protected]> wrote in message
    >> >> news:[email protected]...
    >> >> > Hi all......
    >> >> >
    >> >> > I'll apologise from the start as this
    is off topic..............but
    >> >> >
    >> >> > I'm sure that many designers are using
    tft screens to design with
    >> >> > but
    >> > i've
    >> >> > tried them and i'm not a big fan.
    >> >> > I'm in the process of looking for a
    new CRT 21" pure flat screen
    >> >> > monitor
    >> >> > and
    >> >> > would like to ask for other designers
    to give their opinions on the
    >> >> > best
    >> >> > crt
    >> >> > screen to use.
    >> >> > At present i'm using a Hitachi
    SuperScan 813 21" but it's getting a
    >> > little
    >> >> > old now.
    >> >> >
    >> >> > I'd appreciate all replies with
    recommendations, reviews, links etc.
    >> >> >
    >> >> > Thanks in advance
    >> >> >
    >> >> > Andy
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >
    >> >
    >>
    >>
    >
    >

  • Importing Java Class Question

    Hello,
    Sorry for such a newbie question and such a long post, I did remember how to do this before but now I can't for the life of me remember. Anyhow, I have a simple question about importing custom-made java classes, from another directory in the windows operating system. I have the classpath set, and also I realize that because the two files below are in the same directory theres no need for an import statement as Java will look for the class in the same directory.
    But I would like to know how the import statement is suppose to look to import a custom made java class from another directory, (assuming of course that I set the correct classpath)
    here's the java class location:
    c:\school\csc365\narcus.java
    //narcus.java
    import java.io.*;
    class narcus implements Comparable
    String firstName = "firstName";
    String lastName = "lastName";
         public narcus()
         firstName = firstName;
         lastName = lastName;
         public narcus(String f)
         firstName = f;
         lastName = lastName;
         public narcus(String f, String l)
         firstName = f;
         lastName = l;
    public String getFirst()
    return "first..";
         public int compareTo(Object e)
         return 1;
    Here's the location of the driver program thats suppose to use the narcus.java class
    c:\school\csc365\test.java
    //test.java
    //import statement? maybe import "c:\\school\\csc365\\*"; ?
    import java.io.*;
    class test
    public static void main(String[] args)
         narcus jim = new narcus();
         System.out.println("omg\n");
         System.out.println(jim.getFirst());
    And also, here is my classpath:
    PATH=c:\school\csc365\;c:\school\
    The classpath also points to the jdk libraries and few other directories but I didn't write that above, as it probably isn't relevant.
    I've tried the following import statements.
    import "c:\\school\csc365\\narcus.java";
    import "narcus.java";
    import "c:\\school\\csc365\\*";
    But I keep getting an error that says:
    test.java:1 <identifier> expected
    Any help is appreciated!

    Hi Folks,
    I am new to this forum, heard that interesting discussions always happens on this forum so immediately registered,don't want to miss any oppurtunity to participate in discussions.
    I have pretty much basic question regarding compiling and exceuting files in different packages.I have the following directory structure
    C:\Projects\WDPROEast\Development\CommonService\Code\Java from where java files stored in different packages as follows:
    com\wdpro\commerce\common\crm\dae\nautilus\adapter directory has java files in com.wdpro.commerce.coomon.crm.dae.nautilus.adapter package.
    com\wdpro\commerce\common\dae\exception has java files with package named com.wdpro.commerce.common.dae.exception.
    com\wdpro\commerce\common\dls\exception has java files with corresponding package name.
    com\wdpro\commerce\common\dto has java files under proper package name.
    com\wdpro\commerce\common\exception has java files with appropriate package name.
    com\wdpro\commerce\common\util has java files with package name. I am starting at Java Directory,want to compile and run file named a.java in com.wdpro.commerce.coomon.crm.dae.nautilus.adapter package with having all other java files on classpath as follows
    so I issued command for compilation as follows C:\Projects\WDPROEast\Development\CommonService\Code\Java>javac com/wdpro/commerce/common/crm/dae/nautilus/ada
    pter/a.java com/wdpro/commerce/common/crm/dae/nautilus/adapter/NautilusServiceUtility.java com/wdp
    ro/commerce/common/crm/dae/nautilus/adapter/URLReader.java com/wdpro/commerce/common/crm/dae/nautilus/adapter/
    b.java com/wdpro/commerce/common/dae/exception/*.java com/wdpro/commerce/common/dto/*.java
    com/wdpro/commerce/common/exception/*.java com/wdpro/commerce/common/util/*.java com/wdpro/commerce/common/dl
    s/exception/*.java It compiled greatly but when I issue command to run a.class file as
    C:\Projects\WDPROEast\Development\CommonService\Code\Java>java com/wdpro/commerce/common/crm/dae/nautilus/adap
    ter/UtilityAccesssit's giving following exception
    Exception in thread "main" java.lang.NoClassDefFoundError: com/wdpro/commerce/common/crm/dae/nautilus/adapter/
    UtilityAccesssbut when I run a.java with the following command
    C:\Projects\WDPROEast\Development\CommonService\Code\Java>java com/wdpro/commerce/common/crm/dae/nautilus/adap
    ter/UtilityAccess com/wdpro/commerce/common/crm/dae/nautilus/adapter/NautilusServiceUtility.java com/wdpro/com
    merce/common/crm/dae/nautilus/adapter/URLReader.java com/wdpro/commerce/common/crm/dae/nautilus/adapter/Nautil
    usAccessUtility.java com/wdpro/commerce/common/dae/exception/*.java com/wdpro/commerce/common/dto/*.java com/w
    dpro/commerce/common/exception/*.java com/wdpro/commerce/common/util/*.java com/wdpro/commerce/common/dls/exce
    ption/*.javaSo my question do I need to add all required java files to path when required class files are under different packages?is it manadatory.
    I hope you understand my question,pass me any comments you may have.
    Thanks alot,
    Anu

  • Simple Java Question (Hopefully)

    I'm not sure if anyone out here is familiar with ClearCase, I'm sure there are some, but I am trying to create some basic classes that perform various cleartool shell out commands, one of which returns the some information about ClearCase code repositories.
    When I execute a command line "cleartool lsvob" via cmd here's what I get:
    \mt_group \\happy\vobdata\vobstore\mt_group.vbs public
    * \company_cmtools \\happy\vobdata\vobstore\company_cmtools.vbs public
    \loc_test \\happy\vobdata\vobstore\loc_test.vbs public
    \iais \\happy\vobdata\vobstore\iais.vbs public
    \loc_test1 \\happy\vobdata\vobstore\loc_test1.vbs public
    * \ccase_tool \\happy\vobdata\vobstore\ccase_tool.vbs public
    \ddts \\happy\vobdata\vobstore\ddts.vbs public
    \cmtools_a2 \\happy\vobdata\vobstore\cmtools_a2.vbs public
    \pams \\happy\vobdata\vobstore\pams.vbs public
    However, when I try to do this via a class file it just sits there and doesn't do anything. When I change the command string to "cleartool lsvob -s" it prints:
    \mt_group
    \company_cmtools
    \loc_test
    \iais
    \loc_test1
    \ccase_tool
    \ddts
    \cmtools_a2
    \pams
    Does Java have a problem with white spaces? Here is the code I have:
    import java.lang.*;
    import java.io.*;
    import com.oroinc.text.perl.*;
    public class GetVobMount {
         String cleartool;
         String os = System.getProperty("os.name");
         String cmd = " lsvob";
         public String getVobs () {
              Perl5Util perl = new Perl5Util();
              if (perl.match("/Win/i", os)) {
                   cleartool = "cmd /c cleartool.exe";
              } else {
                   cleartool = "/usr/atria/bin/cleartool";
              StringBuffer data = new StringBuffer();
              System.out.println(cleartool + cmd);
              try {
                   Runtime r = Runtime.getRuntime();
                   Process p = r.exec(cleartool + cmd);
                   p.waitFor();
                   DataInputStream in = new DataInputStream(p.getInputStream());
                   String input;
                   while ((input = in.readLine()) != null) {
                                         data.append(input);
                        data.append("\n");
              } catch (Exception e) { System.out.println(e); }
              return data.toString();
         public static void main (String [] args) {
              GetVobMount vobs = new GetVobMount();
              System.out.println(vobs.getVobs());
    }Of course this won't work in an enviroment that isn't using ClearCase but perhaps there is a reason why java won't return a string of:
    \something \\server\path\dir\something.vbs public
    Any help or suggestions will be greatly appreciated.
    -Wes

    Howdy... I myself have done a lot of clearcase work with a Java app that runs on both UNIX and NT, so hail to you.
    So the problem here is that the spawned process blocks? And there is no way to get it to resume?? Isn't this a bug?? The original code seems perfectly acceptable.
    I've encountered the same problem. My app. was running some system calls and there were some unusual error messages due to system/server problems. The java app should've handled it fine (I handle STDERR), but instead my java app FROZE, no doubt because the spawned process went into this blocked state as Chuck described. In my case, when the system/server error was fixed and the error messages went away, my app stopped locking up.

  • Import java.*; question

    Hi,
    My understanding of the import keyword is somewhat similar to includes in C/C++ but the "*" is somewhat confusing. Is it not a wildcard meaning to 'include' all that is necessary in the subcategories? For example, I quite often see
    import java.awt.*;
    import java.awt.event.*;
    Why is the second import necessary, shouldn't the first one include the second?
    Thanks

    .* includes all the class files in that package, not
    all the sub packages, etc thats why the second is
    neccessary...ah, ok... thanks for the quick and clear answer. So understanding the structure of the API is important. It's nice to have the API on the web, but anyone find value in that new Java Almanac book that covers 1.4?

  • Question on import java.util.ArrayList, etc.

    Hi,
    I was wondering what the following meant and what the differences were. When would I have to use these:
    import java.util.ArrayList;
    import java.util.Collections; <--I especially don't understand what this means
    import java.util.Comparator; <---same for this (can I consolidate these into the bottom two?)
    import java.io.*;
    import java.util.*;

    MAresJonson wrote:
    Also, what does this mean:
    return foo == f.getFoo() ? true : false;
    (more specifically...what does the "? true : false" mean and is there another way to code that?)It's called the ternary operator. For your specific example, you could just do:
    return foo == f.getFoo();But, more generally,
      return foo == f.getFoo() ? "equal" : "Not equal";means:
    if (foo == f.getFoo()) {
       return "equal";
    else {
       return "Not equal";
    }As everyone else said at the same time...

  • Import  java.whatever       Standards question

    Is there a difference between doing: import java.net.URL; & import java.net.*;
    The URL class is the only thing I need from there btw.
    Just wondering what the standard is.

    The standard i see the most is to use import java.net.* when you need more then a certain number of that package
    and to use import java.net.URL when you only need a couple.
    The best reason to use the second is to avoid namespace polution by always including everything.

  • Can I build a GUI application with SWING only without [import java.awt.*;]

    I have seen several threads (in forums), books and tutorials about SWING and I see that they all mix SWING with AWT (I mean they import both Swing and AWT in their code).
    The conclusion that comes out is:
    It is good to learn about SWING and forget AWT as it won't be supported later. I have decided to do so, and I never include <<import java.awt.*;>> in my code.
    But I see that you cannot do much without <<import java.awt.*;>>. For example this line which changes the background color:
    <<frame.getContentPane().setBackground(Color.red)>>
    works only with <<import java.awt.*;>>. I have seen that codes in this and other forums import awt to change the background. Why is that?
    After all, I wonder, what can I do;
    My question is, can I change the background (and of course do all other things listener, buttons etc) without using <<import java.awt.*;>>.
    I would like to avoid using <<import java.awt.*;>> and using awt since my program will not work later.
    In addition, I believe there is no point to learn awt, which later will not exist.
    I know, I must have misunderstood something. I would appreceate it very much, if anyone could give me even a short answer.
    Thank you in advance,
    JMelsi

    Since swing is a layer on top of awt, AWT will exist for as long as swing does.
    If sun does ever remove AWT they will have to replace it something else swing can layer on to and you will probably only have to replace your import statements.
    The main difference is the way there drawn to the screen.
    You can do custom drawing on swing components but you can't on AWT.
    If your using a desktop PC system it's probably best to use swing just in case you wish to do some custom drawing.
    awt uses less memory than swing and is faster but swing can be extended. awt comes only as standard.
    Say for example you wish to implement a JButton with a ProgressBar below the button text, this can be done with swing!

  • Cannot import java.sql.BaseQuery

    Hi,
    I am trying to run the following example using JDK6:
    import java.sql.BaseQuery;
    import java.sql.DataSet;
    import java.sql.Select;
    public interface UserQueries extends BaseQuery {
        // Select all users
        @Select (sql ="SELECT userId, firstName, lastName FROM Users",
                 readOnly=false, connected=false, tableName="Users")
        DataSet<User> getAllUsers ();
        // Select user by name */
        @Select (sql ="SELECT userId, firstName, lastName FROM Users"
                 + "WHERE userName=?", readOnly=false, connected=false,
                 tableName ="Users")
        DataSet<User> getUserByName(String userName);
    }But I get the error in the import statement itlself. It is not able to import these classe-
    import java.sql.BaseQuery;
    import java.sql.DataSet;
    import java.sql.Select;
    Are they shipped with JDK 6?
    thnx
    Sanjeev.

    Because those classes don't exist. A simple, and very quick, perusal of the API docs would have told you this.
    http://java.sun.com/javase/6/docs/api/index.html

  • TextSamplerDemo.java question

    I took the TextSamplerDemo from http://java.sun.com/docs/books/tutorial/uiswing/components/text.html and stripped it down to the one thing I have a question about. Given the code below, how do I implement the toolbar button to make selected text turn bold? I've been beating my head againt this one for a couple of days now and getting nowhere.
    Any help would be deeply appeciated.
    --gary
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*; //for layout managers and more
    import java.awt.event.*; //for action events
    public class TextSamplerDemo extends JPanel
    implements ActionListener {
    private String newline = "\n";
    protected static final String textFieldString = "JTextField";
    public TextSamplerDemo() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    JToolBar toolBar = buildToolbar();
    add(toolBar);
    //Create a text pane.
    JTextPane textPane = createTextPane();
    JScrollPane paneScrollPane = new JScrollPane(textPane);
    paneScrollPane.setVerticalScrollBarPolicy(
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    paneScrollPane.setPreferredSize(new Dimension(250, 155));
    paneScrollPane.setMinimumSize(new Dimension(10, 10));
    add(textPane);
    public void actionPerformed(ActionEvent e) {
    private JTextPane createTextPane() {
    String[] initString =
    { "This is an editable JTextPane, ",            //regular
    "another ", //italic
    "styled ", //bold
    "text ", //small
    "component, " + newline, //large
    "which supports embedded components..." + newline,//regular
    newline + "JTextPane is a subclass of JEditorPane that " + newline +
    "uses a StyledEditorKit and StyledDocument, and provides " + newline +
    "cover methods for interacting with those objects."
    String[] initStyles =
    { "regular", "italic", "bold", "small", "large",
    "regular", "regular"
    JTextPane textPane = new JTextPane();
    StyledDocument doc = textPane.getStyledDocument();
    addStylesToDocument(doc);
    try {
    for (int i=0; i < initString.length; i++) {
    doc.insertString(doc.getLength(), initString,
    doc.getStyle(initStyles[i]));
    } catch (BadLocationException ble) {
    System.err.println("Couldn't insert initial text into text pane.");
    return textPane;
    protected void addStylesToDocument(StyledDocument doc) {
    //Initialize some styles.
    Style def = StyleContext.getDefaultStyleContext().
    getStyle(StyleContext.DEFAULT_STYLE);
    Style regular = doc.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "SansSerif");
    Style s = doc.addStyle("italic", regular);
    StyleConstants.setItalic(s, true);
    s = doc.addStyle("bold", regular);
    StyleConstants.setBold(s, true);
    s = doc.addStyle("small", regular);
    StyleConstants.setFontSize(s, 10);
    s = doc.addStyle("large", regular);
    StyleConstants.setFontSize(s, 16);
    private JToolBar buildToolbar() {
    JToolBar toolBar = new JToolBar();
    toolBar.setRollover( true );
    toolBar.setFloatable( false );
    JButton boldButton = new JButton("Bold");
    boldButton.setToolTipText( "Set selected text to bold" );
    boldButton.addActionListener( new ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    // code here to make selected text bold
    toolBar.add( boldButton );
    return toolBar;
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    JFrame frame = new JFrame("TextSamplerDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create and set up the content pane.
    JComponent newContentPane = new TextSamplerDemo();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();

    try this, but im'not sure.
    StyleContext styleContext = StyleContext.getDefaultStyleContext();
    Style def = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
    Style bold = styledDocument.addStyle("bold", def);
    StyleConstants.setBold(bold, true);into the listener of your component insert this:
    int start = getSelectionStart();
    int len = getSelectionEnd() - start;
    styledDocument.setCharacterAttributes(start, len, bold, true);by gino

  • How can i import java.sql package for midlet development

    I am trying to write a midlet app using Wireless Toolkit 2.5.2. I would like to connect my application to JavaDB in embedded mode. But when I write "import java.sql.*;", I get an error "package java.sql does not exist
    ". I would like to know how can i include this package. please help.

    FBL wrote:
    Sorry to jump in, but isn't there limited jdbc using unconventional methods?
    [http://developers.sun.com/mobility/configurations/articles/cdc/jdbc/|http://developers.sun.com/mobility/configurations/articles/cdc/jdbc/]
    If so, I feel this may better answer the OPs question.
    -TresAbove article refers to CDC - it is useless in CLDC midlets

  • Cannot Import Java Classes

    I am trying to do the sample contact walkthrough in FLEX
    builder. For the Java Adapter.
    http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/js/html/wwhelp.htm?href=00000138 .html
    I cannot get any import statements to work for the java class
    files. I have tried this using the FDS as a J2EE application
    running in tomcat, I have tried with the standalone JRUN version of
    the FDS app.
    I have put the contact files everywhere I can think of, in
    the server classes folder, in the project, in the default web
    folder and nothing I try works. I have even setup the project to
    compile on the server and I get nothing. Everytime, I get errors.
    I did the tutorial from the JDJ magazine:
    http://java.sys-con.com/read/210991.htm
    I cant get that java connection to work either. Please
    someone help me.
    The flex code is below.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Script>
    <![CDATA[
    import mx.data.DataService;
    import mx.collections.ArrayCollection;
    import samples.contact.Contact;
    public var ds:DataService;
    [Bindable]
    public var contacts:ArrayCollection;
    //public var contact:Contact;
    ]]>
    </mx:Script>
    <mx:DataGrid id="dg" editable="true">
    <mx:columns>
    <mx:DataGridColumn dataField="contactId" headerText="Id"
    editable="false"/>
    <mx:DataGridColumn dataField="firstName"
    headerText="First Name"/>
    <mx:DataGridColumn dataField="lastName" headerText="Last
    Name"/>
    </mx:columns>
    </mx:DataGrid>
    </mx:Application>

    Ken, thank you for replying, I have had absolutly nothing but
    problems trying to get this 'simple' thing to work.
    Here is my code.
    In the remote-config.xml file, I have this code:
    <?xml version="1.0" encoding="UTF-8"?>
    <service id="remoting-service"
    class="flex.messaging.services.RemotingService"
    messageTypes="flex.messaging.messages.RemotingMessage">
    <adapters>
    <adapter-definition id="java-object"
    class="flex.messaging.services.remoting.adapters.JavaAdapter"
    default="true"/>
    </adapters>
    <default-channels>
    <channel ref="my-amf"/>
    </default-channels>
    <destination id="SimpleJava">
    <properties>
    <source>javaSamples.SimpleMath</source>
    </properties>
    </destination>
    </service>
    Here is my MXML file: (Called new.MXML)
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:RemoteObject id="math" destination="SimpleJava">
    <mx:method name="doMath" concurrency="last"
    result="fillTxt(event.result as int)"/>
    </mx:RemoteObject>
    <mx:Script>
    <![CDATA[
    import mx.rpc.events.ResultEvent
    private function fillTxt(b: int):void{
    txtResult.text = (String)
    //comment
    ]]>
    </mx:Script>
    <mx:Panel x="10" y="24" width="250" height="200"
    layout="absolute" title="Simple Math with Java">
    <mx:Label x="10" y="10" text="Input Number to
    Multiply:"/>
    <mx:TextInput x="10" y="36" id="txtNumber"
    maxChars="1"/>
    <mx:Label x="10" y="126" id="txtResult"/>
    <mx:Label x="10" y="100" text="Your Number will appear
    below:"/>
    <mx:Button x="10" y="66" label="Multiply by 2"
    click="math.doMath(txtNumber.text)"/>
    </mx:Panel>
    </mx:Application>
    Here is my SimpleJava.java file:
    package javaSamples;
    //import java.util.*;
    * @author jsanders
    public class SimpleMath {
    public int doMath(String a){
    int new_a = Integer.parseInt(a.trim());
    int b = new_a * 2;
    return b;
    //changesd
    Like I said I have had absolutly nothing but problems with
    this. Yesterday, I was getting send failures, So I did some
    reasearch found some folks who said that they had the same problem,
    and they had to hard code the app name into the services-config.xml
    file. The file used to have {context.root} in it, and that variable
    was set to /flex, now I hardcoded this line into the my-amf channel
    definition to get rid of the send failure error.
    <channel-definition id="my-amf"
    class="mx.messaging.channels.AMFChannel">
    <endpoint uri="
    http://{server.name}:{server.port}/flex/messagebroker/amf"
    class="flex.messaging.endpoints.AMFEndpoint"/>
    <properties>
    <polling-enabled>false</polling-enabled>
    </properties>
    </channel-definition>
    As you can see what should say:
    http://{server.name}:{server.port}/{context.root}
    Now says:
    http://{server.name}:{server.port}/flex.
    This was the only way I could get the send error to go away.
    Now I worry that I might have broken something else. Since I
    removed all references to {context.root} in that file.
    {context.root} is defined in the flex-config.xml file, like
    this:
    <context-root>/flex</context-root>
    I have tried it with or without the '/' in the value of the
    context.root variable.
    I have played with the remoting-config file, and I know that
    I am accessing the destination.
    I have played with the <source> option of the
    destination, and I know that I am finding the class and making a
    good connection.
    I am using the JRUN install of FDS on my box, and yesterday
    at the end of the day after getting the context.root situation
    sorted out, I got a different error something like major.minor
    versioning errors.
    So the Java guys here at work told me that the JRUN version
    packaged with FDS was 1.4, and I used 1.5 to compile my java class.
    So I recompiled this morning with the 1.4 sdk. Now I dont get that
    error about the major minor versioning anymore.
    Now I get nothing. I use firefox, and all the browser tells
    me is 'transferring data from localhost' Nothing else. It just sits
    there and does nothing.
    When I did the debug on it, I got into a loop on the
    UIComponent.as file in the callLaterDispatcher(event:Event)
    function.
    Any clues what might be causing this new hang up. Basically
    the machine just hangs. Is there a problem with the result from the
    Method I am calling in the MXML? Did I do something wrong with the
    Event as Int thing?
    Again any help would be appreciated.

  • Cannot import java.util.concurrent.locks ... WHY?

    Why is Xcode unable to find the java.util.concurrent.locks package. The class browser knows it exists. For example the entry for the ReentrantLock class looks like this in the browser class window:
    ReentrantLock (java.util.concurrent.locks)
    Xcode knows about other java.util packages such as java.util.ResourceBundle which I have been accessed successfully in other parts of my projecgt.
    Here is a source file and the resulting compiler error:
    The source file:
    // Foo.java
    import java.util.ResourceBundle;
    import java.util.concurrent.locks;
    public class Foo { }
    The compiler error:
    compile:
    Compiling 2 source files to /Users/Terry/Desktop/JAVA/PROJECTS/Logic/bin
    /Users/Terry/Desktop/JAVA/PROJECTS/Logic/src/Foo.java:3: cannot find symbol
    symbol : class locks
    location: package java.util.concurrent
    import java.util.concurrent.locks;
    ^
    1 error
    BUILD FAILED
    Help or hints would be greatly appreciated!

    Well the reason to your problem is very simple... java.util.concurrent.locks is a package... Not a class.
    if you want to import a specific class, the class should be written at the end like you did for import java.util.ResourceBundle; but if you want to import a whole package you need to add the little star at the end :
    import java.util.concurrent.locks.*;
    Or else, you only import the class you need :
    import java.util.concurrent.locks.ReentrantLock;

Maybe you are looking for

  • SQL Server 2008 Execute SQL Task parameter problem

    hi, guys i create a very simply package which only Execute SQL task, set the properties as: the testing table structure: create table t( idx int, cname varchar(60) Execute SQL Task setting: [genaral] ResultSet: None ConnectionType: Ado.net connection

  • Help with password encryption

    Hello I am trying to create a one way hash password encryption...here is what I have developed so far..... Login class (contains GUI) import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.awt.image.*; import

  • A previous web page I was viewing appeared unexpectedly for a second then displayed correct page.

    true story. while teaching guitar to a 14 yr old student, I opened up safari to find lyrics for a song for us to learn. typed in the name. Clicked and Looked at the first link on results page. Went back to results page. clicked on second link. played

  • Deployment (Ejb and third party jars with portal app)

    My problem is that I'm trying to set up the development env for a portal project. I have an ejb and a third party jar in my portal app. My portlets have some java classes associated with them. The ejb needs to reference(instantiate) the java classes

  • Sync i tunes library

    I have several Macs (iMac, 2 MacBook Pros).  What is the best way to 'sync' my itunes libraries between the 3 machines?  Thanks for the ideas...