Uploaded by xie

JAVA-PROGRAMMING-WEEK-9-MODULE-7

advertisement
Republic of the Philippines
Department of Education
National Capital Region
DIVISION OF CITY SCHOOLS – PASIG
JAVA PROGRAMMING
Science, Technology, Engineering
and Mathematics (STEM) Strand
QUARTER 1 WEEK 9 MODULE 7
Learning Competency:
Creating Java Applications
LESSON 7: JAVA NETBEANS IDE and CREATING THE FIRST JAVA APPLICATION
1
JAVA PROGRAMMING
K TO 12 CURRICULUM
DIVISION OF CITY SCHOOLS – PASIG
DEPARTMENT OF EDUCATION
K TO 12 BASIC EDUCATION CURRICULUM
JUNIOR HIGH SCHOOL
SCIENCE, TECHNOLOGY, ENGINEERING AND
MATHEMATICS (STEM) TRACK
JAVA PROGRAMMING
2
Before starting the module, set aside tasks that might hinder you to enjoy the lesson. You’ll be
given instructions to successfully meet the objectives of this module! Have fun!
1. Read the content and follow the instructions for activities and learning outcomes in
every page of the module
2. You are also strongly encouraged to do hands-on check to make sure that you follow
all instructions as actual hands-on/demonstration of the activity will be required in
the succeeding modules
3. You’ll be provided with activities that require program logic formulation and
demonstration of writing codes.
4. Analyze the concepts and answer the post-test to evaluate how you
perform in every module.
5. Enjoy learning!
Expectations - This points to the set of knowledge and skills
that you will learn after completing the module.
Pretest - This measures your prior knowledge about the lesson
at hand.
Recap - This part of the module provides a review of concepts
and skills that you already know about a previous lesson.
Lesson - This section discusses the topic in the module.
Activities - This is a set of activities that you need to perform.
Wrap-Up - This section summarizes the concepts and
application of the lesson.
Valuing - This part integrates a desirable moral value in the
lesson.
Posttest - This measures how much you have learned from the
entire module.
3
Parts of the module:
Specific objectives: This are the list of specific goals to meet after completing each
module.
Pre-test: This will determine students’ prior knowledge on the concepts
included in the course
Brief Introduction: This will give you an overview of the scope and sequence of
discussion in this module.
Technical Terms: Are vocabulary words that specializes in the field of computing.
Activities: Are set of tasks that you need to accomplish in this module.
Remember: This section explains the summary concepts and applications discussed
in every module.
Check your understanding: This section will assess your learning from each lesson
in this module.
Post-test: This will assess how much you learn from each part of the module.
At the end of the lesson, the students should be able to:
1. Follow the installation set-up for Java Development Kit (JDK) file and Apache
Netbeans.
2. identify the parts of the Java Netbeans IDE and define their functions.
3. Create the first Java Application.
TECHNICAL TERMS
Abstraction
It’s a java concept which means showing the relevant information that is need for
a task.
Encapsulation
For data security purposes, this concept identifies data that is stored within the
classes and is not easily accessible to anyone.
4
Inheritance
The attributes and characteristics of one class can be inherited by another class.
In effect, it takes less time writing codes.
Polymorphism
This means using the same method for different tasks.
In java, we can use the same object or variable in two different places where their
tasks will differ.
Define Loop.
___________________________________________________
___________________________________________________
___________________________________________________
Give a real-life example where loop is evident.
_______________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
Multiple Choice: Choose the letter of the correct answer that referred to the
statements below.
1. Which of the following Java Netbeans IDE parts displays the tools used for
commonly used tasks?
a. Title bar
b. Menu bar
c. Tool bar
d. Toolbox
5
2. Which of the following Java edition is used when the user wants to create a
mobile application?
a. Java SE
b. Java ME
c. Java EE
d. Java CE
3. The following are Java features except
a. Operator overloading
b. Platform independent
c. Exception handling
d. Multi-threading
4. The following are Java names except
a. Oak
b. Green
c. Red
d. Java Coffee
5. Which of the following is NOT a Java concept?
a. Inheritance
b. Abstraction
c. Encapsulation
d. Data Overloading
Programming makes life easier. Consider how easy to book a ticket at a travel agency,
shopping and paying your bills at the comfort of your own home. Everything has become
possible because of the development of programming languages including Java.
Java is an object-oriented programming language that is used in a distributed
environment on the internet. It is a high-level language that is easy to understand. It is
popularly used in console Graphic User Interface(GUI) web and mobile applications,
game development and embedded system.
6
For some basic household electronic devices such as tv, washing machine, air-condition
units and a lot more, Java program has played a part.
Java is a computer-based program language invented by James Gosling and Sun
Microsystems(later acquired by Oracle) in 1991. His single motto while creating a
language is, “Write once, run anywhere.” It means code must be written only once but
could be used anywhere.
They name the language, “Oak” and later change to “Green” then to “Java Coffee” which
was named after the coffee in Indonesia and finally to “Java” in 1995.
There are three (3) editions of Java you can choose from based on your preference.
Java SE (Java Platform Standard Edition):- It has concepts for developing
software for Desktop based (standalone) CUI (command user interface) and GUI
(graphical user interface) applications, applets, database Interaction application,
distributed application, and XML parsing applications.
Java EE (Java Platform Enterprise Edition):- It has concepts to develop software
for Web applications, Enterprise applications, and Interoperable applications. These
applications are called high-scale applications. Some examples are:- banking and
insurance-based applications.
Java ME (Java Platform Micro Edition):- It has concepts to develop software for
consumer electronic devices means embedded systems, like mobile and electronic level
applications. Java ME was popular for developing mobile gaming applications. This
edition was called micro because these edition programs are embedded in small chips.
The program embedded in the chip is called micro (small).
Java is an object-oriented programming language based on C and C++. However, it is
improved and simplified to solve errors in programming.
Java files are converted to bit code format using a compiler and then executed by a java
interpreter.
The whole java code is run on the Java Virtual Machine (JVM) which provides a runtime
environment.
The main concepts of java are methods and classes. A method is a block of code that
performs a task only when it is called. Example: While watching tv, you use a remote to
change channels. Each button on the remote performs a different task. Methods in java
are the same.
A group of methods make a class. Classes are used to organize code just how fruits and
vegetables and other products are divided into different sections in a supermarket
7
Java features:
1. Simple syntax and is very easy to understand and learn.
2. Java language is robust. It eliminates errors that occurs in the C and C++ languages.
3. also has a feature like garbage collectors and exception handling. This makes java
unique.
4. It is platform independent. Here, compilation happens in bytecode, and because of
java can run in any machine.
5. It is a very secure language as it contains no virus.
6. Multithreading -it helps java to multitasking. It is a portable language and can run in
any platform. Data type size are also set permanently.
so it has fix size of code.
7 . Java is not as fast as C and C++ but provides higher performance than any other
language.
Object Oriented Programming (OOPs concept) in Java
Java has 4 concepts namely:
1. Abstraction
- means showing the relevant information that is need for a task.
2. Encapsulation
- makes the java code secure. Data is stored within the classes and it it not easy to access
the data.
3. Inheritance
- the attributes and characteristics of one class can be inherited by another class. It
makes coder take less time to create the code.
4. Polymorphism
--using the same method for different tasks
In java, we can use the same object or variable in two different places where their tasks
will differ.
In java, we use objects and classes related to the real world that makes it easier to read
and understand.
Java Development Kit (JDK) Installation
Step 1. Key in jdk download in the search bar and click the hyperlink.
8
Step 2. For windows installation, select Windows, x64 installer
Step 3. Click the file to proceed with the installation. Click Next.
9
Step 5. Java will be installed in your program files by default. If you wish to change the
directory of the installation folder, click the Change button. Otherwise, click Next.
10
Installing Apache Netbeans.
Step 1. Type in java download at the search bar and click the hyperlink.
Step 2. You’ll be redirected to the java download page. Click download.
Step 3. From the list of available installers,
11
Step 4. Open the downloaded file. Click next to proceed installation
12
Step 5. Tick the checkbox to accept terms and conditions.
Step 6. Set your preferred location where to install Apache Netbeans. Click the next
button.
13
Step 7. To automatically check for updates for installed, the checkbox is ticked by
default. Click the install button.
Step 8. Wait for the installation process until the figure below is displayed. Click finish
and your Apache Netbeans software is ready to use.
14
The Java Integrated Development Environment (IDE)
To familiarize yourself with the Java IDE, follow the following steps.
Step 1. Launch the application by typing Apache Netbeans IDE at the search bar. This
will display options about the program.
Step 2. This will display the start-up page and the default set up for the application
15
Apache Netbeans components and their functions:
1. Title bar – it displays the name of the application.
2. Menu bar and pull down menus – it consists of all available menus which offer
several options that a user can choose from.
3. Tool bar – It displays icons for most commonly used tasks. It displays the most
frequently used commands.
16
4. Project Explorer Window – It displays the different applications created in
Netbeans which makes it easier for users to navigate them at any time.
5. The Code Editor Window – It serves the working area where the user write
Java codes for application.
17
6. Graphical User Interface (GUI) – It is a workspace where the user can build
GUI in Netbeans. It has two views namely Source view and Design view. Design
view enables you to layout forms by clicking and dragging components into it
while Source view enables you to write your java codes.
7. The Palette – It displays all available components to create the GUI.
18
8. The properties window – It displays possible options to manipulate each
component in Netbeans
Programming your first Java Application
Step 1. Click the File Menu. Select New Project in the pull-down or press Ctrl+Shift+N
on your keyboard.
19
Step 2. Select Java Application from the Projects list.
Step 3. Write the project name, My_first_java_application then click finish.
20
Step 4. Notice how the title bar, project name and the codes where set using the
project name you use.
The code window:
In java programming, each line of code must be inside a class. In the above figure,
note that we name it My_first_java_application. Remember that classes should
start with an uppercase first letter.
Java codes are case sensitive. Thus, “My_application” and “MY_APPLICATION”
mean differently.
The main method.
In every java code, the main method is a program requirement making it part of
every java application program.
21
For now, just remember that every Java program has a class name which must
match the filename, and that every program must contain the main() method.
System.out.println()
Inside the main() method, we can use the println() method to print a line of text to
the screen:
Note: The curly braces {} marks the beginning and the end of a block of code.
System is a built-in Java class that contains useful members, such as out, which is
short for "output". The println() method, short for "print line", is used to print a
value to the screen (or a file).
Don't worry too much about System, out and println(). Just know that you need
them together to print stuff to the screen.
You should also note that each code statement must end with a semicolon (;).
Print()
Output:
22
The print() function does not insert a new line compared to println().
Using simple mathematical calculations using println() function.
Output:
Direction: Satisfy the requirement of the following.
Create a java application that will satisfy the requirement of the following:
1. Print any letter.
2. Print any number.
3. Print a word or a sentence.
4. Display the sum, difference, product, and quotient of two numbers using println()
function.
23
1. Name the parts of Java IDE and define their functions.
2. Compare Java IDE to other programming IDEs (E.g. Visual Basic, Python, etc)
Multiple Choice: Choose the letter of the correct answer that referred to the
statements below.
1. Which of the following Java Netbeans IDE parts displays the tools used for
commonly used tasks?
a. Title bar
b. Menu bar
c. Tool bar
d. Toolbox
24
2. Which of the following Java edition is used when the user wants to create
a mobile application?
a. Java SE
b. Java ME
c. Java EE
d. Java CE
3. The following are Java features except
a. Operator overloading
b. Platform independent
c. Exception handling
d. Multi-threading
4. The following are Java names except
a. Oak
b. Green
c. Red
d. Java Coffee
5. Which of the following is NOT a Java concept?
a. Inheritance
b. Abstraction
c. Encapsulation
d. Data Overloading
1.
2.
3.
4.
5.
C
B
A
C
D
25
Note: Answers may vary.
Output:
You don’t have to see the whole staircase, just take the first step.
-Martin Luther
We set goals for ourselves and the only way to achieve them is by taking our first baby
steps. Do you agree with this? Explain your answer.
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
26
References
baeldung. 2019. “Control Structures in Java | Baeldung.” Www.baeldung.com.
January 5, 2019. https://www.baeldung.com/java-controlstructures#:~:text=There%20are%20three%20kinds%20of%20control%20str
uctures%3A%20Conditional.
Davidson, Jerome. 2021. “A Beginner’s Guide to Java Selection Statements.” MUO.
July 22, 2021. https://www.makeuseof.com/java-selectionstatements/#:~:text=Selection%20statements%20are%20a%20program%20co
ntrol%20structure%20in.
“Java Editions & Concepts - Java SE/EE/ME/FX.” 2019. Www.knowprogram.com.
December 3, 2019. https://www.knowprogram.com/java/javaeditions/#:~:text=Java%20editions.
Writer: Mr. Raffy C. Escarda
Illustrator: Mr. Raffy C. Escarda
Layout Artist:
Language Editors: Ms. Maria Jasmin J. Tampes, English Teacher and
Mrs. Maricar Oriarte, HT III, PCSHS
Reviewer: Ms. Maria Allen B. Secretario , Physics/Robotics Teacher, PCSHS
Validator: Mr. Paul Ryan R. Quiogue, Asst. Principal
Management Team: Mr. Charlie O. Fababaer, Principal III, PCSHS
Mrs. Ada Agon, TLE Supervisor
Mrs. Maria Evalou Agustin, Schools Division Superintendent,
DEPED-Division of Pasig City
27
28
29
Download