Applying Basics of Java Language: Lesson
Applying Basics of Java Language: Lesson
Applying Basics of Java Language: Lesson
https://pixabay.com/vectors/computer-desktop-workstation-office-158675/
Image by OpenClipart-Vectors from Pixabay
Introduction:
Let Us Study
a
History of Java
2
What is Java Technology?
As a programming language
As a development environment
An application environment
A deployment environment
Garbage Collection
3
Java garbage collection is the process by which Java programs
perform automatic memory management. It means the programmer does
not need to explicitly mark objects to be deleted. The garbage collection
implementation lives in the JVM. Each JVM can implement garbage
collection however it pleases; the only requirement is that it meets the
JVM specification.
4
Dissecting a Java Program
Below is an example of a java program where its output
“Hello world” is printed on the screen. Make sure to notice each line
of the code and its explanation. It is case sensitive so make sure to
notice the capital letters in the code.
Where:
Line 1 –Java programs must have at least one class declaration
that is defined.
Indicates the declaration of the name of the class which
is Hello.
class – defines the behaviors and characteristic of an
object
public- an access specifier which indicates that class
Hello is accessible to other classes from other packages
(packages are a collection of classes)
{ A left brace indicates the beginning of the body of a
class declaration
Line 2- Blank lines can be used so that programs are easier to
read.
Line 3,4,5- Indicates a multiline comment. It is not part of the
program itself but used for documentation purposes.
A comment is indicated by delimiters /* and */ is
ignored by the Java compiler and are treated as comments.
(There will be no effect on the program)
Line 4- comment within the delimiters
Line 6- Starting point of a Java application. Indicates the name
of one method in Hello which is the main method
Line 7- Another way to write a comment //. Again, this is
ignored by the Java compiler and is treated as comments.
Line 8- Command that prints the text enclosed by quotation on
screen
Line 9- The right brace ends the main method.
5
Line 10- The right brace ends the class method.
You can place the opening curly brace in line with the statement,
Or next in line:
6
Primitive Data Types
Name or
Type Integer Length Range
-9,223,372,036,854,775,808 to
long 64 bits -263 to 263 -1 9,223,372,036,854,775,807
Example
3.14 //A simple floating-point value (a double)
6.02E23 //A large floating-point value
2.718F //A simple float size value
123.4E+306D //A large double value with redundant D
7
3. Characters such as char are symbols in a character set that
are similar to letters and numbers.
Example
char letterA = 'A‘ //The letter A
Declaring a Variable
To declare a variable:
Ex. <data type> <name> [=initial value];
8
Let Us Practice
Direction: Unscramble the words below to get the exact word/s per item.
Use the given clues as your guide. Write your answers on your activity
notebook or any separate sheet and mark “ACTIVITY 1.1” at the top
before answering.
9
Let Us Practice
Direction: Explain the following in your own words. Write your answers on
your activity notebook or any separate sheet and mark “ACTIVITY 1.3” at
the top before answering.
4 System.out.println____________;
5 _______out.println___________;
6 ______
7 _____
Let Us Assess
ITEM IDENTIFICATION
Direction: Read each item carefully and select the correct phase from
the box that corresponds to the definition. Write your answers on your
activity notebook or on any separate sheet and mark “Let Us Assess” at the
top before answering.
Let Us Enhance
Let Us Reflect
Let Us Enhance
}
}