jshell
, a “read-eval-print-loop”, that you saw in the videos. If you have Java 9 installed, you execute it by running
path to JDK/bin/jshellWe'll do that eventually, but for today we'll use the online version. Type in
Integer.toBinaryString(5)and hit Enter. What do you get?
Integer.toHexString(60)Why? (Hint: A is 10, B is 11, C is 12.)
Integer.valueOf("101", 2)
lab2
. Make a new class HexViewer
. Remember—be sure it is in the default package. Clear out the Package: field. Then paste this code.
hello.txt
from the Downloads directory. What happens?0A
at the end?Hello, San José!In UTF-8, the é is encoded as two bytes. What are they? Use the HexViewer and the hello2.txt file to find out. Be careful to use this exact file. Or, if you make your own file, be sure to save in UTF-8. (While the vast majority of computing devices defaults to UTF-8 for file encoding, both Windows and Mac OS still cling to archaic coding system defaults.)
Hello, Java™!What is the UTF-8 encoding of the
™
symbol?Hello 😻What is the UTF-8 encoding of the
😻
symbol?cd Downloads
). Type
ls hello*.txtor, on Windows,
dir hello*.txtWhat do you get? Then type
ls *.javaor, on Windows,
dir *.javaWhat do you get?
HexViewer.java
, then keep going. If not, ask for help.HexViewer
from the command line. How do you do that?java HexViewer hello1.txtWhat happens?
hello2.txt
? (Hint: Hit the ↑ key)lab2
project. Compile and run, and type in the input Hello
. What happens?San José
to figure out what happens with the é. But how is that going to work? Even if you know how to type an é on your computer, how do you know what character encoding is used in your console? To have complete control over this, we'll again read from a file. (As Vladimir Lenin said, “Trust is good. Control is better.”)
cd
command to change to that directory. Run
javac StringPrinter.java java StringPrinter hello2.txtWhat happens? (If you get an error message, ask for help.)
"\uD83D\uDE3B"
? This page tells how to do it:
substring
. (You may not actually have twenty digits. Deal with that somehow.)int
. (See Step 1.)