Download JSP คืออะไร - Thaiall.com

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
การโปรแกรมเชิงวัตถุด้วยภาษา JAVA
Keyword & Data Type
มหาวิทยาลัยเนชัน่
http://www.nation.ac.th
http://www.thaiall.com/class
บุรินทร์ รุจจนพันธุ์ .
ปรั บปรุ ง 15 มิถุนายน 2552
49 Java Keywords
abstract boolean
break byte case
(Sorting)
catch char class const continue
default do double else extends
final finally float for goto if
implements import instanceof int
interface long native new
package private protected public
return short static strictfp
super switch synchronized this
throw throws transient try void
volatile while assert
http://www.thaiall.com/class
49 Java Keywords (4
Groups)
short static strictfp transient void
DATA
boolean byte char double final float int long
CONTROL
assert break case catch continue default do else
finally for if return switch synchronized throw
throws try while
OBJECTS
abstract class extends implements import
instanceof interface native new package private
protected public super this volatile
Unused
const goto
http://www.thaiall.com/class
49 Java Keywords (9
1. Access Groups
Modifiers
1/5)
private : Makes a method or a variable
accessible only from within its own
class.
protected : Makes a method or a
variable accessible only to classes in
the same package or subclasses of the
class.
public : Makes a class, method, or
variable accessible from any other
class.
http://www.thaiall.com/class
49 Java Keywords (9
Groups 2/5)
2. Class, Method, and Variable Modifiers
abstract : Used to declare a class that cannot be instantiated, or a
method that must be implemented by a nonabstract subclass.
class : Keyword used to specify a class.
extends : Used to indicate the superclass that a subclass is extending.
final : Makes it impossible to extend a class, override a method, or
reinitialize a variable.
implements : Used to indicate the interfaces that a class will implement.
interface : Keyword used to specify an interface.
native : Indicates a method is written in a platform-dependent language,
such as C.
new : Used to instantiate an object by invoking the constructor.
static : Makes a method or a variable belong to a class as opposed to an
instance.
strictfp : Used in front of a method or class to indicate that floatingpoint numbers will follow FP-strict rules in all expressions.
synchronized : Indicates that a method can be accessed by only one thread
at a time.
transient : Prevents fields from ever being serialized. Transient fields
are always skipped when objects are serialized.
volatile : Indicates a variable may change out of sync because it is used
in threads.
http://www.thaiall.com/class
49 Java Keywords (9
Groups 3/5)
3. Flow Control
break : Exits from the block of code in which it resides.
case : Executes a block of code, dependent on what the switch
tests for.
continue : Stops the rest of the code following this statement
from executing in a loop and then begins the next iteration of
the loop.
default : Executes this block of code if none of the switch-case
statements match.
do : Executes a block of code one time, then, in conjunction with
the while statement, it performs a test to determine whether the
block should be executed again.
else : Executes an alternate block of code if an if test is
false.
for : Used to perform a conditional loop for a block of code.
if : Used to perform a logical test for true or false.
instanceof : Determines whether an object is an instance of a
class, superclass, or interface.
return : Returns from a method without executing any code that
follows the statement (can optionally return a variable).
switch : Indicates the variable to be compared with the case
statements.
while : Executes a block of code repeatedly while a certain
condition is true.
http://www.thaiall.com/class
49 Java Keywords (9
Groups 4/5)
4. Error Handling
catch : Declares the block of code used to handle an
exception.
finally : Block of code, usually following a try-catch
statement, which is executed no matter what program flow
occurs when dealing with an exception.
throw : Used to pass an exception up to the method that
called this method.
throws : Indicates the method will pass an exception to
the method that called it.
try : Block of code that will be tried, but which may
cause an exception.
assert : Evaluates a conditional expression to verify the
programmer’s assumption.
5. Package Control
import : Statement to import packages or classes into
code.
package : Specifies to which package all classes in a
source file belong.
http://www.thaiall.com/class
49 Java Keywords (9
Groups 5/5)
6. Primitives
boolean : A value indicating true or false.
byte : An 8-bit integer (signed).
char : A single Unicode character (16-bit unsigned)
double : A 64-bit floating-point number (signed).
float : A 32-bit floating-point number (signed).
int : A 32-bit integer (signed).
long : A 64-bit integer (signed).
short : A 16-bit integer (signed).
7. Variable Keywords
super : Reference variable referring to the immediate superclass.
this : Reference variable referring to the current instance of an object.
8. Void Return Type Keyword
void : Indicates no return type for a method.
9. Unused Reserved Words
const : Do not use to declare a constant; use public static final.
goto : Not implemented in the Java language. It’s considered harmful.
http://www.thaiall.com/class
boolean, char, byte,
short, int, long
// 1. boolean true of false
boolean b = true;
System.out.println("boolean = "+b);
// 2. character (2 Byte)
char y;
y = 'a';
System.out.println("character = "+y);
// 3. byte -2^7 to 2^7-1 (1 Byte)
byte c;
c = 127;
System.out.println("byte = "+c);
// 4. short -2^15 to 2^15-1 (2 Byte)
short a;
a = 32767;
System.out.println("Short = "+a);
// 5. integer -2^31 to 2^31-1 (4 Byte)
int x;
x = 2147483647;
System.out.println("Integer = "+x);
// 6. long -2^63 to 2^63-1 (8 Byte)
long b;
b = 9223372036854775807L;
System.out.println("long = "+b);
http://www.thaiall.com/class
float, double
// 7. float -3.4e38 to 3.4e38 (4 Byte)
float d;
d = 340000000000000000000000000000000000000f;
System.out.println("float = "+d);
// 8. double -1.7e308 to 1.7e308 (8 Byte)
double e;
e = 17900000000000000000000000000000000000000d;
System.out.println("double = "+e);
http://www.thaiall.com/class
Literals & Casting
float
f = 1.0f, 1.0F
double
d = 1.0, 1.0f
boolean
b = true, false
char
c = (char)70000; = 4464 (0-66535)
byte
b = (byte)300;
error on byte b = 300;
Hexadecimal Literals 0x001, 0xcafe;
error on 0xone, 0xjava
Octal Literals 011, 071
error on 081, 099
char c = 'e', '\u0065' (hex)
error on '\u065', '\u00065', 'aa', "a"
http://www.thaiall.com/class
Convert of Number and
String
String aa = Double.toString(123.45);
String bb = Integer.toString(123);
double cc = Double.parseDouble("123") + 1;
int dd = Integer.parseInt("456") + 2;
String xx = Double.toString(Double.parseDouble("123") + 1);
String yy = Integer.toString(Integer.parseInt("456") + 2);
ข้ อมูลจาก http://yn1.yonok.ac.th/burin/javadocs/api/java/lang/String.html
http://www.thaiall.com/class
String Class
String z ="ThaiAll";
System.out.println("string = "+z);
System.out.println(z.substring(0,4));
// Thai
System.out.println(z.substring(2,5));
// aiA
System.out.println(z.substring(4));
// All
System.out.println(z.toUpperCase());
// THAIALL
System.out.println(z.toLowerCase());
// thaiall
char ar[] = new char[128];
ar = z.toCharArray();
System.out.println((char)ar[0]);
// T
System.out.println(ar[0]);
// T
System.out.println(ar[2] + ar[4]);
// 162 (97+65)
ข้ อมูลจาก http://yn1.yonok.ac.th/burin/javadocs/api/java/lang/String.html
http://www.thaiall.com/class
Argument of Main
// java j0100 abc def
class j0100 {
public static void main(String args[]) {
System.out.println(args.length);
System.out.println(args[0]);
// abc
}
}
http://www.thaiall.com/class
Data Structure
Size
TeraByte Database
GigaByte Table
MegaByte Record
KiloByte Field
Byte Character
BIT
http://www.thaiall.com/class
Relation
Data Type
1 2
a b
Stack Memory
Stack Memory
Heap Memory
c d a=1
4
b = 2
c
int a = 1;
int b;
d
b = a;
a = 2;
int c[]={3};
int d[]= c;
c[0] = 4;
System.out.println(“”+a+b+c[0]+d[0]);
http://www.thaiall.com/class
4