# \[JAVA\] Unicode Characters and string copying/comparison

**URL:** <https://forum.kirupa.com/t/java-unicode-characters-and-string-copying-comparison/266379>\
**Category:** programming\
**Created:** [July 19, 2008, 3:00am UTC](https://forum.kirupa.com/t/java-unicode-characters-and-string-copying-comparison/266379 "2008-07-19T03:00:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SpyrL](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@SpyrL](https://forum.kirupa.com/u/SpyrL)\
**Post date:** [July 19, 2008, 3:00am UTC](https://forum.kirupa.com/t/java-unicode-characters-and-string-copying-comparison/266379/1 "2008-07-19T03:00:20Z")

</div>

Hey all,  
I normally do C++ but lately ive been learning some Java, due to my CIT/TAFE course doing Java next semester.  
Anyway so ive been on [COLOR=Blue]www.net-force.nl[/COLOR] doing some of the challenges they have over there, just to get to know Java better.  
**[SIZE=2]NOTE: The terms and conditions of doing the challenges state that NO-ONE is to give me the answer/password, or help me on the challenges.  
so please DO NOT give me the answer/password.  
[/SIZE]**  
Im not asking for help on the challenge, but just some Java stuff that is used in the challenge.

```auto

    public applet4()
    {
        SubmitButton = null;
        PasswordField = null;
        SubmitButton = null;
        PasswordField = null;
        SubmitButton = new Button();
        PasswordField = new TextField("", 8);
    }

    public void actionPerformed(ActionEvent actionevent)
    {
        String s = PasswordField.getText();
        String s1 = getDocumentBase().toString();
        char c = '\u01C0';
        int i = hash(s);
        s1 = s1.substring(0, s1.lastIndexOf('/') + 1);
        String s2;
        if(c == i)
            s2 = s1 + "index.php?pass=" + s;
        else
            s2 = s1 + "index.php?pass=kneus";
        try
        {
            getAppletContext().showDocument(new URL(s2), "_self");
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
    }

    private int hash(String s)
    {
        int i = 0;
        for(int j = 0; j < s.length(); j++)
            i += s.charAt(j);

        return i;
    }

```

ok so thats part of the code.

**Q1**  
The thing I would like to know is with this line of code:  
_PasswordField = new TextField("", 8);_  
then,  
_String s = PasswordField.getText();_

Say I put “cats” in the password field, when the field value is copied into _String s_ will _String s_ then equal [COLOR=Navy]“cats”[/COLOR] or will the rest of password field (8 characters long) be placed into it with other null characters or something? Like this [COLOR=Navy]“cats\0\0\0\0”[/COLOR][COLOR=Black]? :stare:[/COLOR]

**Q2**  
As you can also see a comparison is made between _char c_ and int _i_ (return of _hash(s)_)

```auto

if(c == i)
            s2 = s1 + "index.php?pass=" + s;

```

and as you can also see, _c = ‘\u01C0’;_  
So when the comparison is made “_if(c == i)_” will c be seen as ‘\u01C0’ or the latin character ‘ǀ’?  
And mainly, how the hell can you compare a character and an integer?!?!

Im not sure if im even doing this the right way, but as i quoted at the start, **no-one** is to help with the challenge, or give out the answer/password!  
But your welcome to sign up and do it yourself 😉 (just dont show me up too much =P)

I appreciate all the help you all always give me.  
Cheers.
