Howdy. 

Present today (so far): wang686 dgerman ssalmero hgarciah luo23 zeyang 
balbakr rthammon runxzhao mahazuga jnp2 ruifan yiwecao mzelenin serepate 
dweissma kevcao zhang486. Missing (so far): creba. 

Since yesterday we created silo accounts for you. 

Use PuTTY to log into silo. 

Commands you need to learn:

  clear

  pwd

  mkdir 

  ls 

  ls -l 

  https://kb.iu.edu/search?q=Unix+commands&s=15

  https://kb.iu.edu/d/afsk

Yesterday: 

  We study Java. 

  Java is an OOPL. 

  We used DrJava IDE to write and evaluate expressions. 

  In Java there are four primitive types:
  
    (a) whole numbers    (there are four types: byte short int long) 

    (b) numbers with decimals   (two categories: float and double)

    (c) booleans         (boolean) 

    (c) characters       (char) 

  Strings are sequences of characters between double quotes. 

  Strings are objects. 

  Objects have special syntax. 

Today: 
 
  I would like to reproduce that kind of knowledge on silo. 

  Read the book chapter 1 says: 

    (a) create file (source code, contains one class) 

    (c) compile it

    (d) run it

  Here's an example on silo: 

[luo23@silo ~]$ pwd
/u/luo23
[luo23@silo ~]$ ls
bin  cgi-pub  FROM  GROUP  LIMIT  README  WHERE
[luo23@silo ~]$ mkdir c212-6w2-sum2018
[luo23@silo ~]$ ls
bin  c212-6w2-sum2018  cgi-pub  FROM  GROUP  LIMIT  README  WHERE
[luo23@silo ~]$ cd c212-6w2-sum2018/
[luo23@silo c212-6w2-sum2018]$ pwd
/u/luo23/c212-6w2-sum2018
[luo23@silo c212-6w2-sum2018]$ ls -l
total 0
[luo23@silo c212-6w2-sum2018]$

  I created a folder for this class and moved there. 

[luo23@silo c212-6w2-sum2018]$ pwd
/u/luo23/c212-6w2-sum2018
[luo23@silo c212-6w2-sum2018]$ nano -w One.java
[luo23@silo c212-6w2-sum2018]$ ls -l
total 4
-rw------- 1 luo23 students 481 Jun 19 11:59 One.java
[luo23@silo c212-6w2-sum2018]$ cat One.java
public class One {
  public static void main(String[] args) {

   // write statements below:

   System.out.println( 12 /  7                     ); // 1
   System.out.println(  7 % 12                     ); // 7
   System.out.println( "what" + "ever"             ); // whatever
   System.out.println( 'a' + 0                     ); // 97
   System.out.println( 'a' + 'b'                   ); // 97 + 98
   System.out.println( "automaton".substring(2, 8) ); tomato

  }
}
[luo23@silo c212-6w2-sum2018]$ javac One.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
One.java:11: error: not a statement
   System.out.println( "automaton".substring(2, 8) ); tomato
                                                      ^
One.java:11: error: ';' expected
   System.out.println( "automaton".substring(2, 8) ); tomato
                                                            ^
2 errors
[luo23@silo c212-6w2-sum2018]$ nano -w One.java
[luo23@silo c212-6w2-sum2018]$ cat One.java
public class One {
  public static void main(String[] args) {

   // write statements below:

   System.out.println( 12 /  7                     ); // 1
   System.out.println(  7 % 12                     ); // 7
   System.out.println( "what" + "ever"             ); // whatever
   System.out.println( 'a' + 0                     ); // 97
   System.out.println( 'a' + 'b'                   ); // 97 + 98
   System.out.println( "automaton".substring(2, 8) ); // tomato

  }
}
[luo23@silo c212-6w2-sum2018]$ javac One.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
[luo23@silo c212-6w2-sum2018]$ ls -l
total 8
-rw------- 1 luo23 students 575 Jun 19 12:00 One.class
-rw------- 1 luo23 students 484 Jun 19 12:00 One.java
[luo23@silo c212-6w2-sum2018]$ file One.class
One.class: compiled Java class data, version 52.0 (Java 1.8)
[luo23@silo c212-6w2-sum2018]$ file One.java
One.java: C source, ASCII text
[luo23@silo c212-6w2-sum2018]$ java One
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
1
7
whatever
97
195
tomato
[luo23@silo c212-6w2-sum2018]$

So the basic idea is: 

  one creates files (with classes) 

  compiles them 

  and runs the class with the main 


Let's see this example from Lab 01. 


[luo23@silo c212-6w2-sum2018]$ ls -l
total 12
-rw------- 1 luo23 students 575 Jun 19 12:00 One.class
-rw------- 1 luo23 students 484 Jun 19 12:00 One.java
-rw------- 1 luo23 students 146 Jun 19 12:06 Two.java
[luo23@silo c212-6w2-sum2018]$ cat Two.java
public class Two {
  public static void main(String[] args) {

   // write statements below:

   System.out.println( true ); // true

  }
}
[luo23@silo c212-6w2-sum2018]$ javac Two.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
[luo23@silo c212-6w2-sum2018]$ java Two
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
true
[luo23@silo c212-6w2-sum2018]$

Booleans. 

A type is a set of values. 

boolean type is this set: {true, false}

Operations: not (!), and (&&), or (||). 


  a     b       !a       a && b     a || b 
-------------------------------------------------
  true  true    false    true       true 
  true  false            false      true 
  false true    true     false      true 
  false false            false      false 

Reminder: you can use parens, and !   works like unary minus
                                  &&  works like multiplication 
                                  ||  works like + 


In other words

   
  a || b && ! c


is the same as 


  (a || (b && (! c)))


Recall: 

  1 + 2 * -3 

is in fact -5

  (1 + (2 * (- 3))) 

Definitely not: 

  (1 + 2) * -3  

What about this: 

  1 + 2 * - 3 + 2

Is it the same as this: 

  (1 + 2) * (- (3 + 2))

[luo23@silo c212-6w2-sum2018]$ cat Two.java
public class Two {
  public static void main(String[] args) {

   // write statements below:

   System.out.println( true                  ); // true

   System.out.println( 1 + 2 * - 3 + 2       );

   System.out.println( (1 + 2) * (- (3 + 2)) );

  }
}
[luo23@silo c212-6w2-sum2018]$ javac Two.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
[luo23@silo c212-6w2-sum2018]$ java Two
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
true
-3
-15
[luo23@silo c212-6w2-sum2018]$

Exercise: can you please simplify these expressions

  a && true 

  a || true 

  a == false 

  a != false 

  a && false 

  a || false 

  (n > 20) || (n < 30)

  (n > 4) && (n < 4)

  (n > 4) || (n < 4) 

Assume a is a boolean variable. Like below:

public class Two {
  public static void main(String[] args) {

    boolean a, b; // declare two names to be placeholders for boolean values

    a = true;

    b = false;

    System.out.println( a || !b && !a ); // outcome: ...

  }
}

Assume n is an int variable, like below:

[luo23@silo c212-6w2-sum2018]$ nano -w Three.java
[luo23@silo c212-6w2-sum2018]$ clear
[luo23@silo c212-6w2-sum2018]$ ls -l
total 20
-rw------- 1 luo23 students 575 Jun 19 12:00 One.class
-rw------- 1 luo23 students 484 Jun 19 12:00 One.java
-rw------- 1 luo23 students 453 Jun 19 12:29 Three.java
-rw------- 1 luo23 students 491 Jun 19 12:24 Two.class
-rw------- 1 luo23 students 520 Jun 19 12:23 Two.java
[luo23@silo c212-6w2-sum2018]$ cat Three.java
public class Three {
  public static void main(String[] args) {

    int n, m; // declare two int variables

    n = 3; // put 3 in n

    m = 5; // now m has 5 inside

    n = n + m; // what happened?

    m = n - m; // what is m now?

    n = n - m; // is n the same as m at this point?

    System.out.println( n + m ); // prints the sum

    System.out.println( n ); // prints n: ...
    System.out.println( m ); // prints m: ...

  }
}
[luo23@silo c212-6w2-sum2018]$ javac Three.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
[luo23@silo c212-6w2-sum2018]$ ls -l
total 24
-rw------- 1 luo23 students 575 Jun 19 12:00 One.class
-rw------- 1 luo23 students 484 Jun 19 12:00 One.java
-rw------- 1 luo23 students 440 Jun 19 12:29 Three.class
-rw------- 1 luo23 students 453 Jun 19 12:29 Three.java
-rw------- 1 luo23 students 491 Jun 19 12:24 Two.class
-rw------- 1 luo23 students 520 Jun 19 12:23 Two.java
[luo23@silo c212-6w2-sum2018]$ java Three
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
8
5
3
[luo23@silo c212-6w2-sum2018]$

Simplify means find an equivalent shorter expression 

Equivalent means 

  having the same value 
  for the same combination of values 
  of the independent variable(s) in the expression. 

[luo23@silo c212-6w2-sum2018]$ cat Two.java
public class Two {
  public static void main(String[] args) {

    boolean a, b; // declare two names to be placeholders for boolean values

    a = true;

    b = false;

    System.out.println(  a    ||   !b      &&  !a       ); // outcome: ...
    //                   true ||   !false  &&  !true
    //                  (true || ((!false) && (!true)))
    //                  (true || ( true    &&  false ))
    //                  (true ||          false       )
    //                        true
  }
}
[luo23@silo c212-6w2-sum2018]$ javac Two.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
[luo23@silo c212-6w2-sum2018]$ java Two
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
true
[luo23@silo c212-6w2-sum2018]$

Now: simplify those expressions. 

Henri     and Jiaxeng :  a && true 

They say:                a

Yawen     and Zejun   :  a || true 

They say:                true 

Mary-Anne and Runxia  :  a == false 

They say:                !a

Ryan      and Jingyun :  a != false 

They say:                true 

Bakr      and Matthew :  a && false 

They say:                false 

Yiwei     and Rui     :  a || false 

They say:                a

Kevin     and Jay     :  (n > 20) || (n < 30)

They say:                true 

Andrew    and Serena  :  (n > 4) && (n < 4)

They say:                false 

Me        and Santiago:  (n > 4) || (n < 4) 

They say:                n != 4

Summary:

silo accounts with "problems":

-bash-4.2$ finger mahazuga
Login: mahazuga                         Name: Mary A Hazuga
Directory: /u/mahazuga                  Shell: /bin/bash
Last login Tue Jun 19 11:42 (EDT) on pts/122 from 156-56-142-202.dhcp-bl.indiana.edu
No mail.
No Plan.
-bash-4.2$ ls /u/mahazuga
ls: cannot access /u/mahazuga: No such file or directory
-bash-4.2$ finger runxzhao
Login: runxzhao                         Name: Runxia Zhao
Directory: /u/runxzhao                  Shell: /bin/bash
Never logged in.
No mail.
No Plan.
-bash-4.2$ ls /u/runxzhao
ls: cannot access /u/runxzhao: No such file or directory
-bash-4.2$ finger zeyang
Login: zeyang                           Name: Zejun Yang
Directory: /u/zeyang                    Shell: /bin/bash
Never logged in.
No mail.
No Plan.
-bash-4.2$ ls /u/zeyang
ls: cannot access /u/zeyang: No such file or directory

--