Introduction to
Java Programming
BY: ALJOHN S. MARILAG
What is Computer Programming?
Computer programming is the process of writing
code to facilitate specific actions in a
computer, application or software program,
and instructs them on how to perform.
Computer programmers are professionals that
create instructions for a computer to execute by
writing and testing code that enables
applications and software programs to operate
successfully.
What is Java Programming?
Java is a high-level, class-based, object-oriented
programming language that is designed to have as
few implementation dependencies as possible. It is a
general-purpose programming language intended to
let programmers write once, run anywhere (WORA),
meaning that compiled Java code can run on all
platforms that support Java without the need to
recompile. Java applications are typically compiled to
bytecode that can run on any Java virtual machine
(JVM) regardless of the underlying computer
architecture.
What is Java Programming?
Java was originally developed by James
Gosling at Sun Microsystems. It was released in
May 1995 as a core component of Sun
Microsystems' Java platform.
Oracle Corporation is the current owner of the
official implementation of the Java SE platform,
following their acquisition of Sun Microsystems
on January 27, 2010.
Java Virtual Machine (JVM)
Allows developers to create Java
programs that can be executed by the
Java Runtime Environment (JRE).
When you run the Java program, Java
compiler first compiles your Java code to
bytecode. Then, the JVM translates
bytecode into native machine code (set
of instructions that a computer's CPU
executes directly).
Java Development Kit (JDK)
Allows developers to create Java
programs that can be executed by the
Java Runtime Environment (JRE).
Java Runtime Environment (JRE)
JRE (Java Runtime Environment) is a
software package that provides Java
class libraries, Java Virtual Machine
(JVM), and other components that are
required to run Java applications.
Java Virtual Machine (JVM)
Relationship between JVM, JRE,
and JDK.
Integrated Development
Environment (IDE)
A software used by a developer so
that they can easily code in a
certain programming language. IDE
has tons of features that makes
programming easier.
Java Variables and
Literals
BY: ALJOHN S. MARILAG
Java Variables
A variable is a location in memory
(storage area) to hold data.
To indicate the storage area, each
variable should be given a unique
name (identifier).
Rules for Naming Variables in
Java
Java is case sensitive. Hence, age and
AGE are two different variables.
Rules for Naming Variables in
Java
Variablesmust start with either a letter
or an underscore, _ or a dollar, $ sign.
Rules for Naming Variables in
Java
Variable names cannot start with
numbers.
Rules for Naming Variables in
Java
Variable names can't use
whitespace.
Rules for Naming Variables in
Java
Here, is we need to use variable
names having more than one word,
use all lowercase letters for the first
word and capitalize the first letter of
each subsequent word. For
example, myAge.
Rules for Naming Variables in
Java
When creating variables, choose a
name that makes sense. For example,
score, number, level makes more sense
than variable names such as s, n, and l.
If you choose one-word variable
names, use all lowercase letters. For
example, it's better to use speed rather
than SPEED, or sPEED.
Java Data Types
As the name suggests, data types
specify the type of data that can
be stored inside variables in Java.
This means that all variables must be
declared before they can be used.
Java Data Types
1. boolean – true/false
2. int – integer/whole numbers
3. double – decimal numbers
4. String – text
Java Literals
Literals are data used for
representing fixed values. They can
be used directly in the code.
Java Literals
1. Boolean Literals
2. Integer Literals
- An integer literal is a numeric value(associated with
numbers) without any fractional or exponential part.
3. Floating-point Literals
- A floating-point literal is a numeric literal that has
either a fractional form or an exponential form.
4. Character Literals
- Character literals are unicode character enclosed
inside single quotes.
5. String literals
- A string literal is a sequence of characters
enclosed inside double-quotes.