Reviewer in JAVA by GRAPE
“INTRO TO JAVA”
JAVA – high level, modern programming language
- Designed by Sun Microsystems in early 1990s
- Currently owned by Oracle
- Originally designed for Cable TV Switchboxes
- Founded by James Gosling
- Project was code-named Green by Nikalus Wirth (Inventor of Pascal)
- Initiated by James Gosling, Mike Sheridan, Patrick Naughton in June 1991 called the Green Team
- Called Greentalk by James Gosling with the file extension .gt
- Called Oak after
- Named Java by Chris Warth after naming constraints.
JAVA Technology can:
Be a Programming Language – designed to operate at high levels
Be a Development Environment – provides a large collection of tools
Use Technology Applications – general-purpose programs that can run on any machine
Advantages of using Java
Object-oriented – to function in complex environments
Portable and Platform Independent – Can run on any system using a special file called bytecodes
Dynamically Linked – Codes are linked at a runtime
Multithreaded – can contain multiple threads of execution
Garbage-Collected – Contains its own garbage-collection feature
Interpreted – Supports cross-platform code through use of Java bytecode
Characteristics of Java
Java is Simple
Java is Secure
Java is Robust
Java is Case-Sensitive
Components of Java
Java Virtual Machine (JVM) – refers to the virtual machine that serves as the base for the Java platform
Java Application Program Interface (API) – refers to the collection of readymade software components
What can you do with Java
Applets – are programs that adhere to certain conventions
Applications – are stand-alone programs that run directly on the Java platform
“BASIC CONCEPTS OF JAVA”
Syntax
- Basic of the language, all the main rules, commands, construction to write programs
- Rules for combining words into statements
Grammar
- Rules for interpreting the meaning of statements
- Allows program to properly execute
Classes
- Considered as the blueprint
Statements
- Specify actions performed during a program’s execution
- Contains the parts necessary for a class
Identifiers
- Used to label variables, statements, classes, and other parts of a program
- Serves as the way for a program to identify its task
Keywords
- Also called reserved words
- Represent components for a Java program for it to execute properly
- Boolean, byte, short, char, double, int, long, float, void
Variables
- Also called fields in Java
- Stores data for processing
- Items of data used to store the state of objects
Int, double, String, char, boolean
Literals
- Denotes a constant value in a program
- Can be used across different methods and classes
- Useful for values used in mathematical expressions
Types of Literals
Integer Literals – denotes digits that are whole numbers
Floating-point Literals – denotes digits that contain a fractional or decimal point
Character Literals – denotes single characters
Boolean Literals – can only be denoted by true or false
String Literals – denotes sentences or phrase
Primitive Operators
Operand - value used on either side of an operator
Addition – the plus sign operator, adds together two values
Subtraction – the dash sign operator, subtracts one value from another
Multiplication – the asterisk operator, multiplies two values
Division – the forward slash operator, divides one value by another
Modulo – the percentage operator, just like division but only gets the remainder
Data Types
- Used to determine the values a variable may contain
- Determines the operation that can be performed on the variable
Primitive Data Types – are basic, built-in data types on most programming language
o Byte, short, int, long, float, double, Boolean, char
Constructed Data Types – created by a programmer using primitive data types
Numeric Data Types – are used for numbers or digits
o Byte – 8-bit
o Short – 16-bit
o Int – 32-bit non decimal
o Long – 64-bit non decimal
o Float – 32-bit decimal
o Double – 64-bit decimal
Character Data Types – are used for characters. marks, and symbols
The Boolean Data Type – 1-bit data type used for conditional statements
Types of Variables
Primitive Variables – are composed of primitive data types
Reference Variables – are variables that store an address
Constants – used to represent values that never changes
Increment or Decrement – operator that provides a more convenient way to increase or decrease value
Increment – increases value of a variable by one
Decrement – decreases value of a variable by one
Prefix – Increments the variable’s values and uses the new value in the expression
Postfix – the variable’s value is first used in the expression and is then increased
Strings
- an object that represents a sequence of characters
- used for storing text
String Concatenation – forms a new String that is the combination of multiple strings
Java Comments
- are the statements in a program that are not executed by the compiler but the interpreter
Single Line Comment – starts with two forward slashes
Multi-Line Comment – used to comment multiple lines of codes
Documentation Comment – just like multi-line but they generate external documentation of your code
Java Control Structure
- Decide which task-based statement, block, or code is executed based on a given criteria
- Structured Statements that allows to change the way statements in a program is executed
Decision Control Structure – allow control over specific sections of code
Repetition Control Structure – allow repeated execution of specific sections of code
If Statement Structure
- One of the most frequently used conditional statements
Left Bracket | < – less than
Right Bracket | > – greater than
Exclamation Mark and Equal Sign | != – not equal to
Double Equal Sign | == – equal to
Left Bracket and Equal Sign | <= – less than or equal to
Right Bracket and Equal Sign | >= – greater than or equal to
If-else Statement Structure
- Used to execute a statement for a corresponding Boolean Value
- Useful for parts of a program where it needs to execute two separate tasks
Nested If Statements Structure
- Used when more than two conditional statements are involved
Else if Statements Structure
- Used to check multiple conditions
Logical Statements
- Can be used to combine multiple conditions
“And” Operator
- Denoted by two ampersands (&&)
- Checks if both conditions is true
“Or” Operator
- Denoted by two vertical bars (||)
- Checks if any of the conditions Is true
Switch Statements Structure
- Tests a variable for equality against a list of values called Case
- Can evaluate more than two different conditional statements
Default Statements – can be used for performing a task when none of the case is matched
While Loops Structure – basic repetition control structure that repeats statements as a conditional statement
For Loops Structure – provides a compact way to iterate over a range of values used in loops
Do-While Loops Structure – evaluates the statement’s condition at the end of the structure instead of the beginning
Branching Statements – statements that specifically dictate the flow of control within a program
Break Statement – causes the termination of a loop or initiates an exit from a decision control structure
Continue Statement – forces the next iteration of a loop to take place using a set of condition
Return Statement – exits the current method
Java Arrays
- A data structure that can be used in Java that is composed of a sequence of memory locations for storing data
- Composed of elements that contains values of a common data type, such as integers, characters, and strings
- Any collection of items
Arrays
- is a collection of variable of the same type
- the elements are ordered and each has a specific constant position, called an Index
Enhanced For Loop
- used to traverse elements in arrays
- declares a variable of a type compatible with the elements of the array being accessed
Declaring Arrays
ARRAY NAME – will be used to call the entire group of elements
DATA TYPE – will ensure that the collection of elements are of a single data type
PAIR OF BRACKETS ({}) – lets Java identify that the declared object in the program is an array
Instantiating Arrays
- Creates an instance of a declared array in Java
Accessing Array Elements
Subscript – number used to access the elements within the array
- Can be accessed via its Subscript
Multidimensional Arrays
- Arrays that contain other arrays
- Two-dimensional array known as Data Table
The Backlash (\) Symbol
- Used to insert special characters in Java
- Used to execute certain commands in strings values
Statements used to display Strings in Java
System.out.print() – used to print strings in a single line without line breaks for each consecutive statement
System.out.println() – used to print strings with a line break at the end
Printing
- Method or task of displaying text in a Java program