back programming now...
its been 2 weeks...
here's what i got today..
characters and string
try this code
import javax.swing.*;
public class W09Chars {
public static void main(String[] args) {
char ch = 'Z';
byte b = 65;
JOptionPane.showMessageDialog(null, "ASCII code of character " + ch +
" is " + (int)ch);
JOptionPane.showMessageDialog(null, "Character with ASCII code " + b +
" is " + (char)b);
JOptionPane.showMessageDialog(null, ch + " is "
+ ((ch > b) ? "bigger" : "smaller")
+ " than " + (char)b);
}
}
highlight
((ch > b) ? "bigger" : "smaller")
same as
if(ch > b)
"bigger";
else
"smaller"
each character has a code in hexadecimal, which will be shown if the code is ran
back to topic,
character is a single digit while string is array consists of characters
comparing strings
case a : reffering to the same object
String word1 = "Surabaya"
String word2 = word1
both variable reffers to the same object, so
word1 == word2 is true
word1.equals(word2) is true
case b : reffering to different but identical object
String word1 = "Surabaya"
String word2 = new String("Surabaya")
which make
word1 == word2 is false, bacause the address is not the same
word1.equals(word2) is true, because the value is identical
case c : diferent value, different object
pattern matching
sometimes its needed to use a pattern
example 17-08-1945
the regular expression is:
[0-3][0-9]-[0-1][0-9]-[0-9]{4}
string buffer
needed because string is immutable or unchangable
any modification will produce new string
which will use more and more memory
thats all..
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment