SlideShare a Scribd company logo
1 of 34
Download to read offline
1
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
Java Fundamentals
4-1
Getting Started with Eclipse
2
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Objectives
•This lesson covers the following objectives:
−Identify components of Eclipse
−Identify components of a Java application
−Compile an application
−Test to ensure application is complete
−Write the code for GalToLit.java
−Modify a program to execute error free
−Modify a program to use a formula
to convert units of measure
3
3
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Eclipse Community and Requirements
•Facts about Eclipse:
−Eclipse was created by an Open Source community
−The Eclipse project is governed by the Eclipse Foundation, a
non-profit organization
−Eclipse requires an installed Java Runtime Environment (JRE)
−Eclipse contains its own development tools, i.e., a Java
compiler
4
While this course officially uses Eclipse the course can be taught with any IDE that allows a program to
be edited, compiled, and run. S04 L01 is the only lesson in the course that directly discusses Eclipse.
Oracle Academy is a member (sponsor) of the Eclipse Foundation.
4
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Java JRE and Java JDK
•Differences between Java JRE and Java JDK:
−Java Runtime Environment (JRE) contains only the necessary
functionality to start Java programs, such as Internet
applications
−Java Development Kit (JDK) contains functionality to start Java
programs as well as develop them
−At a minimum, the Java JRE is required to run Eclipse
5
The JRE is sometimes referred to as the VM (Virtual Machine). For this course, the JDK will be required.
5
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Check for Java on Your Computer
•To verify that Java is already installed on your
computer:
−Windows or Linux operating systems:
• Enter java -version in a command window
−Mac operating system:
• Use the Software Update option from the Apple menu
•This course assumes that you have Java and Eclipse
installed on your computer
6
With appropriate arguments, java is the command that runs Java programs. javac is the command that
compiles .java source code files into .class files that can then be executed with the java command. The
IDE is the front end interface that uses these commands.
6
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Steps to Launch Eclipse
•On a computer with Windows double-click on the file
eclipse.exe
•On a Linux or Mac computer double click on the file
eclipse
•When prompted, enter the pathname for the
workspace into which you will store your Java projects
and click the OK button
•This can be your c: drive, or possibly a network drive
•Eclipse will start and display the Welcome page
•Close the Welcome page by clicking the X next to the
Welcome tab name
7
As of May 2017, the screen captures are for Eclipse version Kepler, this is only apparent with the
Welcome screen. The most recent version of Eclipse should be used with this course.
7
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Eclipse Welcome Page
•There are valuable resources available from the
Welcome page
•You can return to the Welcome page by choosing
Welcome from the Help menu
8
8
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Eclipse Edit Area and Views
•Eclipse provides an edit area and several views
•An editor is where you type in your Java source code
•Views are sub-windows that provide information about
your project
9
9
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Eclipse Edit Area Tabs
•The edit area uses tabs when more than one file is
open
10
10
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Eclipse Edit Area Windows
•The edit area can have multiple windows occupy the
space
11
11
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Additional Details on Edit Areas and Views
•A combination of views and editors are referred to as a
perspective
•You can choose Open Perspective from the Window
menu
12
12
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
The Workspace
•All projects are developed and modified in a workspace
•A workspace is a collection of Projects
•In this course, you may use the same workspace for all
practice projects and packages
•A project is a way for programmers to organize Java
files
•A package is how Java and Eclipse organize Java files
that are related
•Using packages will ensure that related files can find
each other
13
Do not keep the workspace in the same folder as Eclipse itself. That way if Eclipse is corrupted or
upgraded the workspace will not be lost. Keeping both on a portable device such as a flash drive is an
option. BACK UP THE WORKSPACE!
13
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Switching Workspaces
•You can Switch Workspaces
−From the File menu change
to a different physical location
for your files
14
14
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
High-Level Steps to Create a Program in Eclipse
•Create a Project
•Create a Package (inside the src folder of the project)
•Create Class(es) inside the package
−At least one of the classes must contain a main method
−This class is called the Driver class
•Compile the Java code
•This creates a .class file
•Run the Java code from the Driver class
15
Packages are covered in detail in Java Programming and are used to organize Java classes. A project
may be created without using packages. Eclipse refers to this as the default package and warns that the
practice is discouraged.
15
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Projects in Eclipse
•In Eclipse:
−All programs must reside inside a project for proper
compilation
−You may have one or multiple class files in one project
−One of the classes must contain a main method
16
16
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Steps to Create a Project in Eclipse
•Choose File → New → Java Project*
•Enter a project name and click Finish
•All project values are set to default by clicking the
Finish button
17
If the project pane is closed, it may be reopened from the Window -> Show View menus and then
selecting Project Explorer. (Note that for the purposes of this course, there is no significant difference
between the Project Explorer and the Package Explorer.)
*Update: If New -> Java Project is not available, choose Window -> Open Perspective -> Java. Then
New -> Java project will be available.
17
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Project Display
•The project is created and displayed as a folder
•It displays in the Package view to the left of the edit
area
18
18
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Steps to Create a Package
•Select the src folder in the Package view
•Right click the src folder and choose New → Package
A package, in Java, is a mechanism for organizing Java classes into
namespaces or containers. In Eclipse, packages are created inside
projects.
19
19
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Naming Packages
•Name this package the same name as the Project
using lower camel case
Camel case is the practice of stringingCapitalizedWords together with no
spaces. Lower camel case does not capitalize the lead word.
20
Conventional naming practices for packages will be covered in Java Programming. For now, we use the
same name for the package and the project for convenience.
20
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Steps to Create a Class
•Right click on the project name to create a new class
named StudyPage in the studyTool package
•Select the option to create the main method
A class in Java is a construct that is used as a blueprint to create
objects. It can also be a construct in which objects are created.
21
21
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Create a Class Display
•The option is selected to create the main method
A main method, in Java, is the method
inside a class that runs when the class is
compiled and run. This class is referred to as
the Driver Class.
22
22
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
New Class
•Notice the following:
−The StudyPage.java class appears in the studyTool package in
the Package Explorer View
−The StudyPage.java class is created with the main method
23
The class name in the .java file must match the name of the .java file (without the .java extension). If
the class name is changed in the source code, the file name must also be changed. It is recommended
that this NOT be done manually. Right click on the class in the Project pane and select Refactor ->
Rename. This has the added benefit of updating the class name change in all files where it is used in the
project.
23
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Steps to Create and Run Java Code
•To implement the main method and run the program,
enter the following information into the main class
•The method inside a class that runs when the class is
compiled and ran is the main method
public class StudyPage {
public static void main(String[] args) {
System.out.println("Enter a study term");
}//end method main
}//end class StudyPage
24
24
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Steps to Create and Run Java Code
•Right click on StudyPage.java in the package view
•Choose Run As → Java Application
•Save the class when prompted
•Note results display in the Console View
25
25
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Implementing the Main Class Code
•Continue implementing the main class to accept a
term, prompt for a definition, accept a definition, and
finally, display the term and definition as shown below
package studyTool;
import java.util.Scanner;
public class StudyPage {
public static void main(String[] args) {
Scanner scanterm = new Scanner(System.in);
String termvar;
System.out.println("Enter a study term");
termvar = scanterm.nextLine();
Scanner scandef = new Scanner(System.in);
String termdef;
System.out.println("Enter a definition");
termdef = scandef.nextLine();
System.out.println(termvar + ": " + termdef);
}//end method main
}//end class StudyPage
26
The Scanner class is covered in detail in Section 5, Lesson 1.
26
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Implementing the Main Class Code
•You may have to correct some syntax errors that are a
result of typing errors
•See if you can correct them without asking for
assistance
•Pay particular attention to the ";" at the end of each
line, and that your "{" (left curly brace) has a matching
"}" (right curly brace
27
27
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Describe the StudyPage Class Code
•See if you can describe how the code in the StudyPage
class is interpreted by Java
•Add comments to your code to describe what you
think the lines of code do
−Comments are ignored by the Java compiler
−To add a comment, type // in front of the comment
28
/* Of course, the multi-line comment may be used, too. */
28
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Program to Convert Gallons to Liters
•What is the formula to convert gallons to liters?
−1 US gallon is equivalent to 3.78541178 Liters
29
29
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Pseudocode for Gallons to Liters Conversion
•What is the math calculation to complete the
conversion?
•Pseudocode would look like:
−Use Scanner to read in the number of gallons
−Store the number of gallons in a variable
−Multiply that variable by 3.785 (variable*3.785) and store this
new value into a second variable (Hint: use double for the
variables, not int)
−Display the output
−Use the StudyPage program as a guide to create the program
on your own
30
30
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Hints for Gallons to Liters Conversion
•Hints:
−an int variable type is used to store whole numbers
−a double variable type is used to store decimal numbers
−int numgallons = 0; //declare a variable for number of gallons
−double converttoliters = numgallons * 3.785
31
31
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Terminology
•Key terms used in this lesson included:
−Camel case
−Eclipse:
• edit and view areas, perspective, workspace
−Java JRE vs. Java JDK
−Java classes
−Java packages
−Java main methods
32
32
Copyright © 2020, Oracle and/or its affiliates. All rights reserved.
JF 4-1
Getting Started with Eclipse
Summary
•In this lesson, you should have learned how to:
−Identify components of Eclipse
−Identify components of a Java application
−Compile an application
−Test to ensure application is complete
−Write the code for GalToLit.java
−Modify a program to execute error free
−Modify a program to use a
formula to convert units of
measure
33
33
34

More Related Content

Similar to JF_4_1_sg.pdf

Java Intro: Unit1. Hello World
Java Intro: Unit1. Hello WorldJava Intro: Unit1. Hello World
Java Intro: Unit1. Hello WorldYakov Fain
 
Eclipse Overview
Eclipse Overview Eclipse Overview
Eclipse Overview Lars Vogel
 
Assign 10 - Creating Projects using Eclipse IDE
Assign 10 -  Creating Projects using Eclipse IDE Assign 10 -  Creating Projects using Eclipse IDE
Assign 10 - Creating Projects using Eclipse IDE Yogesh Deshpande
 
Eclipse_Building_Blocks
Eclipse_Building_BlocksEclipse_Building_Blocks
Eclipse_Building_BlocksRahul Shukla
 
Page 8 of 83.Tutorial Get Started with Eclipse in the Compute.docx
Page 8 of 83.Tutorial Get Started with Eclipse in the Compute.docxPage 8 of 83.Tutorial Get Started with Eclipse in the Compute.docx
Page 8 of 83.Tutorial Get Started with Eclipse in the Compute.docxalfred4lewis58146
 
Applet blue j-intro_applets
Applet blue j-intro_appletsApplet blue j-intro_applets
Applet blue j-intro_appletsFajar Baskoro
 
Introduction to Eclipse
Introduction to Eclipse Introduction to Eclipse
Introduction to Eclipse Arpana Awasthi
 
Supplement J Eclipse
Supplement J EclipseSupplement J Eclipse
Supplement J Eclipsenga
 
Selenium topic 4 - Selenium Web Driver Set Up
Selenium topic 4 - Selenium Web Driver Set UpSelenium topic 4 - Selenium Web Driver Set Up
Selenium topic 4 - Selenium Web Driver Set UpITProfessional Academy
 
Installing and setting up eclipse java projects
Installing and setting up eclipse java projectsInstalling and setting up eclipse java projects
Installing and setting up eclipse java projectshccit
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee applicationKumar
 
Myeclipse+Eclipse+J Boss开发Ejb
Myeclipse+Eclipse+J Boss开发EjbMyeclipse+Eclipse+J Boss开发Ejb
Myeclipse+Eclipse+J Boss开发Ejbyiditushe
 

Similar to JF_4_1_sg.pdf (20)

Java Intro: Unit1. Hello World
Java Intro: Unit1. Hello WorldJava Intro: Unit1. Hello World
Java Intro: Unit1. Hello World
 
3 more abouteclipse
3 more abouteclipse3 more abouteclipse
3 more abouteclipse
 
Eclipse Overview
Eclipse Overview Eclipse Overview
Eclipse Overview
 
Assign 10 - Creating Projects using Eclipse IDE
Assign 10 -  Creating Projects using Eclipse IDE Assign 10 -  Creating Projects using Eclipse IDE
Assign 10 - Creating Projects using Eclipse IDE
 
Eclipse_Building_Blocks
Eclipse_Building_BlocksEclipse_Building_Blocks
Eclipse_Building_Blocks
 
DesktopApps.pptx
DesktopApps.pptxDesktopApps.pptx
DesktopApps.pptx
 
Page 8 of 83.Tutorial Get Started with Eclipse in the Compute.docx
Page 8 of 83.Tutorial Get Started with Eclipse in the Compute.docxPage 8 of 83.Tutorial Get Started with Eclipse in the Compute.docx
Page 8 of 83.Tutorial Get Started with Eclipse in the Compute.docx
 
J introtojava1-pdf
J introtojava1-pdfJ introtojava1-pdf
J introtojava1-pdf
 
1 about eclipse
1 about eclipse1 about eclipse
1 about eclipse
 
Applet blue j-intro_applets
Applet blue j-intro_appletsApplet blue j-intro_applets
Applet blue j-intro_applets
 
Introduction to Eclipse
Introduction to Eclipse Introduction to Eclipse
Introduction to Eclipse
 
Supplement J Eclipse
Supplement J EclipseSupplement J Eclipse
Supplement J Eclipse
 
Selenium topic 4 - Selenium Web Driver Set Up
Selenium topic 4 - Selenium Web Driver Set UpSelenium topic 4 - Selenium Web Driver Set Up
Selenium topic 4 - Selenium Web Driver Set Up
 
1 about eclipse
1 about eclipse1 about eclipse
1 about eclipse
 
1 about eclipse
1 about eclipse1 about eclipse
1 about eclipse
 
Installing and setting up eclipse java projects
Installing and setting up eclipse java projectsInstalling and setting up eclipse java projects
Installing and setting up eclipse java projects
 
Android programming-basics
Android programming-basicsAndroid programming-basics
Android programming-basics
 
Java part 1
Java part 1Java part 1
Java part 1
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee application
 
Myeclipse+Eclipse+J Boss开发Ejb
Myeclipse+Eclipse+J Boss开发EjbMyeclipse+Eclipse+J Boss开发Ejb
Myeclipse+Eclipse+J Boss开发Ejb
 

Recently uploaded

Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITMgdsc13
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewingbigorange77
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Roomdivyansh0kumar0
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)Christopher H Felton
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一Fs
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...akbard9823
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Roomdivyansh0kumar0
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMartaLoveguard
 
The Intriguing World of CDR Analysis by Police: What You Need to Know.pdf
The Intriguing World of CDR Analysis by Police: What You Need to Know.pdfThe Intriguing World of CDR Analysis by Police: What You Need to Know.pdf
The Intriguing World of CDR Analysis by Police: What You Need to Know.pdfMilind Agarwal
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 

Recently uploaded (20)

Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewing
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130  Available With RoomVIP Kolkata Call Girl Alambazar 👉 8250192130  Available With Room
VIP Kolkata Call Girl Alambazar 👉 8250192130 Available With Room
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptx
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
The Intriguing World of CDR Analysis by Police: What You Need to Know.pdf
The Intriguing World of CDR Analysis by Police: What You Need to Know.pdfThe Intriguing World of CDR Analysis by Police: What You Need to Know.pdf
The Intriguing World of CDR Analysis by Police: What You Need to Know.pdf
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
 

JF_4_1_sg.pdf

  • 1. 1
  • 2. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Java Fundamentals 4-1 Getting Started with Eclipse 2
  • 3. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Objectives •This lesson covers the following objectives: −Identify components of Eclipse −Identify components of a Java application −Compile an application −Test to ensure application is complete −Write the code for GalToLit.java −Modify a program to execute error free −Modify a program to use a formula to convert units of measure 3 3
  • 4. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Eclipse Community and Requirements •Facts about Eclipse: −Eclipse was created by an Open Source community −The Eclipse project is governed by the Eclipse Foundation, a non-profit organization −Eclipse requires an installed Java Runtime Environment (JRE) −Eclipse contains its own development tools, i.e., a Java compiler 4 While this course officially uses Eclipse the course can be taught with any IDE that allows a program to be edited, compiled, and run. S04 L01 is the only lesson in the course that directly discusses Eclipse. Oracle Academy is a member (sponsor) of the Eclipse Foundation. 4
  • 5. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Java JRE and Java JDK •Differences between Java JRE and Java JDK: −Java Runtime Environment (JRE) contains only the necessary functionality to start Java programs, such as Internet applications −Java Development Kit (JDK) contains functionality to start Java programs as well as develop them −At a minimum, the Java JRE is required to run Eclipse 5 The JRE is sometimes referred to as the VM (Virtual Machine). For this course, the JDK will be required. 5
  • 6. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Check for Java on Your Computer •To verify that Java is already installed on your computer: −Windows or Linux operating systems: • Enter java -version in a command window −Mac operating system: • Use the Software Update option from the Apple menu •This course assumes that you have Java and Eclipse installed on your computer 6 With appropriate arguments, java is the command that runs Java programs. javac is the command that compiles .java source code files into .class files that can then be executed with the java command. The IDE is the front end interface that uses these commands. 6
  • 7. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Steps to Launch Eclipse •On a computer with Windows double-click on the file eclipse.exe •On a Linux or Mac computer double click on the file eclipse •When prompted, enter the pathname for the workspace into which you will store your Java projects and click the OK button •This can be your c: drive, or possibly a network drive •Eclipse will start and display the Welcome page •Close the Welcome page by clicking the X next to the Welcome tab name 7 As of May 2017, the screen captures are for Eclipse version Kepler, this is only apparent with the Welcome screen. The most recent version of Eclipse should be used with this course. 7
  • 8. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Eclipse Welcome Page •There are valuable resources available from the Welcome page •You can return to the Welcome page by choosing Welcome from the Help menu 8 8
  • 9. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Eclipse Edit Area and Views •Eclipse provides an edit area and several views •An editor is where you type in your Java source code •Views are sub-windows that provide information about your project 9 9
  • 10. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Eclipse Edit Area Tabs •The edit area uses tabs when more than one file is open 10 10
  • 11. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Eclipse Edit Area Windows •The edit area can have multiple windows occupy the space 11 11
  • 12. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Additional Details on Edit Areas and Views •A combination of views and editors are referred to as a perspective •You can choose Open Perspective from the Window menu 12 12
  • 13. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse The Workspace •All projects are developed and modified in a workspace •A workspace is a collection of Projects •In this course, you may use the same workspace for all practice projects and packages •A project is a way for programmers to organize Java files •A package is how Java and Eclipse organize Java files that are related •Using packages will ensure that related files can find each other 13 Do not keep the workspace in the same folder as Eclipse itself. That way if Eclipse is corrupted or upgraded the workspace will not be lost. Keeping both on a portable device such as a flash drive is an option. BACK UP THE WORKSPACE! 13
  • 14. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Switching Workspaces •You can Switch Workspaces −From the File menu change to a different physical location for your files 14 14
  • 15. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse High-Level Steps to Create a Program in Eclipse •Create a Project •Create a Package (inside the src folder of the project) •Create Class(es) inside the package −At least one of the classes must contain a main method −This class is called the Driver class •Compile the Java code •This creates a .class file •Run the Java code from the Driver class 15 Packages are covered in detail in Java Programming and are used to organize Java classes. A project may be created without using packages. Eclipse refers to this as the default package and warns that the practice is discouraged. 15
  • 16. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Projects in Eclipse •In Eclipse: −All programs must reside inside a project for proper compilation −You may have one or multiple class files in one project −One of the classes must contain a main method 16 16
  • 17. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Steps to Create a Project in Eclipse •Choose File → New → Java Project* •Enter a project name and click Finish •All project values are set to default by clicking the Finish button 17 If the project pane is closed, it may be reopened from the Window -> Show View menus and then selecting Project Explorer. (Note that for the purposes of this course, there is no significant difference between the Project Explorer and the Package Explorer.) *Update: If New -> Java Project is not available, choose Window -> Open Perspective -> Java. Then New -> Java project will be available. 17
  • 18. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Project Display •The project is created and displayed as a folder •It displays in the Package view to the left of the edit area 18 18
  • 19. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Steps to Create a Package •Select the src folder in the Package view •Right click the src folder and choose New → Package A package, in Java, is a mechanism for organizing Java classes into namespaces or containers. In Eclipse, packages are created inside projects. 19 19
  • 20. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Naming Packages •Name this package the same name as the Project using lower camel case Camel case is the practice of stringingCapitalizedWords together with no spaces. Lower camel case does not capitalize the lead word. 20 Conventional naming practices for packages will be covered in Java Programming. For now, we use the same name for the package and the project for convenience. 20
  • 21. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Steps to Create a Class •Right click on the project name to create a new class named StudyPage in the studyTool package •Select the option to create the main method A class in Java is a construct that is used as a blueprint to create objects. It can also be a construct in which objects are created. 21 21
  • 22. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Create a Class Display •The option is selected to create the main method A main method, in Java, is the method inside a class that runs when the class is compiled and run. This class is referred to as the Driver Class. 22 22
  • 23. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse New Class •Notice the following: −The StudyPage.java class appears in the studyTool package in the Package Explorer View −The StudyPage.java class is created with the main method 23 The class name in the .java file must match the name of the .java file (without the .java extension). If the class name is changed in the source code, the file name must also be changed. It is recommended that this NOT be done manually. Right click on the class in the Project pane and select Refactor -> Rename. This has the added benefit of updating the class name change in all files where it is used in the project. 23
  • 24. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Steps to Create and Run Java Code •To implement the main method and run the program, enter the following information into the main class •The method inside a class that runs when the class is compiled and ran is the main method public class StudyPage { public static void main(String[] args) { System.out.println("Enter a study term"); }//end method main }//end class StudyPage 24 24
  • 25. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Steps to Create and Run Java Code •Right click on StudyPage.java in the package view •Choose Run As → Java Application •Save the class when prompted •Note results display in the Console View 25 25
  • 26. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Implementing the Main Class Code •Continue implementing the main class to accept a term, prompt for a definition, accept a definition, and finally, display the term and definition as shown below package studyTool; import java.util.Scanner; public class StudyPage { public static void main(String[] args) { Scanner scanterm = new Scanner(System.in); String termvar; System.out.println("Enter a study term"); termvar = scanterm.nextLine(); Scanner scandef = new Scanner(System.in); String termdef; System.out.println("Enter a definition"); termdef = scandef.nextLine(); System.out.println(termvar + ": " + termdef); }//end method main }//end class StudyPage 26 The Scanner class is covered in detail in Section 5, Lesson 1. 26
  • 27. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Implementing the Main Class Code •You may have to correct some syntax errors that are a result of typing errors •See if you can correct them without asking for assistance •Pay particular attention to the ";" at the end of each line, and that your "{" (left curly brace) has a matching "}" (right curly brace 27 27
  • 28. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Describe the StudyPage Class Code •See if you can describe how the code in the StudyPage class is interpreted by Java •Add comments to your code to describe what you think the lines of code do −Comments are ignored by the Java compiler −To add a comment, type // in front of the comment 28 /* Of course, the multi-line comment may be used, too. */ 28
  • 29. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Program to Convert Gallons to Liters •What is the formula to convert gallons to liters? −1 US gallon is equivalent to 3.78541178 Liters 29 29
  • 30. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Pseudocode for Gallons to Liters Conversion •What is the math calculation to complete the conversion? •Pseudocode would look like: −Use Scanner to read in the number of gallons −Store the number of gallons in a variable −Multiply that variable by 3.785 (variable*3.785) and store this new value into a second variable (Hint: use double for the variables, not int) −Display the output −Use the StudyPage program as a guide to create the program on your own 30 30
  • 31. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Hints for Gallons to Liters Conversion •Hints: −an int variable type is used to store whole numbers −a double variable type is used to store decimal numbers −int numgallons = 0; //declare a variable for number of gallons −double converttoliters = numgallons * 3.785 31 31
  • 32. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Terminology •Key terms used in this lesson included: −Camel case −Eclipse: • edit and view areas, perspective, workspace −Java JRE vs. Java JDK −Java classes −Java packages −Java main methods 32 32
  • 33. Copyright © 2020, Oracle and/or its affiliates. All rights reserved. JF 4-1 Getting Started with Eclipse Summary •In this lesson, you should have learned how to: −Identify components of Eclipse −Identify components of a Java application −Compile an application −Test to ensure application is complete −Write the code for GalToLit.java −Modify a program to execute error free −Modify a program to use a formula to convert units of measure 33 33
  • 34. 34