Download AS/400 Java

Document related concepts
no text concepts found
Transcript
Java
▮ How the class works
▮ Java programming concepts
▮ Downloading the JDK
▮ Java coding and executing example
Chapter 1
© copyright Janson Industries 2014
1
PP Presentations
▮ Can be viewed online or downloaded
▮ Go to:
▮ web.fscj.edu/Janson/COP2551
▮ For all presentations and class files
Chapter 1
© copyright Janson Industries 2014
2
Or you can go to my school website
(web.fscj.edu/Janson) and click on this link
Chapter 1
© copyright Janson Industries 2014
3
This presentation is 4thed.Ch01.ppt
Click file name (link) to view online…
Chapter 1
© copyright Janson Industries 2014
4
Or choose Save as
Chapter 1
© copyright Janson Industries 2014
5
How Class Works
▮ Do the non-graded exercises first
▮ They will help you solve the graded assgs
▮ I can help you with these assgs/probs
▮ Keep track of the probs and solutions
▮ You will make the same mistakes many
times
▮ Graded assgs (the Tutorials in the
chapter and Challenge Exs) are for you
(and you alone) to complete
Chapter 1
© copyright Janson Industries 2014
6
How Class Works
▮ Tutorials (chapters 1-7) are 10% of your
grade
▮ Challenge Exercises (Review Exercises at
the end of chapters 1-7) are 20%
▮ Extra Credit (chapters 8-10 Tutorials) are
extra 5%
▮ Must do non-graded assgs to get
credit for graded assgs
Chapter 1
© copyright Janson Industries 2014
7
How Class Works
▮ Tests are composed of 50 multiple
choice questions
▮ To get an A you will have to do the
Review Exercises
▮ Strongly advise you to do all of them
▮ You can also do the end of chapter
challenge exercises
▮ If you can do all these you probably know
the material
Chapter 1
© copyright Janson Industries 2014
8
How Class Works
▮ If you come to a lecture, listen and take
notes
▮ You will not learn the material by listening
to the lecture and viewing the slides once
▮ You need to study/do the material covered
in the lecture and examples
▮ And doing an exercise correctly once doesn’t
necessarily mean you know it!
▮ This class assumes you all have WIN 7
Chapter 1
© copyright Janson Industries 2014
9
How Class Works
▮ You will need a thumb drive for the class
to store all your assgs
▮ Suggestion: create a file named ICE or
IFFOUND and put in some contact info
for yourself
▮ This may mean you will get it back when
you lose it ;-)
Chapter 1
© copyright Janson Industries 2014
10
Classroom Computers
▮ The anti-virus s/w does not play nicely
with RAD
▮ You need to sign on to the computers
using the following:
▮ User id
.\ibm
▮ PW
cop2551
Chapter 1
© copyright Janson Industries 2014
11
How Class Works
▀
▀
▀
How long has it been since you
took COP1000?
Code.org
Uses videos and games to get
across the basic programming
structures which you are already
expected to understand
♦
http://learn.code.org/hoc/1
12
Copyright 2014 by Janson Industries
You can skip the video and go
straight to the instructions
Once done with
instruction, close window
and try exercises
13
Copyright 2014 by Janson Industries
The first puzzle will start
14
Copyright 2014 by Janson Industries
When puzzle finished will
allow you to continue to the
next one or you can click to
skip ahead
There may be more
instructions, click
X's to close
15
Copyright 2014 by Janson Industries
Click Continue to go
to next puzzle
16
Copyright 2014 by Janson Industries
Click Continue to go
to next puzzle
17
Copyright 2014 by Janson Industries
If you can't figure it out, scroll
down and click the help links
18
Copyright 2014 by Janson Industries
How Class Works
▀
▀
There's an entire COP1000 set
of lessons at
http://learn.code.org/
19
Copyright 2014 by Janson Industries
Unplugged activites have the
theory – good to read first
Then tackle the puzzles
20
Copyright 2014 by Janson Industries
Java Concepts
▮ Java source code stored in files with an
extension of .java
▮ The source code is “compiled”, meaning:
▮ Translated into bytecode
▮ Bytecode stored in class files (files with an
extension of .class)
▮ Bytecode is a “cross-platform program
representation” that is non-executable
Chapter 1
© copyright Janson Industries 2014
21
Java Concepts
Cust.java
(Java file)
Cust.class
(Class file)
Java source
code
Editor
Compiler
Java source
code
Programmer
Chapter 1
Java
bytecode
javac Cust.java
Programmer
© copyright Janson Industries 2014
22
Java Concepts
▮ Review: files with an extension of .java
contain source code
▮ Review: files with an extension of .class
contain “bytecode”
▮ .java files are “compiled” (javac) to create
.class files
▮ Bytecode is a cross-platform program
representation that is non-executable
▮ New: bytecode needs to be translated to
machine language (java)
Chapter 1
© copyright Janson Industries 2014
23
Java Virtual Machine (JVM)
▮ JVM is “the place” (i.e. s/w) where the
.class files (i.e. programs) are translated
▮ The JVM is invoked with the java
command
▮ The JVM translates bytecode into
machine language and sends to CPU for
execution (i.e. program is run)
▮ Therefore, each "type" of computer
needs a unique JVM
Chapter 1
© copyright Janson Industries 2014
24
Java Concepts
Cust.java
(Java file)
Cust.class
(Class file)
Java source
code
Editor
Java source
code
Programmer
Chapter 1
CPU
Java
bytecode
Compiler
javac Cust.java
Programmer
© copyright Janson Industries 2014
JVM
main method
in Machine
Language
java Cust
Programmer
25
Java Virtual Machine (JVM)
▮ To run a java application on a computer
you must download a JVM/JRE (java
runtime environment)
▮ Oracle (and many other vendors) offer
▮ Oracle has a JDK (Java Development Kit)
that includes a JRE (and compiler)
Chapter 1
© copyright Janson Industries 2014
26
JDK (aka JSDK)
Chapter 1
© copyright Janson Industries 2014
27
JDK on the PC
▮ Java JDK 8 is an example
▮ Use IE (not Chrome) to download the JDK:
▮ http://www.oracle.com/technetwork/java/javase
/downloads/index.html
▮ Select the latest version
▮ Click on the JDK download button for the latest
update (i.e. JDK 8, or JDK8u20, etc.)
▮ Select the JDK for your computer (i.e. Windows)
▮ Download to thumb drive (G:) or your C drive
Chapter 1 (at home)
© copyright Janson Industries 2014
28
JDK on the PC
▮ To install the JDK:
▮ Run jdk-8(u#)-windows-i586-p.exe (where # is
the latest version and update numbers)
▮ During the install, create folders to hold the JDK
and JRE called jdk and jre
▮ Delete the original .exe file jdk-8(u#)-windows-
i586-p.exe
Chapter 1
© copyright Janson Industries 2014
29
Select the latest JDK version
Chapter 1
© copyright Janson Industries 2014
30
Scroll down and click the accept agreement radio button
Double click the operating system of the lab computers
(Windows x86)
Chapter 1
© copyright Janson Industries 2014
31
Specify to save the file by clicking the Save drop down
button and then Save As
Chapter 1
© copyright Janson Industries 2014
32
Create a folder called jdkzip on your thumb drive (or the
C: if you will always being work on that same computer)
and save the .exe file to jdkzip
Chapter 1
© copyright Janson Industries 2014
33
Using My Computer open the jdkzip folder
Chapter 1
© copyright Janson Industries 2014
34
JDK on the PC
▮ Only takes
up 165 meg
▮ Final install
will take up
~180 meg
▮ Run the exe file by
double clicking
▮ Click the Next button
Chapter 1
© copyright Janson Industries 2014
35
If you get this, you downloaded the wrong JDK
Chapter 1
© copyright Janson Industries 2014
36
Or this (or any other msg), you downloaded the wrong
JDK
Chapter 1
© copyright Janson Industries 2014
37
Accept the default components
(notice the JRE is just one part of the JDK)
Chapter 1
You can control where the JDK is installed
© copyright Janson Industries 2014
by clicking the Change... button
38
To save on typing later, we’ll change directory to just JDK i.e. E:\JDK
(or C:\JDK\) then click the OK button
Chapter 1
© copyright Janson Industries 2014
39
JDK install window redisplayed with new location
Click Next
Chapter 1
© copyright Janson Industries 2014
40
Shows where JRE will be installed. Change to…
Some students tell me this screen doesn’t appear, if it
doesn’t – no problem, skip the next two slides.
Chapter 1
© copyright Janson Industries 2014
41
Choose drive to save to, then click Make New Folder
Then specify jre, click OK
Chapter 1
© copyright Janson Industries 2014
42
JRE install window redisplayed with new location, click
Next
Chapter 1
© copyright Janson Industries 2014
43
You may have to shut down some running apps
Chapter 1
© copyright Janson Industries 2014
44
And again…
Depending on where you installing, could take a while (a thumb drive
will take longer than a hard drive
Chapter 1
© copyright Janson Industries 2014
45
Two folders called jdk and jre are created (verify with
My Computer)
Delete jdkzip\jdk-8(u#)-windows-i586-p.exe and
click the Close button
Chapter 1
© copyright Janson Industries 2014
46
To verify that you installed correctly, display the
contents of jdk/bin folder and make sure you have two
executable files called javac and java
Chapter 1
© copyright Janson Industries 2014
47
Running a pgm
▮ When you run a application in Windows,
you are specifying an executable file
name
▮ Executable files contain machine
language
▮ On Windows machines these files have
names that end in .exe
Chapter 1
© copyright Janson Industries 2014
48
▮ For instance, clicking
the IE icon tells
Windows to “run”
iexplore.exe in
C:\Program
Files\Internet Explorer\
Chapter 1
© copyright Janson Industries 2014
49
▮ C:\Program Files\Internet Explorer\iexplore.exe is a
fully qualified file name
Chapter 1
© copyright Janson Industries 2014
50
Running a pgm
▮ If a fully qualified file name is not
specified, Windows searches
▮ 1. The default (aka current) directory
▮ 2. The locations stored in the the
Environment Variable called PATH
▮ I.e. path holds all the locations Windows
should search when an unqualified file name
is specified
▮ You can control the value of the Path variable
▮ Let’s prove it!!
Chapter 1
© copyright Janson Industries 2014
51
Running a pgm
▮ In command prompt we specify iexplore.exe
▮ You get the “Not recognized” message
▮ Now specify fully qualified file name (in quotes)
▮ Internet Explorer is started
Chapter 1
© copyright Janson Industries 2014
52
Running a pgm
▮ Now we will set the path value
▮ path = "C:\Program Files\Internet Explorer\"
▮ In command prompt we specify iexplore.exe
▮ Internet Explorer started
Chapter 1
© copyright Janson Industries 2014
53
Running a pgm
▮ JDK/bin must be in the PC’s path for
Windows to access the compile (javac) and
run (java) commands
▮ Path holds the locations to search for files
▮ Several ways to define path locations
▮ Each time you go to the command prompt
(depending on where jdk installed) enter
▮ path=f:\jdk\bin
or
▮ path=c:\jdk\bin
Chapter 1
© copyright Janson Industries 2014
54
Running a pgm
Start Notepad, enter source code, and save file with type of java
F:\Customer.java (must specify type as All Files)
Chapter 1
© copyright Janson Industries 2014
55
Running a pgm
To run, bring up the Command Prompt by clicking:
Start, Accessories, Command Prompt
Chapter 1
© copyright Janson Industries 2014
56
Running
▮ When javac and java commands are run, at
first they do the same thing as Windows
▮ They check the default directory for the java and
bytecode files
▮ If files not there, "file not found" msg displayed
▮ 2 solutions
▮ Change current directory to the location of the files
with the CD (change directory) command
▮ CD F:\, hit Enter, then type F:, hit Enter again
▮ Include files location in classpath variable
Chapter 1
© copyright Janson Industries 2014
57
Running
▮ 1. Issue the path command so that jdk/bin is in
the path
▮ 2. If necessary, change the default path to the
location of the java file (i.e. F:\ )
(type CD F:\, hit Enter, then type F:, hit Enter)
▮ 3. Convert to bytecode (javac Customer.java)
▮ 4. Convert bytecode to machine language and
run the program (java Customer)
Chapter 1
© copyright Janson Industries 2014
58
Running
Prompt shows the default directory
Customer.java is on F:\
current directory is H:\
so “file not found”
Must change current directory to
location of Customer.java (i.e. F:\)
Customer.java found cause
default directory is F:
Chapter 1
© copyright Janson Industries 2014
59
Running a pgm
▮ It’s that easy!
▮ But not very pretty both in terms of
▮ The application function and appearance
▮ The development environment
▮ So we’ll change how we do several things
Chapter 1
© copyright Janson Industries 2014
60
Making Programming Easier
▮ Easier ways to set up path and default dir
▮ Use an IDE (Integrated Development
Environment) instead of notepad
▮ Eclipse
▮ Rational Application Developer (RAD)
▮ NetBeans
▮ Learn more java so that the application
GUI is PURTY
Chapter 1
© copyright Janson Industries 2014
61
JDK Install Problems?
▮ Error 1723 occurred in the installer
package
▮ Lot’s of possible reasons
▮ Click here for some suggestions
Chapter 1
© copyright Janson Industries 2014
62
Possible Problems?
▮ javac or java command is not recognized
▮ Why?
Path not defined correctly. Common mistakes: wrong
drive letter, incorrect directory name(s), extra spaces after
bin, when installing you mixed up jdk and jre directories
▮ Customer file not found:
NoClassDefFoundError,
ClassNotFoundException, could not find the main class
▮ Why?
Chapter 1
Current directory not where Customer file is located (or
per book, Classpath not defined correctly) or file name not
specified correctly (extra spaces, etc.)
© copyright Janson Industries 2014
63
Possible Problems?
▮ When there are Java syntax errors, JVM will
show:
▮ A message with useful info
▮ File name: Customer.java
▮ Line number that has the error: 10
▮ What the problem is: ‘;’ expected
▮ The source code statement(s) that have errors
with ^ under where it thinks there are problems
Chapter 1
© copyright Janson Industries 2014
64
Possible Problems?
▮ Common Java syntax errors
▮ Upper case/lower case letters are
different
▮ If example shows upper case letter, you must
use upper case letter
▮ Forward slash/ back slash\ are different
▮ println (means: print line) not printIn
Chapter 1
© copyright Janson Industries 2014
65
Changes
▮ We’re going to use RAD instead of
notepad
▮ Ch01a slides are next
Chapter 1
© copyright Janson Industries 2014
66
But first….
▮ Class exercise:
▮ Download the JDK to the F: or C: or...
▮ I suggest your thumb drive
▮ Install it
▮ Setup the path and default directory
▮ Enter the source code (exactly as shown on
the slide)
▮ javac and java to run the program
Chapter 1
© copyright Janson Industries 2014
67