Introduction
to
Java Language
Rueda Street, Calbayog City, Samar, Philippines | +63 (055) 533 9857 | main@[Link] | [Link]
Let’s Hit These:
• Create, compile, and run Java programs
• Use Java programming style and
document programs properly
• Develop Java programs using TextPad
What is Java?
What is Java?
• a programming language and
a platform
• Platform: Any hardware or software environment in which a
program runs
Types of Java Application
Application
• Desktop Applications such as acrobat reader, media player, antivirus, etc.
• Web Applications such as [Link], [Link], etc.
• Enterprise Applications such as banking applications.
• Mobile
• Embedded System
• Smart Card
• Robotics
• Games, etc.
Java Platforms/Editions
Java Platforms / Editions
• Java SE (Java Standard Edition)
Java programming platform
Includes Java programming APIs such as
[Link], [Link], [Link], [Link],
[Link], [Link] etc.
The applications can run standalone or as
applets running from a Web browser.
Java Platforms / Editions
• Java EE (Java Enterprise Edition)
Enterprise platform
mainly used to develop web and
enterprise applications
Java Platforms / Editions
• Java FX
used to develop rich internet applications.
It uses a lightweight user interface API.
Requirements for Running a Java Program
Requirements for Running a Java Program
• Install the JDK
• Set path of the jdk/bin directory
• Create the Java program
• Compile and run the Java program
Java Development Kit (JDK)
• a software development environment which
is used to develop Java applications
and applets.
Java Development Kit (JDK)
Java Development Tool
• software that provides an integrated
development environment (IDE) for
developing Java programs quickly
• (e.g., NetBeans, Eclipse, and TextPad)
Creating a Simple Java Program
Simple Java Program
Class
Naming a Class
Main Method
• In order to run a class, the class must contain a method named
main. The program is executed from the main method.
Java Output
• print() - prints string inside the quotes.
• println() - prints string inside the quotes similar
like print() method. Then the cursor moves to the
beginning of the next line.
• printf() - it provides string formatting
Performing Output with [Link]
• [Link]
known as the standard output object.
allows a Java applications to display
information in the command window
• [Link]
displays (or prints) a line of text in the
command window
[Link]()
Displaying Text with printf
• [Link] method
f means “formatted”
displays formatted data
consist of fixed text and format specifiers
Printing in Uppercase
Example:
Displaying a Single Line of Text with Multiple Statements
Example:
Displaying a Single Line of Text with a Single Statement
Escape Characters / Escape Sequences
signal an alternative interpretation of a series
of characters
character preceded by a backslash (\)
Escape Characters / Escape Sequences
Statement Terminator
• Every statement in Java ends with a semicolon (;), known as
the statement terminator.
Keywords/Reserved Words
Blocks
• A pair of curly braces in a program that groups the program’s
components
• each block begins with an opening brace ({) and ends with a
closing brace (})
Block Styles
• There are two popular styles:
1. next-line style
2. end-of-line style
Comments
Comments
• It documents what the program is and how it is constructed
• help programmers to communicate and understand the program
Single-line comment - comments are preceded by two
slashes (//)
block comment or paragraph comment or multi-line
comment - enclosed between /* and */
Example Comments
Appropriate Comments in a Program
Special Symbols
Proper Indention and Spacing
• A consistent indentation style makes
programs clear and easy to read, debug, and
maintain.
• Indentation
• used to illustrate the structural relationships between
a program’s components or statements.
Proper Indention and Spacing
• Indent each subcomponent or statement at least
two spaces more than the construct within which
it is nested.
• A single space should be added on both sides of a
binary operator
Proper Indention and Spacing
Programming Errors
Programming Errors
Programming Errors
Programming Errors
Example: