Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Java Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Java

Java History
-created 1995.
Java Platforms?Editions
-high-level programming, general-purpose, object- 1) Java SE (Java Standard Edition)
oriented, and secure programming language.
-developed by James Gosling (Father of Java) at Sun It is a Java programming platform. It includes Java
Microsystems Inc. in 1991. programming API’s such as java.lang, java.io, java.net,
Green Team- James Gosling, Mike Sheridan, and Patrick
java.util, java.sql, java.math etc.
Naughton.
-In 1995, Time magazine called Java one of the Ten Best 2) Java EE (Java Enterprise Edition)
Products of 1995.
-is formally known as OAK (symbol of strength). It is an enterprise platform which is mainly used to
-In 2009, Sun Microsystem takeover by Oracle
develop web and enterprise applications.
Corporation.
-JDK 1.0 released in January 23, 1996. 3) Java ME (Java Micro Edition)

Principles of Java It is a micro platform which is mainly used to develop


"Simple, Robust, Portable, Platform-independent, mobile applications.
Secured, High Performance, Multithreaded, Architecture
Neutral, Object-Oriented, Interpreted, and Dynamic" 4) JavaFX

It is used to develop rich internet applications. It uses a

Uses of Java
light-weight user interface API.

 Mobile applications (specially Android apps) Java Syntax


 Desktop applications
public class Main {
 Web applications
 Web servers and application servers
public static void main(String[] args) {
 Games System.out.println("Hello World");
 Database connection }
}
Types of Java Applications  Every line of code must be inside a class.
1) Standalone Application  Class names should always start w/ capital letter.
2) Web Application  Java is case sensitive.
3) Enterprise Application  Java file name must match the class name. (ext: .java)
4) Mobile Application  Any code inside the main() method will be executed.
 println()- print a line of text to the screen.
 (//)- comment
Java Variables
 COMPARISON OPERATORS – used to compare two
values.

VARIABLES - are containers for storing data values. Operators Description


== Equal to
!= Not equal
Types of Variables in Java > Greater than
 String - stores text, such as "Hello". String values
< Less than
are surrounded by double quotes
>= Greater than or equal to
 int - stores integers (whole numbers), without
decimals, such as 123 or -123 <= Less than or equal to
 float - stores floating point numbers, with
decimals, such as 19.99 or -19.99
 char - stores single characters, such as 'a' or 'B'.  LOGICAL OPERATORS –used to determine the logic
Char values are surrounded by single quotes between variables or values.
 boolean - stores values with two states: true or Operators Name Description
false. && Logical Returns true if both
Syntax for Declaring a Variable ||
and
Logical or
statements are true.
Returns true if one of the
type variable= value;
statement is true.
! Logical not Reverse the result, return

Java Operators
false if the result is true.

 BITWISE OPERATORS - can be applied to the


 ARITHMETIC OPERATORS –are used to perform integer types, long, int, short, char, and byte.
common mathematical operation.

Operators
+
Description
Add together two values
Data Types
- Subtracts one value from another Primitive Data Types
* Multiply two values -specifies the size and type of variable values, and t has no
/ Divides one value by another additional methods.
% Returns the division remainder  Integer types stores whole numbers, positive or
++ Increment (++x) negative (such as 123 or -456), without decimals.
-- Decrement (--x)  Byte can be used instead of int or other integer
types to save memory when you are certain that
the value will be within -128 and 127.
 ASSIGNMENT OPERATORS –used to assign values to
 Short data type can store whole numbers from -
variables. (=)
32768 to 32767.
Operators Example Same As  Int data type can store whole numbers from -
= x=5 x=5 2147483648 to 2147483647.
+= x+=3 x=x+3  Long data type is used when int is not large enough
-= x-=3 x=x-3 to store the value. End the value with an "L".
*= x*=3 x=x*3  Floating point types represents numbers with a
/= x/=3 x=x/3 fractional part, containing one or more decimals.
%= x%=3 x=x%3  Float data type can store fractional numbers from
&= x&=3 x=x%3 3.4e−038 to 3.4e+038. End the value with an "f”.
|= X|=3 x=x|3  Double data type can store fractional numbers
^= X^=3 x=x^3 from 1.7e−308 to 1.7e+308. End the value with a
>>= x>>=3 x=x>>3 "d":
<<= X<<=3 x=x<<3  A floating point number can also be a scientific
number with an "e" to indicate the power of 10.
Data Types  String Concatenation
-combining string using + operator or .concat() method.
 Special Characters
 Booleans - declared with the boolean keyword and
Escape Character Result Description
can only take the values true or false: \’ ‘ Single quote
 Characters - is used to store a single character. The \” “ Double quote
character must be surrounded by single quotes, like \\ \ Backslash
'A' or 'c’.
 The String data type is used to store a sequence of  Six other escape sequences
characters (text). String values must be surrounded by
double quotes:
Code Result
\n New line
Non-primitive Data Types \r Carriage return
-Non-primitive data types are called reference types
\t Tab
because they refer to objects.
\b Backspace
\f Form Feed
Primitive and Non-primitive Data Types
Differences  Numbers are added. Strings are concatenated.
➢ Primitive types are predefined (already defined) in

Java Math
Java. Non-primitive types are created by the
programmer.
➢ Non-primitive types can be used to call methods to
perform certain operations, while primitive types cannot. -allows to perform mathematical tasks on numbers.
➢ A primitive type has always a value, while non-  Math.max(x,y)
primitive types can be null. -maximum value of x and y.
➢ A primitive type starts with a lowercase letter, while  Math.min(x,y)
non-primitive types starts with an uppercase letter. -minimum value of x and y.
➢ The size of a primitive type depends on the data type,  Math.sqrt(x)
while non-primitive types have all the same size. -returns the square root of x.
 Math.abs(x)
-returns the absolute value of x.

Java String  Math.random()


-returns a random number between 0.0 (inclusive),
and 1.0(exclusive).
String- used for storing text. (Example: “String”)
-string in Java is actually an object, w/c contain Example: Random number between 0 and 100.
method that can perform certain operation on Int randomNum=(int)(Math.random()*101); // 0 to 100
strings.
 length() method- length of string
String txt=”ABCDEFGHIJKLMNOPQRSTUVWXYZ”
System.out.println(“The length of the string is:” Java If…Else
+txt.length());
 toUpperCase() and toLowerCase() Java-Conditional Statements
 indexOf() –position/index (include whitespace).  if – if a specified condition is true.
-Java counts start from zero.  else – if the same condition is false.
 else if – to specify a new condition to test, if the first
String txt=”ABCDEFGHIJKLMNOPQRSTUVWXYZ”
condition is false.
System.out.println(txt.indexOf (“A”));  switch– to specify many alternative blocks of code to
be executed.
Java If…Else
The If Statements
Syntax:
If (condition){
//block of code to be executed if the condition is true
}

The else Statements


Syntax:

If (condition){
//block of code to be executed if the condition is true
}
else{
//block of code to be executed if the condition is false
}

The else if Statements


Syntax:

If (condition1){
//block of code to be executed if the condition is true
}

Fighting!!!
else if(condition2){
//block of code to be executed if the condition is false
}
else{
//block of code to be executed if the condition is false
}

Short Hand If…Else Statements


Syntax:
Variable=(condition)? expressionTrue: expressionFalse;

Goodluck sa mindterm self. Kayamo yan HAAHAHAHA

You might also like