23
Java Environment CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D. [email protected]

Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Java EnvironmentCSCI 201

Principles of Software Development

Jeffrey Miller, [email protected]

Page 2: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Outline

• Java Environment• Eclipse Tutorial

USC CSCI 201L

Page 3: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

History of Java

▪ Java was created by Sun Microsystems› First version 1.0 was released in 1996

▪ Sun Microsystems was bought by Oracle in 2010▪ Java has gone through numerous major and minor releases

› Current major version is Java 10, released in 2018 with few updates since

▪ Java is open source▪ http://java.sun.com

USC CSCI 201L 3/23• Java Environment

Page 4: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Compiling▪ Java has a motto of “write once, run anywhere”

› When code is compiled, it produces byte code instead of a binary executable

› The Java Virtual Machine (JVM) is compiled for a specific operating system, then allowing for the byte code to run on any operating system (for which there is a JVM)

› Since the JVM is written in a native language, there may be subtle, or not-so-subtle, differences when run on different JVMs

▪ Java may run slightly slower than compiled native languages

USC CSCI 201L 4/23• Java Environment

Page 5: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Command Line▪ You can write with any text editor you want and compile

it from a command line that has the Java Development Kit (JDK) installed

USC CSCI 201L 5/23• Java Environment

Page 6: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

IDE▪ There are many Integrated Development Environments to

use› Eclipse› NetBeans› IntelliJ› Visual J++› Others?

USC CSCI 201L 6/23• Java Environment

Page 7: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Outline

• Java Environment• Eclipse Tutorial

USC CSCI 201L

Page 8: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Downloading Eclipse▪ Go to http://www.eclipse.org

USC CSCI 201L 8/23• Eclipse Tutorial

Page 9: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Downloading Eclipse▪ Click Downloads

USC CSCI 201L 9/23• Eclipse Tutorial

Page 10: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Downloading Eclipse▪ Select your OS (if not already selected) then click the

version for the Eclipse IDE for Java Developers

USC CSCI 201L 10/23• Eclipse Tutorial

Page 11: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Downloading Eclipse▪ Click the green arrow next to the selected mirror

USC CSCI 201L 11/23• Eclipse Tutorial

Page 12: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Downloading Eclipse▪ Save the zip file

USC CSCI 201L 12/23• Eclipse Tutorial

Page 13: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Downloading Eclipse▪ Open the zip file and drag the “eclipse” directory to your

Desktop (or another directory of your choosing)

USC CSCI 201L 13/23• Eclipse Tutorial

Page 14: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Running Eclipse▪ After the zip file finishes extracting, open the “eclipse”

directory and run the eclipse executable

USC CSCI 201L 14/23• Eclipse Tutorial

Page 15: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Running Eclipse▪ Select a workspace directory

› The workspace directory will be the one that contains all of your projects, code, and compiled files

USC CSCI 201L 15/23• Eclipse Tutorial

Page 16: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Creating a Project▪ Go to File->New->Java Project

USC CSCI 201L 16/23• Eclipse Tutorial

Page 17: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Create a Project ▪ Type a name for the Project and click Finish

› This has nothing to do with the code, but it should be descriptive enough for you to know what code is in the project

USC CSCI 201L 17/23• Eclipse Tutorial

Page 18: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Create a Class▪ Expand the Project by clicking the arrow next to the

name of the project you just created

USC CSCI 201L 18/23• Eclipse Tutorial

Page 19: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Create a Class▪ Right-click on “src” and go to New->Class

USC CSCI 201L 19/23• Eclipse Tutorial

Page 20: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Create a Class▪ Type a name for the class and uncheck all other boxes

(unless you want Eclipse to generate code for you), then click Finish

USC CSCI 201L 20/23• Eclipse Tutorial

Page 21: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Write Some Code▪ You should now have a nearly-blank file and can begin

writing code

USC CSCI 201L 21/23• Eclipse Tutorial

Page 22: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Write Some Code▪ Type the following code into the HelloCSCI201.java file

USC CSCI 201L 22/23• Eclipse Tutorial

Page 23: Java Environment - University of Southern Californiacsci201/lectures/Lecture1/Environment.pdf · Java Environment CSCI 201. Principles of Software Development. Jeffrey Miller, Ph.D

Running the Code▪ Click the green play button at the top to run your code

› If your code doesn’t compile, you will have error messages at the bottom of the screen

› If your code compiles, your output will be at the bottom of the screen

USC CSCI 201L 23/23• Eclipse Tutorial