Concerning String Handling

Hello To Every One,
I have a query concerning String Handling.
String s3 = "Java is a wonderful language";
    System.out.println("s3 is: "+s3);
    System.out.println("lastIndexOf(a, 23) = " + s3.lastIndexOf('a', 23));
    System.out.println("********");
String s4= "Java is a wonderful language";
    System.out.println("s4: "+s4);
    System.out.println("lastIndexOf(a, 19) = " + s4.lastIndexOf('a', 19));Output is:
s3 is: Java is a wonderful language
lastIndexOf(a,23)=21
s4 is: Java is a wonderful language
lastIndexOf(a,19)=8what is basic difference in s3.lastIndexOf('a', 23)); and
s4.lastIndexOf('a', 19));
that output is lastIndexOf(a,23)=21 and
lastIndexOf(a,19)=8
Please clarify..
Thanks.

Even without reading the API you should be work out what it is doing
- by reading the source code for the method.
- debugging it with a debugger.
- inferring what it does from its name.
But reading the API is the most obvious, that what the documentation is for.

Similar Messages

  • Doubt in String handling...

    Hi
    Here i have a code snippet.
    public class StringComp
         public static void main(String[] args)
              String a = "abc";
              String b = "def";
              String c = "abcdef";
              String d = "xyz";
              String e = "xyz";
              a+=b;
              System.out.println("Value of a = :" + a);
              System.out.println("Value of c = :" + c);
              System.out.println("Value of d = :" + d);
              System.out.println("Value of e = :" + e);
              if(a==c)
                   System.out.println("TRUE");
              else
                   System.out.println("FALSE");
              if(e==d)
                   System.out.println("TRUE");
              else
                   System.out.println("FALSE");
    if i compile and run this code snippet i am getting the result as
    Value of a = :abcdef
    Value of c = :abcdef
    Value of d = :xyz
    Value of e = :xyz
    FALSE
    TRUE
    here i add the value of a and b to a. so a=abcdef, value of c also abcdef.
    but if i check (a==c) the result is False why??
    Can anyone tell me how the string is handled in java (behind the scene) where they are stored ? and how the == operator works on String?
    thanks in advance
    chithrakumar

    Strings are pooled. This means that if you writeString a = "1";
    String b = "1";you have a good chance that a == b.
    For new Strings (as "abc" + "def" returns), the pool is bypassed. This explains why "abc + "def" != "abcdef". To make sure a String is pooled, use intern (). ("abc" + "def").intern () == "abcdef", guaranteed.
    This is all very opaque behaviour and you shouldn't really rely on this in your code, except in very rare circumstances (extreme performance concerns or if you're stuck with an identity hash map [not that that's very likely]).

  • Anybody have some unicode string handling code I could use?

    Text handling plugins are not working for some users, since Lua and Lr are not on the same page char-representation-wise.
    For example, if you enter
    À
    in Lightroom, it's getting interpreted as
    À
    in Lua.
    in non-plugin environment, one could just use slnunicode, however in plugin one needs pure lua solution.
    Anybody?
    ref: http://lua-users.org/wiki/LuaUnicode
    R

    Try
    Debug.pause( "uni-find", string.find( photo:getFormattedMetadata( 'title' ), 'À' ) )
    when title field has an 'À' in it.
    Instead of seeing the coordinates of the 'À' that is there, you'll see nil.
    PS - this code looks promising (?) found at http://forums.gaspowered.com/viewtopic.php?f=19&t=29879
       function conv2utf8(unicode_list)
          local result = ''
          local w,x,y,z = 0,0,0,0
          local function modulo(a, b)
             return a - math.floor(a/b) * b
          end
          for i,v in ipairs(unicode_list) do
             if v ~= 0 and v ~= nil then
                if v <= 0x7F then -- same as ASCII
                   result = result .. string.char(v)
                elseif v >= 0x80 and v <= 0x7FF then -- 2 bytes
                   y = (v & 0x0007C0) >> 6
                   z = v & 0x00003F
                   y = math.floor(modulo(v, 0x000800) / 64)
                   z = modulo(v, 0x000040)
                   result = result .. string.char(0xC0 + y, 0x80 + z)
                elseif (v >= 0x800 and v <= 0xD7FF) or (v >= 0xE000 and v <= 0xFFFF) then -- 3 bytes
                   x = (v & 0x00F000) >> 12
                   y = (v & 0x000FC0) >> 6
                   z = v & 0x00003F
                   x = math.floor(modulo(v, 0x010000) / 4096)
                   y = math.floor(modulo(v, 0x001000) / 64)
                   z = modulo(v, 0x000040)
                   result = result .. string.char(0xE0 + x, 0x80 + y, 0x80 + z)
                elseif (v >= 0x10000 and v <= 0x10FFFF) then -- 4 bytes
                   w = (v & 0x1C0000) >> 18
                   x = (v & 0x03F000) >> 12
                   y = (v & 0x000FC0) >> 6
                   z = v & 0x00003F
                   w = math.floor(modulo(v, 0x200000) / 262144)
                   x = math.floor(modulo(v, 0x040000) / 4096)
                   y = math.floor(modulo(v, 0x001000) / 64)
                   z = modulo(v, 0x000040)
                   result = result .. string.char(0xF0 + w, 0x80 + x, 0x80 + y, 0x80 + z)
                end
             end
          end
          return result
       end
    or maybe this: (?)
    function unichr(ord)
        if ord == nil then return nil end
        if ord < 32 then return string.format('\\x%02x', ord) end
        if ord < 126 then return string.char(ord) end
        if ord < 65539 then return string.format("\\u%04x", ord) end
        if ord < 1114111 then return string.format("\\u%08x", ord) end
    end
    from http://stackoverflow.com/questions/7780179/what-is-the-way-to-represent-a-unichar-in-lua
    R

  • Regular Expressions and string handling

    I'd like to be able to make a method that takes a String and removes certain substrings from that string. What I'm doing is that I'm getting some text from the internet (an HTML doc) and I'd like to remove all the tags from it.
    my method is:
         String DeTokenString(String s)
    String t=new String(s.replaceAll("<regex>",""));
              return t;
    What would I put in place of <regex> to remove all html tags? s has already had its leading and following whitespace removed elsewhere with .trim() before being passed to DeTokenString.
    Is there any other simple way to accomplish this?

    It does on whatever manages to get through my 17
    firewall, hand-woven packet destroyers, and
    titanium-lead armor.So! That is your final defense mechanism. Bwah hah hah hah hah! Now I have you. That was all I needed to improve my 17-firewall-sneaking-through, hand-woven-packet-destroyer-unweaving, titanium-lead-armor-piercing virus!
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • JTextArea methods + String Handling

    Hi There,
    My Question was, that i have made a small text editor application, and i was hoping that some one could tell me how to add the text, which is opened in a JTextArea to a Vector (or another data structure if this is more appropriate), which i can then parse using Regular expressions??
    Also, could u point me in the direction of a resource that has examples of how to use regular expressions in java 1.4 (util.regex)?
    Thanks in advance,
    much appreciated!

    I'd use getText() and put the text in a String, like the previous poster said. From there you can parse the string using the Pattern and Matcher objects.
    Here's a link that has some examples of regular expressions:
    http://developer.java.sun.com/developer/technicalArticles/releases/1.4regex/

  • Output String Handling in Java

    Hi, guys...............
    How can I format my output I have a long text formula which consist of alot of "()","{ }" "[ ]" and some other special char. I want to see in a readable format. This output formula is approximately you can say 1 or 2 pages but there is no any space or a break line e.g. [sdsadadfdfsdffwesdfsdfsdf{sdsdddsd^afasdfadfsdfasdfasdfasdf(asdfaf(asfasdfbvdcbyrey)eyydfhghghshgfghfg)fghfghfg}hfg]hfg$sdfsdfsdfsdg[fsdgdfhd{[dsfassd{sdfsgsggdfbergdfvgg}dfgdfgdfgdfg]gdfgdfgdfgdfgdg(hfghfghsdfhgasdfasdffdghdfhbdfgd^sdfgasdfgdfgdfgdfbsd|dfsdggdfgdfhdgh)dfhdfh}dfhdfhvnbvbnmghmjyky] and so on.....upto more than 1 page. so how can I control my string. which is readable for me.
    kind regards
    for replying
    merry

    Do you actually want to read a couple of pages of text without white space?
    If the bracket things nest you could output them like code (with the content nested):
       sdsetc {
          asadddetc
          ^
          asasdsetc
       hfg
    ]It's never going to be easy to read, however.

  • RealServer plugin bad string-handling

    Having had trouble with the RealServer plugin for a couple of days we have finally got it to work on Oracle 9i database and Realserver 8.
    In rmserver.cfg, we had a list with a <Var Database> tag that contained many lines, with newlines, tabs and spaces.
    <List Name="Oracle DB system select">
    <Var Database="
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = SULE22)(PORT = 1521))
    (CONNECT_DATA =
    (SID=tennis.idi.ntnu.no)
    "/>
    </List>
    This didn't work, however, when we changed it to be on one line as in:
    <List Name="Oracle DB RealVideo movie">
    <Var Database="(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=sule22.idi.ntnu.no)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=dipvideo.idi.ntnu.no)(INSTANCE_NAME=dipvideo)))"/>
    </List>
    it worked.
    We don't know if it was the newlines (Windows/UNIX encoding), the Tab-characters or the spaces that triggers this difficult-to-find bug, but we suspect one of the first.

    Hmmmm, probably a problem with the parsing of an XML document by realserver. A plugin gets the values from a realServer api, not by parsing XML. Normally newlines in an XML attribute are normalized to whitespace by an XML parser.

  • BSP string handling

    Hi,
    I'm currently in the process of modifying some ITS Templates for our ESS Open Enrollment application. Based on who is logging in, I must either prompt them for a screen to allow employees to reset their passwords or proceed to reset their passwords automatically.
    To differenciate these two groups, I'm comparing the login ID (~login) against a temporary ID that begins with ID followed by 6 digits (i.e. ID400088). I have the following command:
    `if (~login=="ID400088")`
    `else`
    `end`
    So, what I would like to do is to have an IF statement that would work for all IDs. In ABAP, it would be something like this:
    `if (~login+0(2)=="ID")`
    `else`
    `end`
    Can you please provide some assistance or suggestions?
    Thanks,
    Paul (new to BSP)

    Yes, you can use substrings in IF statements in ABAP.
    if login+0(2) = 'ID'.
    * Do Something.
    endif.
    or are you trying to do this directly in the BSP code.
    Regards,
    Rich Heilman

  • Extracting string from a file name

    Hello,
    I have a legacy (read: I didn't build it) SharePoint list  that includes some validation when uploading files that's giving me some trouble.
    Basically, our users are required to add files to a list in a certain filename format and based on the naming convention are approved/rejected and routed to the appropriate location.
    One of the validations looks at a section of the file name and compares it to a folder name in the library.
    For example, the file name format is XX_AAA_999_2014_05.xlsx and that matches on the folder name of /submissions/2014_05
    Currently the rule says look at the last 7 characters of the folder and the 7 characters starting at position 12 of the filename and make sure they match.
    The problem is the 999 in the example above is a sequential identifier to the project a file is associated with... e.g. they range from project 000 to project 999. We've now hit project 1000 so file being added for project 1000 (and beyond) fails because
    the starting position has shifted one spot. (Note: we have active 3 digit projects so I cannot simply change that to be position 13... not to mention what that does to my history).
    So, my task is to come up with something that can accomodate 3 or 4 digit numbers.
    I'm trying to stick as closely to the original setup so I don't mess up the history so I'm looking at other methods of getting to the same data in the string.  Another problem is that the file names include the extension and the extension can be 3 (pdf)
    or 4 (xlsx) characters long.
    I've tried this:  =LEFT([Source File Name],SEARCH(".",[Source File Name])-1)
    but that brings back everything in front of the period and I need just the 7 preceeding characters.  Is there a way to limit the number of chars a LEFT() function returns?
    In a nutshell, the 4 variations of file names are as follows of which I need to extract the
    bolded section.:
    ZZ_AAA_999_2014_05.xls
    ZZ_AAA_999_2014_05.xlsx
    ZZ_AAA_1000_2014_05.xls
    ZZ_AAA_1000_2014_05.xlsx
    Thanks!
    Kevin

    Hi,
    According to your description, you might want to retrieve the string “2014_05” from the file name.
    I would suggest you create a SharePoint Designer workflow and implement your logic of handling the filename.
    In SharePoint Designer 2010, there are already some useful utility workflow actions which can enable users to deal with the various requirements come from the business scenarios.
    For the string handling, you can consider to use the
    Utility Actions:
    http://msdn.microsoft.com/en-us/library/office/jj164026(v=office.15).aspx
    Another two links about creating SharePoint Designer workflow for your reference:
    http://office.microsoft.com/en-001/sharepoint-designer-help/introduction-to-designing-and-customizing-workflows-HA101859249.aspx
    http://www.codeproject.com/Tips/415107/Create-a-Workflow-using-SharePoint-Designer
    Thanks
    Patrick Liang
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Patrick Liang
    TechNet Community Support

  • "Using a CIN to Create an Array of Strings in LabVIEW" example crashes LV on Linux

    Tried to utilize this NI example: "Using a CIN to Create an Array of Strings in LabVIEW" (http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B4B282BE7EF907C8E034080020E74861&p_node=&p_source=External)
    Compiles OK with the makefile made by the LV's lvmkmf utility. Nevertheless when I try to run the VI (with the code loaded into the CIN, of course), LabVIEW 7.1.1 on a SUSE 9.3 Linux machine crashes:
    LabVIEW caught fatal signal
    7.1.1 - Received SIGSEGV
    Reason: address not mapped to object
    Attempt to reference address: 0x0
    Segmentation fault
    Any ideas? Did anybody try this on a Windows machine?

    H View Labs wrote:
    Tried to utilize this NI example: "Using a CIN to Create an Array of Strings in LabVIEW" (http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B4B282BE7EF907C8E034080020E74861&p_node=&p_source=External)
    Compiles OK with the makefile made by the LV's lvmkmf utility. Nevertheless when I try to run the VI (with the code loaded into the CIN, of course), LabVIEW 7.1.1 on a SUSE 9.3 Linux machine crashes:
    LabVIEW caught fatal signal
    7.1.1 - Received SIGSEGV
    Reason: address not mapped to object
    Attempt to reference address: 0x0
    Segmentation fault
    Any ideas? Did anybody try this on a Windows machine?
    This code is badly broken. In addition to resizing the actual handle to hold the number of string handles you also would need to create the string handles itself before attempting to write into them. NumericArrayResize is the fucntion to use as it will either resize an existing handle (if any) or create a new one if the value is uninitialized (NULL).
    /* resize strarr to hold handles to NUMSTRINGS strings */
    err = SetCINArraySize((UHandle)strarr, 0, NUMSTRINGS);
    if (err)
    goto out;
    /* perform this loop once for each element */
    /* of array of strings being created */
    for (i = 0; i < NUMSTRINGS;) {
    LStrHandle handle = (*strarr)->arg1[i];
    /* determine length of string that will be element of strarr */
    strsize = StrLen(str[i]);
    err = NumericArrayResize(uB, 1, &handle, strsize);
    if (err)
    goto out;
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    /* moves strsize bytes from the address pointed to */
    /* by str[i] to the address pointed to by the data pointer in the handle */
    MoveBlock(str[i], LStrBuf(*handle), strsize);
    /* manually set size of string pointed to by *strarr */
    (*((*strarr)->arg1[i]))->cnt = strsize;
    /* manually set dimSize of strarr */
    (*strarr)->dimSize = ++i;
    return noErr;
    out:
    return err;
    Rolf KalbermatterMessage Edited by rolfk on 06-30-2005 03:15 AM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Regarding Exception handling in Coherence

    Hi ,
    I am using c++ to connecting coherence
    try{
    String::Handle gridHandleCache = GridCacheName;
    if(hCommCache == NULL) {
    hCommCache = CacheFactory::getCache(gridHandleCache);
    else {
    //cout<<"Info :"<<GridCacheName<<" Cache Already in Active State " <<endl;
    catch(Exception::Handle vex) {
    cout<<" coherence exe" ;
    catch(std::exception e) {
    cout<<e.what();
    catch(...) {
    cout <<"unknown exception" ;
    When the error occurred (either runtime or other errors) i am always getting unname exception . it never enter into the Exception::Handle vex part.
    when it will invoke catch(Exception::Handle vex) {. I want to separate runtime and connection error ecpetion sepeartyely.
    May i know what would be the cause / or how to handle it seperately .
    What are the errors are possible for connect / put/get/invoke(touchprocessor) . serializable cast ?
    -Thanks
    Edited by: 882600 on Aug 31, 2011 5:51 AM

    Hi,
    Still i have one issue
    if i use RuntimeException::view or illegalArgumentException::view
    catch(RuntimeException::view vex)
    here i want to print string error message like
    vseterror("%s",vex.getDescription() ) ; instead of cout<<vex
    Is there any solution to print the error from view obj like e.what() char * / string type message ?
    Is thie poisble to classify Confiuration error / Fatal error exceptions ?
    Edited by: 882600 on Sep 6, 2011 12:57 PM
    Edited by: 882600 on Sep 6, 2011 1:25 PM

  • Any way to use Delphi strings?

    I know that LabView can, when calling external libraries, use Pascal string pointers. However, those are limited, is there a way to call an external library using a Delphi string?
    FYI: a Pascal string uses one byte for it's length, a Delphi string uses 4 bytes. Since I'm using Delphi for implementing the DLL, using Delphi strings would be way more straightforward than using C strings.
    Solved!
    Go to Solution.

    Kirillenseer wrote:
    Thank you, I'll try to go with the handle method, pointer to a Delphi string reference. Still funny that LV string and Delphi string are the exact same beasts, yet can't interoperate seamlessly.
    They are not the same! They look the same in terms of the actual byte layout in memory, but the memory management is entirely different. The LabVIEW String is a LabVIEW Handle, an internal memory object managed by the LabVIEW memory manager functions and using a pointer to a pointer to the actual information. Any modification to the string that requires to change its size MUST be performed by calling the according memory manager functions, or a crash is immediately evident.
    The Pascal String is a memory area managed by the Delphi runtime library (and maybe, possibly, but likely not documented be implemented under Windows on top of the SysString datatype.) and repreents just a pointer to the data.
    If you want to pass in a string to a DLL function that is passed in by reference (VAR keyword) you can get away with configuring it as a  LabVIEW String handle. But if the string is passed into the function by value (just the String itself) this won't work at all. And if the function is supposed to return information in the string you can't do it without either a wrapper or some pointer magic implemented in the diagram. This is because if you configure it as a LabVIEW Handle, LabVIEW expects it to be allocated by its memory manager functions, but Delphi will do it with its Delphi runtime functions and as soon as LabVIEW attempts to free that string, it will crash, since the memory loacation is not allocated from the heap managed by the LabVIEW memory manager.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How to remove the "int len" of my return string on the DLLS header when building a DLL on LabVIEW 8.5

    Hi all.
    I'm building a DLL on LabVIEW and I choose a string as an output on the terminals connectors.
    But LabVIEW creates another output, the lenght of the return string.
    This is a problem because I have other DLLs and I need them to be compatible.
    How do I remove this length from the header? What is the difference between Pascal String and C string and String Handle Pointer?
    String Handle Pointer removes the length from the header but I don't know the difference between this data types.
    Thanks in advance for the help.
    Daniel Coelho
    Portugal
    Daniel Coelho
    VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
    Controlar - Electronica Industrial e Sistemas, Lda

    Daniel Coelho wrote:
    Hi all.
    I'm building a DLL on LabVIEW and I choose a string as an output on the terminals connectors.
    But LabVIEW creates another output, the lenght of the return string.
    This is a problem because I have other DLLs and I need them to be compatible.
    How do I remove this length from the header? What is the difference between Pascal String and C string and String Handle Pointer?
    String Handle Pointer removes the length from the header but I don't know the difference between this data types.
    Thanks in advance for the help.
    Daniel Coelho
    Portugal
    C string pointer is a pointer to a memory location whose string information is terminated by a 0 byte. Pascal String Pointer is a pointer to a memory location where the first byte specifies the number of bytes to follow. This obviously allows only for strings up to 255 character length.
    LabVIEW String Handle is a pointer to a pointer to a memory location where the first 4 bytes are an int32 value indicating the number of characters to follow. You can read such a String handle in a function without many problems, but you can only create, resize and delete such a handle by using LabVIEW memory manager functions. So this makes only sense if the caller of such a DLL is LabVIEW too as another caller would have to go through several hoops and tricks in order to gain access to the correct LabVIEW kernel that could provide the memory manager functions to deal with such handles.
    Last but not least output strings whose allocated length is not passed to the funciton as additional parameter are a huge secerity risk (talk about buffer overrun errors). LabVIEW DLL Builder does not support the creation of DLLs with output string (or array parameters)  without the explicit passing of an additional parameter telling the DLL function how large the allocated size is (so that the DLL function can make sure to never write over the end of the buffer).
    The additional length parameter only disappears for String Handles because LabVIEW will simply resize them to whatever length is necessary and that is also the reason why those handles need to be allocated by the same memory manager instance that is also going to execute the DLL function.
    Resizing of memory pointers is non-standardized and in normal circumstances not suited for passed function parameters at all.
    Rolf Kalbermatter
    Message Edited by rolfk on 06-13-2008 12:28 PM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How to prevent Automator's "run shell script" to create fully decomposed forms of my strings ?

    I am using Automator's "run shell script" and I am seeing that it outputs fully decomposed forms of my strings.
    For example, when I set the action to "echo été" in a service (with "Replace selected text" activated) and run that into a Textwrangler window, I'll get fully decomposed forms that Textwrangler won't understand. But when I simply type that command into Terminal, I get my string in composed form.
    The problem is not the display issue, but the fact that if I want to run grep for example in "run shell script", I will not be able to find the proper strings since the forms are different.

    Originally I was using $@ to parse a string and get the result pasted by the service. That was a while ago. There, I noticed that some Japanese characters were messed up. Basically all the kana characters that come with voicing markers like が-ga (instead of か-ka) etc. I did not have the time to pursue that issue though.
    Then, last night, I found that a colleague of mine had tried to use $@ to feed to a local dictionary application called ding (http://ftp.tu-chemnitz.de/pub/Local/urz/ding/). His problem was with characters that had umlauts. After verifying how he wrote his action I remembered that I had similar issues with Japanese.
    Basically his command was "/path/to/ding $@"
    That's supposed to use the selected string as an argument to pass to ding, which will launch a Wish application where the string is used as the searched item.
    From Terminal, that works a treat. But the exact same line in Automator (with input as argument, not as stdin) messed the composition and the resulting string was not recognized by ding as a match to what it was supposed to match.
    So, I tried a few things to get to the core of the issue and found that a simple "echo [accented characters]" was enough to reproduce the difference in string handling between Automator and Terminal. That difference is also reproduced on a number of person's machines.
    I have a number of services that basically revolve on "run shell script" actions and involve 3rd party application outputs, preference files etc. so it would not be convenient to show that to you.
    I have sent a mail about this issue to the automator list yesterday too:
    http://lists.apple.com/archives/Automator-users/2011/Jun/msg00004.html

  • Reading each incoming string?

    How do I read each incoming string?
    import java.net.*;
    import java.io.*;
    public class Mystic_Client{
         public static void main(String [] args){
              Local l = new Local();
              l.Run_Server();
              l.Output();
              InputThread it = new InputThread();
              it.start();
    class Local{
         static boolean Alive = true;
         static Socket server;
         static BufferedReader input;
         static PrintWriter socket_out;
         public void Run_Server(){
              try{
                   server = new Socket("127.0.0.1",27700);
                   System.out.println("Connection Opened");
              }catch(Exception e){
                   System.out.println(e);
                   System.exit(0);
         public void Shutdown_Server(){
              try{
                   Alive = false;
                   InputThread it = new InputThread();
                   input.close();
                   socket_out.close();
                   it.socket_in.close();
                   server.close();
                   System.exit(0);
              }catch(Exception e){
                   System.exit(0);
         public void Output(){
              String handle;
              String input_message;
              try{
                   input = new BufferedReader(new InputStreamReader(System.in));
                   socket_out = new PrintWriter(server.getOutputStream(),true);
                   System.out.print("Handle - ");
                   handle = input.readLine();
                   for(;(input_message = input.readLine()) != null;){
                        if(input_message.equals("~disconnect")){
                             Shutdown_Server();
                        socket_out.println(handle + " <> " + input_message);
              }catch(Exception e){
                   System.out.println(e);
                   Shutdown_Server();
    class InputThread extends Thread{
         Local l = new Local();
         static BufferedReader socket_in;
         String socket_in_message;
         public void run(){
              try{
                   Socket server = l.server;
                   socket_in = new BufferedReader(new InputStreamReader(server.getInputStream()));
                   for(;l.Alive == true;){
              }catch(Exception e){
                   System.out.println(e);
                   l.Shutdown_Server();
    }In the public void run() it suppost to check for new incoming strings to display for my chat program. I started to try something with a for loop, but I'm just not sure yet.
    Please Help!
    Thanks!

    Shouldn't this work? It compiles, but it won't actually display incoming messages:
    import java.net.*;
    import java.io.*;
    public class Mystic_Client{
         public static void main(String [] args){
              Local l = new Local();
              l.Run_Server();
              l.Output();
              InputThread it = new InputThread();
              it.start();
    class Local{
         static boolean Alive = true;
         static Socket server;
         static BufferedReader input;
         static PrintWriter socket_out;
         public void Run_Server(){
              try{
                   server = new Socket("127.0.0.1",27700);
                   System.out.println("Connection Opened");
              }catch(Exception e){
                   System.out.println(e);
                   System.exit(0);
         public void Shutdown_Server(){
              try{
                   Alive = false;
                   InputThread it = new InputThread();
                   input.close();
                   socket_out.close();
                   it.socket_in.close();
                   server.close();
                   System.exit(0);
              }catch(Exception e){
                   System.exit(0);
         public void Output(){
              String handle;
              String input_message;
              try{
                   input = new BufferedReader(new InputStreamReader(System.in));
                   socket_out = new PrintWriter(server.getOutputStream(),true);
                   System.out.print("Handle - ");
                   handle = input.readLine();
                   for(;(input_message = input.readLine()) != null;){
                        if(input_message.equals("~disconnect")){
                             socket_out.println("~disconnect");
                             Shutdown_Server();
                        socket_out.println(handle + " <> " + input_message);
              }catch(Exception e){
                   System.out.println(e);
                   Shutdown_Server();
    class InputThread extends Thread{
         Local l = new Local();
         static BufferedReader socket_in;
         static String socket_in_message;
         public void run(){
              try{
                   Socket server = l.server;
                   socket_in = new BufferedReader(new InputStreamReader(server.getInputStream()));
                   for(;l.Alive == true;){
                        socket_in_message = socket_in.readLine();
                        System.out.println(socket_in_message);
              }catch(Exception e){
                   System.out.println(e);
                   l.Shutdown_Server();
    }

Maybe you are looking for