Lesson 03
Lesson 03
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 3-2
Topics
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 3-3
Java Classes
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 3-4
Program Structure
Java is case-sensitive!
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 3-5
Java Packages
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 3-6
Java IDEs
A Java Integrated Development Environment (IDE) is a type of software that makes it easier
to develop Java applications.
• An IDE provides:
– Syntax checking
– Various automation features
– Runtime environment for testing
• It enables you to organize all your Java resources
and environment settings into a Project.
• Projects contain packages.
• Packages contain files, such as .java.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 3-7
The NetBeans IDE
Code
Project Editor
Navigator
Class
Navigato
r
Program Output
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 3-8
Creating a Java Project
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 3-9
Creating a Java Class
If you need to open an existing project in NetBeans, perform the following steps:
1. Select File > Open Project.
2. Navigate to the directory that contains your projects.
3. Select the project file you want. (This file must be unzipped.)
4. Click Open Project.
If you ever need to create a new package, perform the following steps in NetBeans:
1. Right-click your project.
2. Select New > Java Package.
3. Name the package.
4. Click Finish.
• It is a special method that the JVM recognizes as the starting point for every Java
program.
• The syntax is always the same:
main Program
meth output
od
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 3 - 16
Output to the Console
• Syntax:
System.out.println (<some string value>);
Save is
equivalent to
javac.
Run is
equivalent
to java.
In this exercise, you manually enter a main method that prints a message to the console.
1. Continue editing Exercise_03-1 or open Exercise_03-2.
2. In the code editor, add the main method structure to the ShoppingCart class.
3. In the code block of the main method, use a System.out.println method to print
“Welcome to the Shopping Cart!”
4. Save your program.
5. Click the Run button to test program.
– Select exercise.ShoppingCart as the main class.