Why is IllegalStateException thrown in this Java Code Snippet ?

This is one of the questions in a mock test.
void waitForSignal()
    Object obj=new Object();
    synchronized(Thread.currentThread())
           obj.wait();
           obj.notify();
Which statement is true ?
A. This code may throw and InterruptedException
B. ThHis code may throw and IllegalStateEXception
C. This code may throw and TimeOuException after 10  minutes
D. This code will not compile unless "obj.wait()" is replaced with "((Tread)obj)
     .wait()"
E. Reversing the order of obj.wait() and obj.notify() may cause this method    to         complete normally
Answer : BSo why won't the code throw interrupted exception and throws a illegal state exception.
Also,some pointer to thread's wait() and notify() would help greatly.
Thank you for your consideration.

You must have the lock on an object before you can call wait or notify. The code doesn't synchronize on obj.
Kaj

Similar Messages

  • What is wrong in this java code?

    Can someone please tell me what is wrong in this java code?
    /* The program is intended to start animating text at the click of a button, pause it at another click and resume at the next click. It should continue like this */
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TextAnime implements Runnable
    JFrame frame;
    boolean flag;
    Thread animeThread;
    JLabel label;
    String[] textArray;
    public TextAnime()
    flag = false;
    animeThread = new Thread(this);
    frame = new JFrame("Animate Text");
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    frame.setLayout(gbl);
    JButton button = new JButton("Start");
    label = new JLabel("Stopped");
    textArray = new String[5];
    String textArray1[] = {"Programmer", "SportsMan", "Genius", "Friend", "Knowledgable"};
    for(int ctr = 0; ctr<5 ; ctr++)
    textArray[ctr] = textArray1[ctr];
    gbc.weightx = 1;
    gbc.gridx = 0;
    gbl.setConstraints(button,gbc);
    frame.getContentPane().add(button);
    ButList bl = new ButList();
    button.addActionListener(bl);
    gbc.gridx = 1;
    gbl.setConstraints(label,gbc);
    frame.getContentPane().add(label);
    frame.setSize(200,150);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setVisible(true);
    public class ButList implements ActionListener
    public void actionPerformed(ActionEvent evt)
    if(flag == false)
    flag = true;
    animeStart();
    else
    flag = false;
    //animeStop();
    public synchronized void animeStart()
    animeThread.start();
    Thread newThread;
    newThread = Thread.currentThread();
    newThread.notify();
    public void animeStop()
    animeThread.interrupt();
    public void run()
    int i = 0;
    try
    while(i == i)
    if(i==5)
    i=0;
    label.setText(textArray);
    animeThread.sleep(1000);
    i++;
    if (flag == false)
    animeThread.wait();
    catch(InterruptedException ie)
    label.setText("Stopped");
    public static void main(String args[])
    TextAnime ta = new TextAnime();
    Please tell me if this can be written in a more simpler manner. Also please correct this code. I am tired after trying many times.

    When I fix your error, compile and run it, I get this exception:
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalMonitorStateException
         at java.lang.Object.notify(Native Method)
         at cruft.TextAnime.animeStart(TextAnime.java:81)
         at cruft.TextAnime$ButList.actionPerformed(TextAnime.java:63)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
         at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
         at java.awt.Component.processMouseEvent(Component.java:6038)
         at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
         at java.awt.Component.processEvent(Component.java:5803)
         at java.awt.Container.processEvent(Container.java:2058)
         at java.awt.Component.dispatchEventImpl(Component.java:4410)
         at java.awt.Container.dispatchEventImpl(Container.java:2116)
         at java.awt.Component.dispatchEvent(Component.java:4240)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
         at java.awt.Container.dispatchEventImpl(Container.java:2102)
         at java.awt.Window.dispatchEventImpl(Window.java:2429)
         at java.awt.Component.dispatchEvent(Component.java:4240)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
         at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    %

  • URGENT : Need java code snippet to retrieve uniquemember values OID 11g API

    Hi All,
    We have a requirement to retrieve the uniquemember attribute values using OID 11g API. We are using labeleduri approach for dynamic groups and thus all the uniquemember values are created using dynamic groups.
    When we are trying to retrieve the uniquemember values using Java code snippet, it is not returning the values. The strange thing is: The uniquemember values created using dynamic groups are not visible in ODSM OID console or JExplorer tool. However those values are visible in LDAP Browser v2.8.1 tool.
    So can somebody throw light on this? Any pointers or sample code snippet to retrieve uniquemember values would be grateful.
    Thanks
    Mahendra.

    Hi All,
    We have a requirement to retrieve the uniquemember attribute values using OID 11g API. We are using labeleduri approach for dynamic groups and thus all the uniquemember values are created using dynamic groups.
    When we are trying to retrieve the uniquemember values using Java code snippet, it is not returning the values. The strange thing is: The uniquemember values created using dynamic groups are not visible in ODSM OID console or JExplorer tool. However those values are visible in LDAP Browser v2.8.1 tool.
    So can somebody throw light on this? Any pointers or sample code snippet to retrieve uniquemember values would be grateful.
    Thanks
    Mahendra.

  • Who can help me write this Java code show the prime number ???? PLEASEEEEEE

    Write java code print prime number like this
    Sample Screen Print:
    Initial matrix with N = 37
    2 3 4 5 6 7 8 9 10
    11 12 13 14 15 16 17 18 19 20
    21 22 23 24 25 26 27 28 29 30
    31 32 33 34 35 36 37
    Intermediate results (after 1st iteration)
    2 3 5 7 9
    11 13 15 17 19
    21 23 25 27 29
    31 33 35 37
    Intermediate results (after 2nd iteration)
    2 3 5 7
    11 13 17 19
    23 25 29
    31 35 37
    Intermediate results (after 7th iteration)
    2 3 5 7
    11 13 17 19
    23 29
    31 37
    Final results
    2 3 5 7 11 13 17 19 23 29
    31 37
    How to write this code ?
    Please Help me!
    Thank you so muchhh ?????

    h2. {color:#ff0000}Multiplepost{color}
    Replies here: http://forum.java.sun.com/thread.jspa?threadID=5241012&tstart=0
    There is a useful answer the original thread. Answer it, or ignore it as you like, but don't create multiple threads.

  • What is this Java-code doing?

    I tried to find out what this part of a JAVA code is doing.
    I think that there are the two Strings 'target' and 'phrase'
    declared and initialized, however, what is the value of each
    of these two Strings then respectively what is the return value??
    Here youe see the code:
    1:....
    2: private String O00OoO0O0oOoo00O00oo(String target, String phrase)
    3: {
    4: for(; target.length() > phrase.length(); phrase += phrase);
    5: String s1 = "";
    6: for(int i = 0; i < target.length(); i++)
    7: s1 = s1 + "" + (char)((phrase.charAt(i) + target.charAt 8: (i)) - i);
    9:
    10: return s1;
    11: }
    thx for help!

    I wrote the following program :
    public static void{
    1: private String abcdefghabcdefgh(String target, String phrase)
    2: {  
    3: for(; target.length() > phrase.length(); phrase += phrase);
    4: String a = "";
    5: for(int i = 0; i < target.length(); i++)
    6: a = a + "" + (char)(target.charAt(i) - phrase.charAt(i) - i);
    7: System.out.println(a);
    8: return a;
    9: }
    10: String pass="xxxx";
    11: String ssap="oooo";
    12: String test = "";
    13: test = abcdefghabcdefgh(pass, ssap);
    14: System.out.println(test);
    15:}
    But I always got an error when I tried to compile it...
    and i tried to find out for hours a de5cription for this function...
    Actually I found the de5cription for String(String original) in the
    API documentation, and I think this is what I wrote in line 1...
    I tried so much versions so that this function would work...
    but it didn't at all. (Actually I think that I importet all the java classes
    I need). What the hell are I'm doing Wrong???!!!

  • Why does this java code doesn't work on my pc?

    for example:
    package one;
    public class Alpha {
    //member variables
    private int privateVariable = 1;
    int packageVariable = 2; //default access
    protected int protectedVariable = 3;
    public int publicVariable = 4;
    //methods
    private void privateMethod() {
    System.out.format("privateMethod called%n");
    void packageMethod() { //default access
    System.out.format("packageMethod called%n");
    protected void protectedMethod() {
    System.out.format("protectedMethod called%n");
    public void publicMethod() {
    System.out.format("publicMethod called%n");
    public static void main(String[] args) {
    Alpha a = new Alpha();
    a.privateMethod(); //legal
    a.packageMethod(); //legal
    a.protectedMethod(); //legal
    a.publicMethod(); //legal
    System.out.format("privateVariable: %2d%n",
    a.privateVariable); //legal
    System.out.format("packageVariable: %2d%n",
    a.packageVariable); //legal
    System.out.format("protectedVariable: %2d%n",
    a.protectedVariable); //legal
    System.out.format("publicVariable: %2d%n",
    a.publicVariable); //legal
    As you can see, Alpha can refer to all its member variables and all its methods, as shown by the Class column in the preceding table. The output from this program is:
    privateMethod called
    packageMethod called
    protectedMethod called
    publicMethod called
    privateVariable: 1
    packageVariable: 2
    protectVariable: 3
    publicVariable: 4
    when above example runs on my pc:
    it works below description:
    D:\javacode>javac Alpha.java
    D:\javacode>java Alpha
    Exception in thread "main" java.lang.NoClassDefFoundError: Alpha (wrong name: on
    e/Alpha)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    why it runs wrongly and who can help me?
    thanks

    if i runs it below:
    D:\javacode>javac one\Alpha.java
    D:\javacode>java one.Alpha
    privateMethod called
    protectedMethod called
    protectedMethod called
    privateVariable: 1
    packageVariable: 2
    protectedVariable: 3
    publicVariable: 4
    it runs well!

  • Please help me whit this java code

    Hi!
    I have a litle problem whit this question:
    I try to write a program about Salary. The user writes(puts in from keyboard)
    the workers name, hourePayment and hour(how many hours He has worked).
    The program must compute first week ,second week....fourth week
    The user writes just one time name and hourPayment,
    but he must write hours(total hours he has worked)
    for every week(may be ha has worked 30 hours first week and 40 hours second week.....).
    when the user puts in zero the program stops(while(hour!=0)).
    I wrote the program but I have problem whit
    Test class when the program computes first ,second and...weeks, and if the user don not put in zero the program must compute another persons salary
    we should give new name new houre payement....
    how do I use the same information for second person and computes his salary.
    class Salary{
    private String name;
    private double hourPayment;
    public Salary (String name, double hourPayment, ..){
    this.name= name;
    this.hourPayment=hourPayment;
    public String getNamn(){
    return name;}
    public double getHourPayment(){
    return hourPayment;
    public double compute(int time){
    if(time<=40){
    normalSalary =(hourPayment*time);}
    else if(time>40){
    ....=(((40*hourPayment)+(time-40)*(3/2)*hourPayment));
    else if(timmar>70){
    System.out.println("WARRNING:"+" "+"You have worked more than 30

    The code you wrote only computes one week's salary. You need to wrap that inside loops that collect names, rates and hours. Here's some pseudocode to get you started:
    get name
    while name NOT ""
        get rate
        for i = 1 to 4
            get hours worked
            compute pay // this is the part you've coded
        next i
        get name
    end while

  • How to understand this java code?

    for example:
    * The HelloWorldApp class implements an application that
    * simply displays "Hello World!" to the standard output.
    class HelloWorldApp {
    public static void main(String[] args) {
    System.out.println("Hello World!"); //Display the string.
    the explaination of above example is below:
    above example
    The method signature for the main method contains three modifiers:
    public indicates that the main method can be invoked by any object. Controlling Access to Members of a Class covers the ins and outs of the access modifiers supported by the Java programming language.
    static indicates that the main method is a class method (as opposed to an instance method). Understanding Instance and Class Members talks about class methods and variables.
    void indicates that the main method doesn't return any value.
    in that statement :
    void indicates that the main method doesn't return any value.
    while (System.out.println("Hello World!"); //Display the string.) is in
    main method
    when we run that example and it runs below result:
    Hello World!
    so i think "Hello World" is that the main method return value.
    i know i have misunderstood.
    who can help me?

    What the hell are you on about?
    System.out is a PrintStream. When you call print() or println() the parameter is displayed in/on whatever that PrintStream is associated with. If you have java 1.5 you can run the below code and see that the output will be in the file out.txt. Not in the console and definately not returned.
    import java.io.*;
    class OutTest {
      public static void main(String[] args) {
        File file = new File("out.txt");
        PrintStream ps = null;
        try {
          ps = new PrintStream(file);
        } catch(FileNotFoundException fnfe) {
          fnfe.printStackTrace();
        System.setOut(ps);
        System.out.println("Hello World");
    }

  • Why do I keep getting this error code..."some of the purchased items on the iphone could not be transferred to your itunes library because you are not authorized for them on this computer" I have tried everything in trouble shoot, nothing changes.

    I have a iphone 3GS 16 GB that is currently working on version 4.3.5. I'm having major battery issues and need to take it in for repairs but can't because I can't get the system to back up all my information first. Every time I try to sync or back up or update my apps it gives me that error message in the title. I have unauthorized, and reauthorized the computer. I have changed to another, completely new computer which was also authorized. i have been using the same account since I first got the phone, and never backed it up on any computer before.
    IF I can make the back up work, will it also save my existing text messages and entries in the notes app? I'm about to go to the android system because from all the errors and issues that I am seeing listed in here and on other forums, seems like Apple has been neglecting their products a lot.

    @ deggie, I wasn't threatening ANYONE. I was simply saying how frustrating this has become, seeing how I have been trying on my own to figure this issue out for more then a month with no results. Like I said in the beginning, I have not used any other account to purchase apps or other products on my phone. I have only ever used one account. There are 23 apps that are saying they can't sync. It directs me to authorize the computer, which I do but it doesn't change the outcome. If I proceed, I lose those 23 apps correct? Do I also lose all my text messages saved, and other things such as documents in the "notes"?

  • How to write this java code in jsp using jstl  tags?

    Can anybody help me on this?
    I dont know how to check the containsKey using jstl tags?
    <%
         LinkedHashMap yearMap     =     (LinkedHashMap)request.getAttribute("yearMap");
         TreeSet nocSet               =     (TreeSet)request.getAttribute("nocSet");
         Iterator     yearMapIt     =     yearMap.keySet().iterator();
         while(yearMapIt.hasNext())
              int yearValue               =     (Integer)yearMapIt.next();
    %>
    <tr>
              <td><%=yearValue%></td>
    <%
              LinkedHashMap monthMap     =     (LinkedHashMap)yearMap.get(yearValue);
              Iterator     nocSetIt     =     nocSet.iterator();
              while(nocSetIt.hasNext())
                   String nCase=(String)nocSetIt.next();
                   if(monthMap.containsKey(nCase))
                        String count     =     (String)monthMap.get(nCase);
    %>
                        <td> <%= count %> </td>
    <%            }
                   else
    %>          
                        <td> 0 </td>     
    <%          
    %>
    </tr>
    <% } %>Edited by: avn_venki on Feb 18, 2008 11:54 PM

    <c:forEach var="yearMap" items="${requestScope.yearMap}">
         <th> <c:out value="${yearMap.key}"/> </th>
    <bean:define id="monthMap" value="${yearMap.value}"/>
    <c:forEach var="nocSet" items="${nocSet}">
    then how to write containsKey using tags??

  • Facing syntax error in this simple code snippet

    select case
    when to_number (to_char(sysdate,'mm')) < 7
    then (to_number(to_char(sysdate,'yyyy')) - 1)
    from dual
    --while if in block works fine
    declare
    year number;
    begin
    year := to_number(to_char(sysdate,'yyyy'));
    if (to_number(to_char(sysdate,'mm')) < 7) then
    year := year - 1;
    end if;
    dbms_output.put_line('year = '|| year);
    end;

    You can have:
    -- 1 case expression
    -- 1.2 searched case expressions
    -- 2 simple case statement
    -- 2.1 searched case statement
    In your case you need the first one(-- 1 case expression ), because you return an expression.
    Indeed a simple case statement let you choose a sequence of PL/SQL statements to execute. This follows another syntax.
    It's not always true this statements
    In PL/SQL you would use "END CASE". For this reason I can quietly show you that I can even use 'case expression' in PL/SQL, without end case:
    DECLARE
        subtype TTempWord is varchar2(20);         -- good notation :-)
        valToCompare constant tTempWord:='test';
        temp  tTempWord ;  
        temp2 tTempWord ;
        --- start locals-------     ;-)
        procedure Compare_Display  -- with no parameters just for this dummy test!
        is
        begin
          dbms_output.put_line('Word to compare:'||valToCompare); 
          dbms_output.put_line('temp:'||temp);
          dbms_output.put_line('temp2:'||nvl(temp2,'not assigned'));
          temp2:= case temp when valToCompare then 'identic ' else 'NOT identic' end ; -- I'm  not using *'END CASE'*
          dbms_output.put_line('    --- after the assignation --->');
          dbms_output.put_line('temp:'||temp);
          dbms_output.put_line('temp2:'||temp2);        
          dbms_output.new_line;dbms_output.new_line;
        end;
        --- end locals-------     ;-)
    BEGIN
          temp:='testttt'; 
          Compare_Display ;
          temp:=valToCompare;
          temp2:='';
          Compare_Display ;
    END;--output
    Word to compare:test
    temp:testttt
    temp2:not assigned
        --- after the assignation --->
    temp:testttt
    temp2:NOT identic
    Word to compare:test
    temp:test
    temp2:not assigned
        --- after the assignation --->
    temp:test
    temp2:identic
    PS:for more explanations related to all the cases you could look for at http://tahiti.oracle.com/
    Edited by: zep111 on Apr 28, 2011 11:25 AM

  • How to turn this Java into something I can use in CF?

    Hi - Following on from a recent post about how to strip our special characters from a string before insertion to the db I have found this Java code - my question is, how can I turn this into something I can use with CF? I think I need to use the cfscipt tag but that's right on the boundaries of my knowledge base.. If anyone could please help I'd be ever so grateful - thank you!
    package net.htmlescape;
    * HtmlEscape in Java, which is compatible with utf-8
    * @author Ulrich Jensen, http://www.htmlescape.net
    * Feel free to get inspired, use or steal this code and use it in your
    * own projects.
    * License:
    * You have the right to use this code in your own project or publish it
    * on your own website.
    * If you are going to use this code, please include the author lines.
    * Use this code at your own risk. The author does not warrent or assume any
    * legal liability or responsibility for the accuracy, completeness or usefullness of
    * this program code.
    public class HtmlEscape {
      private static char[] hex={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
       * Method for html escaping a String, for use in a textarea
       * @param original The String to escape
       * @return The escaped String
      public static String escapeTextArea(String original)
        return escapeSpecial(escapeTags(original));    
       * Normal escape function, for Html escaping Strings
       * @param original The original String
       * @return The escape String
      public static String escape(String original)
        return escapeSpecial(escapeBr(escapeTags(original)));
      public static String escapeTags(String original)
        if(original==null) return "";
        StringBuffer out=new StringBuffer("");
        char[] chars=original.toCharArray();
        for(int i=0;i<chars.length;i++)
          boolean found=true;
          switch(chars[i])
            case 60:out.append("&lt;"); break; //<
            case 62:out.append("&gt;"); break; //>
            case 34:out.append("&quot;"); break; //"
            default:found=false;break;
          if(!found) out.append(chars[i]);
        return out.toString();
      public static String escapeBr(String original)
        if(original==null) return "";
        StringBuffer out=new StringBuffer("");
        char[] chars=original.toCharArray();
        for(int i=0;i<chars.length;i++)
          boolean found=true;
          switch(chars[i])
            case '\n': out.append("<br/>"); break; //newline
            case '\r': break;
            default:found=false;break;
          if(!found) out.append(chars[i]);
        return out.toString();
      public static String escapeSpecial(String original)
        if(original==null) return "";
        StringBuffer out=new StringBuffer("");
        char[] chars=original.toCharArray();
        for(int i=0;i<chars.length;i++)
            boolean found=true;
          switch(chars[i]) {
            case 38:out.append("&amp;"); break; //&
            case 198:out.append("&AElig;"); break; //Æ
            case 193:out.append("&Aacute;"); break; //Á
            case 194:out.append("&Acirc;"); break; //Â
            case 192:out.append("&Agrave;"); break; //À
            case 197:out.append("&Aring;"); break; //Å
            case 195:out.append("&Atilde;"); break; //Ã
            case 196:out.append("&Auml;"); break; //Ä
            case 199:out.append("&Ccedil;"); break; //Ç
            case 208:out.append("&ETH;"); break; //Ð
            case 201:out.append("&Eacute;"); break; //É
            case 202:out.append("&Ecirc;"); break; //Ê
            case 200:out.append("&Egrave;"); break; //È
            case 203:out.append("&Euml;"); break; //Ë
            case 205:out.append("&Iacute;"); break; //Í
            case 206:out.append("&Icirc;"); break; //Î
            case 204:out.append("&Igrave;"); break; //Ì
            case 207:out.append("&Iuml;"); break; //Ï
            case 209:out.append("&Ntilde;"); break; //Ñ
            case 211:out.append("&Oacute;"); break; //Ó
            case 212:out.append("&Ocirc;"); break; //Ô
            case 210:out.append("&Ograve;"); break; //Ò
            case 216:out.append("&Oslash;"); break; //Ø
            case 213:out.append("&Otilde;"); break; //Õ
            case 214:out.append("&Ouml;"); break; //Ö
            case 222:out.append("&THORN;"); break; //Þ
            case 218:out.append("&Uacute;"); break; //Ú
            case 219:out.append("&Ucirc;"); break; //Û
            case 217:out.append("&Ugrave;"); break; //Ù
            case 220:out.append("&Uuml;"); break; //Ü
            case 221:out.append("&Yacute;"); break; //Ý
            case 225:out.append("&aacute;"); break; //á
            case 226:out.append("&acirc;"); break; //â
            case 230:out.append("&aelig;"); break; //æ
            case 224:out.append("&agrave;"); break; //à
            case 229:out.append("&aring;"); break; //å
            case 227:out.append("&atilde;"); break; //ã
            case 228:out.append("&auml;"); break; //ä
            case 231:out.append("&ccedil;"); break; //ç
            case 233:out.append("&eacute;"); break; //é
            case 234:out.append("&ecirc;"); break; //ê
            case 232:out.append("&egrave;"); break; //è
            case 240:out.append("&eth;"); break; //ð
            case 235:out.append("&euml;"); break; //ë
            case 237:out.append("&iacute;"); break; //í
            case 238:out.append("&icirc;"); break; //î
            case 236:out.append("&igrave;"); break; //ì
            case 239:out.append("&iuml;"); break; //ï
            case 241:out.append("&ntilde;"); break; //ñ
            case 243:out.append("&oacute;"); break; //ó
            case 244:out.append("&ocirc;"); break; //ô
            case 242:out.append("&ograve;"); break; //ò
            case 248:out.append("&oslash;"); break; //ø
            case 245:out.append("&otilde;"); break; //õ
            case 246:out.append("&ouml;"); break; //ö
            case 223:out.append("&szlig;"); break; //ß
            case 254:out.append("&thorn;"); break; //þ
            case 250:out.append("&uacute;"); break; //ú
            case 251:out.append("&ucirc;"); break; //û
            case 249:out.append("&ugrave;"); break; //ù
            case 252:out.append("&uuml;"); break; //ü
            case 253:out.append("&yacute;"); break; //ý
            case 255:out.append("&yuml;"); break; //ÿ
            case 162:out.append("&cent;"); break; //¢
            default:
              found=false;
              break;
          if(!found)
            if(chars[i]>127) {
              char c=chars[i];
              int a4=c%16;
              c=(char) (c/16);
              int a3=c%16;
              c=(char) (c/16);
              int a2=c%16;
              c=(char) (c/16);
              int a1=c%16;
              out.append("&#x"+hex[a1]+hex[a2]+hex[a3]+hex[a4]+";");    
            else
              out.append(chars[i]);
        return out.toString();

    hi Dan, thanks for asking
    I did this in the end..
    <cfscript>
      // function cleantext(string) {
      //   string = "<p>" & string;
      //   string = Replace(string, chr(13) & chr(10) & chr(13) & chr(10), "</p><p>", "all");
      //   string = Replace(string, chr(13) & chr(10), "<br />", "all");
      //   string = string & "</p>";
      //   return string;
    * HtmlEscape in Java, which is compatible with utf-8
    * @author Ulrich Jensen, http://www.htmlescape.net
    * Feel free to get inspired, use or steal this code and use it in your
    * own projects.
    * License:
    * You have the right to use this code in your own project or publish it
    * on your own website.
    * If you are going to use this code, please include the author lines.
    * Use this code at your own risk. The author does not warrent or assume any
    * legal liability or responsibility for the accuracy, completeness or usefullness of
    * this program code.
    function cleantext(string)  {
      private static char[] hex={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
       * Method for html escaping a String, for use in a textarea
       * @param original The String to escape
       * @return The escaped String
      public static String escapeTextArea(String original)
        return escapeSpecial(escapeTags(original));   
       * Normal escape function, for Html escaping Strings
       * @param original The original String
       * @return The escape String
      public static String escape(String original)
        return escapeSpecial(escapeBr(escapeTags(original)));
      public static String escapeTags(String original)
        if(original==null) return "";
        StringBuffer out=new StringBuffer("");
        char[] chars=original.toCharArray();
        for(int i=0;i<chars.length;i++)
          boolean found=true;
          switch(chars[i])
            case 60:out.append("&lt;"); break; //<
            case 62:out.append("&gt;"); break; //>
            case 34:out.append("&quot;"); break; //"
            default:found=false;break;
          if(!found) out.append(chars[i]);
        return out.toString();
      public static String escapeBr(String original)
        if(original==null) return "";
        StringBuffer out=new StringBuffer("");
        char[] chars=original.toCharArray();
        for(int i=0;i<chars.length;i++)
          boolean found=true;
          switch(chars[i])
            case '\n': out.append("<br/>"); break; //newline
            case '\r': break;
            default:found=false;break;
          if(!found) out.append(chars[i]);
        return out.toString();
      public static String escapeSpecial(String original)
        if(original==null) return "";
        StringBuffer out=new StringBuffer("");
        char[] chars=original.toCharArray();
        for(int i=0;i<chars.length;i++)
            boolean found=true;
          switch(chars[i]) {
            case 38:out.append("&amp;"); break; //&
            case 198:out.append("&AElig;"); break; //Æ
            case 193:out.append("&Aacute;"); break; //Á
            case 194:out.append("&Acirc;"); break; //Â
            case 192:out.append("&Agrave;"); break; //À
            case 197:out.append("&Aring;"); break; //Å
            case 195:out.append("&Atilde;"); break; //Ã
            case 196:out.append("&Auml;"); break; //Ä
            case 199:out.append("&Ccedil;"); break; //Ç
            case 208:out.append("&ETH;"); break; //Ð
            case 201:out.append("&Eacute;"); break; //É
            case 202:out.append("&Ecirc;"); break; //Ê
            case 200:out.append("&Egrave;"); break; //È
            case 203:out.append("&Euml;"); break; //Ë
            case 205:out.append("&Iacute;"); break; //Í
            case 206:out.append("&Icirc;"); break; //Î
            case 204:out.append("&Igrave;"); break; //Ì
            case 207:out.append("&Iuml;"); break; //Ï
            case 209:out.append("&Ntilde;"); break; //Ñ
            case 211:out.append("&Oacute;"); break; //Ó
            case 212:out.append("&Ocirc;"); break; //Ô
            case 210:out.append("&Ograve;"); break; //Ò
            case 216:out.append("&Oslash;"); break; //Ø
            case 213:out.append("&Otilde;"); break; //Õ
            case 214:out.append("&Ouml;"); break; //Ö
            case 222:out.append("&THORN;"); break; //Þ
            case 218:out.append("&Uacute;"); break; //Ú
            case 219:out.append("&Ucirc;"); break; //Û
            case 217:out.append("&Ugrave;"); break; //Ù
            case 220:out.append("&Uuml;"); break; //Ü
            case 221:out.append("&Yacute;"); break; //Ý
            case 225:out.append("&aacute;"); break; //á
            case 226:out.append("&acirc;"); break; //â
            case 230:out.append("&aelig;"); break; //æ
            case 224:out.append("&agrave;"); break; //à
            case 229:out.append("&aring;"); break; //å
            case 227:out.append("&atilde;"); break; //ã
            case 228:out.append("&auml;"); break; //ä
            case 231:out.append("&ccedil;"); break; //ç
            case 233:out.append("&eacute;"); break; //é
            case 234:out.append("&ecirc;"); break; //ê
            case 232:out.append("&egrave;"); break; //è
            case 240:out.append("&eth;"); break; //ð
            case 235:out.append("&euml;"); break; //ë
            case 237:out.append("&iacute;"); break; //í
            case 238:out.append("&icirc;"); break; //î
            case 236:out.append("&igrave;"); break; //ì
            case 239:out.append("&iuml;"); break; //ï
            case 241:out.append("&ntilde;"); break; //ñ
            case 243:out.append("&oacute;"); break; //ó
            case 244:out.append("&ocirc;"); break; //ô
            case 242:out.append("&ograve;"); break; //ò
            case 248:out.append("&oslash;"); break; //ø
            case 245:out.append("&otilde;"); break; //õ
            case 246:out.append("&ouml;"); break; //ö
            case 223:out.append("&szlig;"); break; //ß
            case 254:out.append("&thorn;"); break; //þ
            case 250:out.append("&uacute;"); break; //ú
            case 251:out.append("&ucirc;"); break; //û
            case 249:out.append("&ugrave;"); break; //ù
            case 252:out.append("&uuml;"); break; //ü
            case 253:out.append("&yacute;"); break; //ý
            case 255:out.append("&yuml;"); break; //ÿ
            case 162:out.append("&cent;"); break; //¢
            default:
              found=false;
              break;
          if(!found)
            if(chars[i]>127) {
              char c=chars[i];
              int a4=c%16;
              c=(char) (c/16);
              int a3=c%16;
              c=(char) (c/16);
              int a2=c%16;
              c=(char) (c/16);
              int a1=c%16;
              out.append("&#x"+hex[a1]+hex[a2]+hex[a3]+hex[a4]+";");   
            else
              out.append(chars[i]);
        return out.toString();
    </cfscript>  
    <cfset cleanedtext = cleantext(dirtytext)>
    Although actually I also ended up changing my charset of my tables to utf8 (it was latin_swedish) and that seems to have solved the head issue (with special characters (bullet points i think it was) throwing an error when inserting them in the db)

  • Calling a javascript function from java code and getting tha value in Java

    Hi,
    I would like to call a Java script function confirmRemove() from Java code upon meeting a condition..
    for example the code snippet is:
    if(true){
    // I want to call js confirmRemove() over here. And get the value of variable "answer" in this if block.
    <html>
    <head>
    <script type="text/javascript">
    function confirmRemove() {
         var answer = confirm("Are you sure you want to Delete?")
    </script>
    </head>
    <body>
    <form>...

    Hi,
    Back in 2003 I have used an Applet which contain java code and this java code was calling the java scripts ( different methods, DHTML etc..)
    There was a component developed by NetScape called JSObject I am not sure it there is other third party component other then the JSObject
    look at this article which shows how (based on JSObject)
    [http://java.sun.com/products/plugin/1.3/docs/jsobject.html|http://java.sun.com/products/plugin/1.3/docs/jsobject.html]
    Regards,
    Alan Meio
    London,UK

  • Export java code out of database?  difference between Prod and Test

    Hi all,
    I'm a seasoned DBA, but I have never really dealt with Java, so this is all new to me. Within one of my test databases (10.2.0.3.0), I have a database package - within the package is a procedure that has this Java call:
    language java name 'com.clinapps.pmd.etl.interfaces.forecasting.itemtrial.helper.SSFItemOutboundPMDHelper.processSSFItemInterface()';
    This Java code goes and exports a file to .xml format. The basic problem is that in our Test environment, there is a problem in the xml file that gets generated - the second line is missing the first few characters. However, in all of our other environments, including Production and Validation, it all works fine - the xml file is good. What has me confused, is that we've done several database refreshes, where we export from production, then import it down to test. So from everything I'm looking at, the schema is exactly the same - but something is different, causing the issue in the xml file that is being generated. I was wondering if I could get into the database and export the Java code, then that is something where I could confirm if there's a difference or not, from Prod to Test.
    Does anyone have any input/feedback on how to do this? I've been googling, and tried several methods, including dbms_metadata.get_ddl, and DBMS_JAVA.EXPORT_SOURCE, but I can't get anything to work.
    Or if anyone has any other thoughts on how to debug/troubleshoot this, I'd appreciate any ideas!!
    Thank you from a Java newbie!!

    OK, that is helping me get somewhere!! If I change the query to this, I am getting results:
    select obj_num,long_name from SYS."KU$_JAVA_CLASS_VIEW" where LONG_NAME like '%SSFItemOutboundPMDHelper%';
    171879
    com/clinapps/pmd/etl/interfaces/forecasting/itemtrial/helper/SSFItemOutboundPMDHelper
    Note that it has the / instead of the . as the differentiator
    Now if I do the second query, I see this:
    SQL> select * from SYS."KU$_JAVA_OBJNUM_VIEW" where OBJ_NUM=171879;
    OBJ_NUM DATAOBJ_NUM OWNER_NUM OWNER_NAME
    NAME NAMESPACE SUBNAME
    TYPE_NUM TYPE_NAME CTIME MTIME
    STIME STATUS REMOTEOWNER
    LINKNAME
    FLAGS OID SPARE1 SPARE2 SPARE3
    SPARE4
    SPARE5
    SPARE6
    171879 123 PMD50
    /34bae3f1_SSFItemOutboundPMDHe 1
    29 JAVA_CLASS 2012-06-28 10:44:22 2012-06-28 10:44:22
    2012-06-28 10:44:22 1
    8 6 65535
    Any thoughts on where to go from here??

  • Request for java code

    can any one tell me how to execute unix command in windows platform using java code? (please also send code or related websitename)

    when you have that feature OOTB in OIM, why you want it to write java code for that.,??

Maybe you are looking for

  • Null value in parameter form.

    In parameter form I want to leave blank option in order to print a report for all the values in the parameter form. I am writing the query for the parameter LOV that it fetches the values and making a union with 'select to_char(null) from dual. I am

  • I have bought and been using the 'Adobe Creative Suite 6 Design Standard'. How do i move this from one laptop, to another laptop?

    I have bought and been using the 'Adobe Creative Suite 6 Design Standard'. How do i move this from one laptop, to another laptop? I require this for uni, and am struggling to move it across! If you can help that would be great

  • Lion Server network accounts not working on some computers.

    Hello all - I'm currently having an issue with network accounts working on some Macs but not others. I have a Mac Mini and a MacBook Pro. The Mac Mini works fine and I can login and sync my network account with the server just fine. However, I cannot

  • Errore versione prova illustrator

    ciao ho installato illustrator cs6 prova, ma quando vado a salvare sul pc o in rete il file mi da il seguente errrore: Can not save the illustration, the file may be read-only or in use by another application, or you may not have the necessary permis

  • Modify a dblink

    Hi, on 8.1.7 There is a DBLINK in my DB (with connect ) for userA. When userB wants to use it he can not and receive ORA-02019). How make userB able to use it ? Or how to modify DBLINK so that userB can use it ? Thanks.