Download presentation
Presentation is loading. Please wait.
Published byClaribel Berry Modified over 9 years ago
1
Chapter 1© copyright Janson Industries 20151 Java ▮ Java programming concepts ▮ Downloading the JDK ▮ Java coding and executing example This presentation can be viewed on line at: http://web.fscj.edu/Janson/COP1000/ch01a.IntrotoJava.ppt Ch1 Assg 3
2
Java Concepts Chapter 1© copyright Janson Industries 20152 ▮ 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
3
Java Concepts Chapter 1© copyright Janson Industries 20153 Cust.java (Java file) Editor (Notepad++) Java source code Compiler Java source code Programmer javac Cust.java JVM Java bytecode Programmer java Cust main method in Machine Language CPU Cust.class (Class file)
4
Chapter 1© copyright Janson Industries 20154 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 command) 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 command)
5
Chapter 1© copyright Janson Industries 20155 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
6
Chapter 1© copyright Janson Industries 20156 Java Virtual Machine (JVM) ▮ To run a java application on a computer you must download a JVM/JRE (java runtime environment) ▮ But to compile you also need the java compiler ▮ Oracle (and many other vendors) offer ▮ Oracle has a JDK (Java Development Kit) that includes a JRE and the compiler
7
Chapter 1© copyright Janson Industries 20157 JDK (aka JSDK)
8
Chapter 1© copyright Janson Industries 20158 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 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 JDK8u60, etc. ) ▮ Select the JDK for your computer (i.e. Windows) ▮ Download to thumb drive (G:) or your C drive (at home)
9
Chapter 1© copyright Janson Industries 20159 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
10
Chapter 1© copyright Janson Industries 201510 Select the latest JDK version
11
Chapter 1© copyright Janson Industries 201511 Scroll down and click the accept agreement radio button Double click the operating system of the lab computers (Windows x86)
12
Chapter 1© copyright Janson Industries 201512 Specify to save the file by clicking the Save drop down button and then Save As
13
Chapter 1© copyright Janson Industries 201513 Create and save to a folder called jdkzip on your thumb drive (or the C: if you will always being work on that same computer)
14
Chapter 1© copyright Janson Industries 201514 Using My Computer open the jdkzip folder
15
© copyright Janson Industries 2015Chapter 115 ▮ Run the exe file by double clicking ▮ Click the Next button JDK on the PC ▮ Only takes up 180 meg ▮ Final install will take up ~ 180 meg
16
Chapter 1© copyright Janson Industries 201516 If you get this, you downloaded the wrong JDK
17
Chapter 1© copyright Janson Industries 201517 Or this (or any other msg), you downloaded the wrong JDK
18
Chapter 1© copyright Janson Industries 201518 Accept the default components (notice the JRE is just one part of the JDK) You can control where the JDK is installed by clicking the Change... button
19
Chapter 1© copyright Janson Industries 201519 To save on typing later, we’ll change directory to just JDK i.e. F:\JDK (or C:\JDK\) then click the OK button
20
Chapter 1© copyright Janson Industries 201520 JDK install window redisplayed with new location Click Next
21
Chapter 1© copyright Janson Industries 201521 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.
22
Chapter 1© copyright Janson Industries 201522 Choose drive to save to, then click Make New Folder Then specify jre, click OK
23
Chapter 1© copyright Janson Industries 201523 JRE install window redisplayed with new location
24
Chapter 1© copyright Janson Industries 201524 You may have to shut down some running apps
25
Chapter 1© copyright Janson Industries 201525 And again…
26
Chapter 1© copyright Janson Industries 201526 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
27
Chapter 1© copyright Janson Industries 201527 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
28
Chapter 1© copyright Janson Industries 201528 JDK Install Problems? ▮ Error 1723 occurred in the installer package ▮ Lot’s of possible reasons ▮ Click here for some suggestions Click here
29
Chapter 1© copyright Janson Industries 201529 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
30
Chapter 1© copyright Janson Industries 201530 ▮ For instance, clicking the IE icon tells Windows to “run” iexplore.exe in C:\Program Files\Internet Explorer\
31
Chapter 1© copyright Janson Industries 201531 ▮ C:\Program Files\Internet Explorer\iexplore.exe is a fully qualified file name
32
Chapter 1© copyright Janson Industries 201532 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!!
33
Chapter 1© copyright Janson Industries 201533 Running a pgm ▮ Let’s prove it ▮ In command prompt we specify iexplore.exe ▮ “Not recognized” message ▮ Now specify fully qualified file name (in quotes) ▮ IE started
34
Chapter 1© copyright Janson Industries 201534 Running a pgm ▮ Now we will set the path value ▮ path = "C:\Program Files\Internet Explorer\" ▮ In command prompt we specify iexplore.exe ▮ IE started
35
Chapter 1© copyright Janson Industries 201535 Running a pgm ▮ JDK must be in the PC’s path to access the compile (javac) and run (java) commands (as well as other stuff) ▮ Path holds locations of executable 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
36
Chapter 1© copyright Janson Industries 201536 Will use Notepad++ to enter source code and save to a file Download Notepad++ from http://notepad-plus-plus.org/download
37
Chapter 1© copyright Janson Industries 201537 Save As to your thumbdrive (so you can run anywhere)
38
Chapter 1© copyright Janson Industries 201538 Click Run, then OK
39
Chapter 1© copyright Janson Industries 201539 Click Next then I Agree
40
Chapter 1© copyright Janson Industries 201540 Specify a location on your thumbdrive (so you can run from anywhere) then click Next Click Next again
41
Chapter 1© copyright Janson Industries 201541 If installing to thumbdrive select first option, if not select third option Click Install Click Finish
42
Chapter 1© copyright Janson Industries 201542 Close change.log
43
Chapter 1© copyright Janson Industries 201543 Running a pgm Enter source code as follows (ignore colors) Then click File, Save
44
Chapter 1© copyright Janson Industries 201544 Start Notepad++, enter source code, and save file with type of java F:\Customer.java (must specify type as All Files) Running a pgm Save to the root of your thumbdrive (i.e. F:\) Change Save as type to Java source file then the file name to Customer.java (must leave.java in file name) Click Save
45
Chapter 1© copyright Janson Industries 201545 Running a pgm A couple java rules: File name (Customer) must match certain statements System.out.println() displays text Statements end in a semicolon (;)
46
Chapter 1© copyright Janson Industries 201546 To run, bring up the Command Prompt by clicking: Start, Accessories, Command Prompt Running a pgm
47
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 (source code) and.class (bytecode) files ▮ If files not there, "file not found" msg displayed ▮ Solution ▮ 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 Chapter 1© copyright Janson Industries 201547
48
Running Chapter 1© copyright Janson Industries 201548 ▮ The current/default directory is displayed in the command prompt ▮ In this example it is H:\
49
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 to be compiled (i.e. F:\ ) (type CD F:\, hit Enter, then type F:, hit Enter) ▮ 3. Convert to byte code (javac Customer.java) ▮ 4. Run the program (java Customer) Chapter 1© copyright Janson Industries 201549
50
Running Chapter 1© copyright Janson Industries 201550 Must change current directory to location of Customer.java (i.e. F:\) Customer.java is on F:\ current directory is H:\ so “file not found” Customer.java found cause default directory is F:
51
Chapter 1© copyright Janson Industries 201551 Possible Problems? ▮ javac or java command is not recognized ▮ Why? ▮ Customer not found: NoClassDefFoundError, ClassNotFoundException, could not find the main class ▮ 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 Current directory not where Customer file is located or file name not specified correctly (extra spaces, etc.)
52
Chapter 1© copyright Janson Industries 201552 Possible Problems? ▮ When there are 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 statements that have errors with ^ under where it thinks there are problems
53
Chapter 1© copyright Janson Industries 201553 Possible Problems? ▮ 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
54
54 In Class Exercise ▮ Create Customer.java and enter the source code using notepad ▮ Compile and run Customer
55
55 Non-graded Assg3 ▮ Create a java file called Yay that displays the following: ▮ Yay! ▮ My first java program ▮ Send Yay.java as email attachment to me at rjanson@fscj.edu ▮ Specify the Email topic as Ch01Assg3
56
56 Non–graded Assg3 ▮ When Yay is run the output should look like this:
57
57 Graded Assignments ▮ You will have to download lab files (Word documents) for the graded assignments ▮ Create a folder on your memory stick to hold the files (and your work) called COP1000 ▮ Download the labs from the the folder Labs at the same location as the PP presentations
58
58 Java ▮ Java Language Companion (JLC) guide ▮ This is the Java text book ▮ In a PDF file at the same location as the PP presentations and labs ▮ Download and read
59
Chapter 1© copyright Janson Industries 201559 http://web.fscj.edu/Janson/COP1000/
60
Chapter 1© copyright Janson Industries 201560 No graded assg until C2 but you can start before
61
Chapter 1© copyright Janson Industries 201561 The Word doc contains several non-graded assgs (labs) and one graded assg (usually the last lab in the doc)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.