Howdy. 

Adrian German
dgerman@indiana.edu
IF2010 (Luddy Hall)

On your paper:

(1) Name, username, major, minor
(2) Reasons for taking this class
(3) Expectations
(4) What lab are you in? 
(5) Do you have a laptop? Is it a Mac or a Windows?
(6) Have you taken C211? C200? What did you take before class? 
(7) What's your background in programming? Favorite language? 
(8) What is Unix? What is HTML? How much do you like Math? 
(9) Do you have any fears/concerns? Any questions/comments?

http://www.cs.indiana.edu/classes/c212

http://silo.cs.indiana.edu:8346/cgi-bin/fall2018/schedule

In your Canvas there is a link to the external website. 

No class on labor Day (09/03). 

Automatic W Oct 21

I hope you buy the book look for the deal that's best for you. 

For emergency situations:

https://www.cs.indiana.edu/classes/c212-dgerman/fall2016/resources/rctmpx/toc.html

Read chapter 1 for Wednesday. 

Java is a programming language. 

It is object-oriented. 

Java programs are made of classes. 

public class One {

}

This is an empty class. 

It should be saved as One.java

Microsoft Windows [Version 10.0.16299.551]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\dgerman>cd Desktop

C:\Users\dgerman\Desktop>dir
 Volume in drive C is OSDisk
 Volume Serial Number is C6FD-7531

 Directory of C:\Users\dgerman\Desktop

08/20/2018  05:06 AM    <DIR>          .
08/20/2018  05:06 AM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  246,875,598,848 bytes free

C:\Users\dgerman\Desktop>dir
 Volume in drive C is OSDisk
 Volume Serial Number is C6FD-7531

 Directory of C:\Users\dgerman\Desktop

08/20/2018  03:06 PM    <DIR>          .
08/20/2018  03:06 PM    <DIR>          ..
08/20/2018  03:07 PM                23 One.java
               1 File(s)             23 bytes
               2 Dir(s)  246,875,303,936 bytes free

C:\Users\dgerman\Desktop>type One.java
public class One {

}
C:\Users\dgerman\Desktop>javac One.java
'javac' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\dgerman\Desktop>

So either the computer does not Java installed:

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Or the computer doesn't quite know about where Java is. 

Ours is in the second case:

C:\Users\dgerman\Desktop>"C:\Program Files\Java\jdk1.8.0_162\bin\javac.exe" One.java

C:\Users\dgerman\Desktop>dir
 Volume in drive C is OSDisk
 Volume Serial Number is C6FD-7531

 Directory of C:\Users\dgerman\Desktop

08/20/2018  03:14 PM    <DIR>          .
08/20/2018  03:14 PM    <DIR>          ..
08/20/2018  03:14 PM               180 One.class
08/20/2018  03:07 PM                23 One.java
               2 File(s)            203 bytes
               2 Dir(s)  246,885,056,512 bytes free

C:\Users\dgerman\Desktop>

Unfortunately the class you created can be compiled but won't run.

To run a class has to have a special method inside:

public class One {
  public static void main(String[] args) {
    System.out.println("How are you?"); 
  } 
}

Now I can compile and run this:

C:\Users\dgerman\Desktop>dir
 Volume in drive C is OSDisk
 Volume Serial Number is C6FD-7531

 Directory of C:\Users\dgerman\Desktop

08/20/2018  03:14 PM    <DIR>          .
08/20/2018  03:14 PM    <DIR>          ..
08/20/2018  03:14 PM               180 One.class
08/20/2018  03:18 PM               113 One.java
               2 File(s)            293 bytes
               2 Dir(s)  246,883,528,704 bytes free

C:\Users\dgerman\Desktop>"C:\Program Files\Java\jdk1.8.0_162\bin\java.exe" One
Error: Main method not found in class One, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

That was me trying to run the class I compiled earlier. 

That class didn't have a main so I compiled the new source code. 

C:\Users\dgerman\Desktop>"C:\Program Files\Java\jdk1.8.0_162\bin\javac.exe" One.java

C:\Users\dgerman\Desktop>"C:\Program Files\Java\jdk1.8.0_162\bin\java.exe" One
How are you?

C:\Users\dgerman\Desktop>

The newly compiled class works now. 

--

C:\Users\dgerman\Desktop>PATH="C:\Program Files\Java\jdk1.8.0_162\bin";%PATH%

C:\Users\dgerman\Desktop>javac One.java

C:\Users\dgerman\Desktop>java One
How are you?

C:\Users\dgerman\Desktop>

--

Fortunately there are also IDEs that we can use. 

http://www.drjava.org/

In Java we have numbers, strings, ... 

+ - ( ) / % * 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> 3
3
> 1 + 2
3
> 3 - 2
1
> 1 - 2 - 3
-4
> 1 - (2 - 3)
2
> ((1 - 2) - 3)
-4
> 3 / 2
1
> 5 / 7
0
> 5 % 7
5
> 12 % 5
2
> 2 / 3 * 3
0
> 3 * 2 / 3
2
> 3.0
3.0
> 3.141592
3.141592
> Math.PI
3.141592653589793
> 3.0 / 2
1.5
> 2.0 / 3 * 3
2.0


There are a number of primitive types in Java: 

(a) int, long, short, byte

(b) double, float

(c) char

(d) boolean 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> 4
4
> 4L
4
> 2.3
2.3
> 2.3F
2.3
> 4.53 * 100
453.0
> 4.35 * 100
434.99999999999994
> 0.1
0.1
> 0.1 + 0.1
0.2
> 0.1 + 0.1 + 0.1
0.30000000000000004
> 0.1 + 0.1 + 0.1 + 0.1
0.4
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.5
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.6
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.7
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.7999999999999999
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 
0.8999999999999999
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
0.9999999999999999
> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
1.0999999999999999


So we can use BigDecimal:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> BigDecimal a = new BigDecimal("4.35");
Static Error: Undefined class 'BigDecimal'
> import java.math.BigDecimal; // auto-import
BigDecimal a = new BigDecimal("4.35");
> a
4.35
> 4.35 * 100
434.99999999999994
> BigDecimal b = new BigDecimal("100");
> a
4.35
> b
100
> a.multiply(b)
435.00
> 4.35 * 100
434.99999999999994