Java database programming with jdbc(java programming tutorials)
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
-
Upload
nora-briggs -
Category
Documents
-
view
217 -
download
0
description
Transcript of Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
![Page 2: Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.](https://reader036.fdocuments.us/reader036/viewer/2022082510/5a4d1b2c7f8b9ab05999959d/html5/thumbnails/2.jpg)
Review
![Page 3: Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.](https://reader036.fdocuments.us/reader036/viewer/2022082510/5a4d1b2c7f8b9ab05999959d/html5/thumbnails/3.jpg)
XuanTung Hoang 3
Introduction to Computers Computer :
Hardware 6 logical units: Input, output, CPU, ALU, memory, secondary
storage Software:
Computer programs that command computer hardware to for solving computing tasks
Programming languages: For writing computer software Machine language assembly language High-level
languages High level language needs translator or compiler
![Page 4: Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.](https://reader036.fdocuments.us/reader036/viewer/2022082510/5a4d1b2c7f8b9ab05999959d/html5/thumbnails/4.jpg)
XuanTung Hoang 4
Java Programming Language A high level language
Use both interpreter and compiler Compiler: Source code byte code Interpreter: byte code machine language
J2SE Java Platform JRE – Java Runtime Environment:
Java Virtual Machine (JVM): interpreter, java.exe Libraries
JDK – Java Development Kits JRE Compiler: javac.exe Library + other tools
![Page 5: Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.](https://reader036.fdocuments.us/reader036/viewer/2022082510/5a4d1b2c7f8b9ab05999959d/html5/thumbnails/5.jpg)
XuanTung Hoang 5
Java Language: Things to remember Java is case-sensitive Statements end with “ ; ” Comments: //, /* … */ Block of code: { … } Array: [ ] Keywords: class, this, public, private, static, final,
int, double, float, short, long, boolean, true, false, if, for, while, do, switch, case, break, continue, new, return, …
![Page 6: Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.](https://reader036.fdocuments.us/reader036/viewer/2022082510/5a4d1b2c7f8b9ab05999959d/html5/thumbnails/6.jpg)
XuanTung Hoang 6
Java Language: Things to remember One file = one class
File name = class name Compile: javac <java file name> Run: java <class name with main method> Identifiers (class/method/variable name):
Comprise of: lower case chars (a – z), upper-case char (A – Z), numeric char (0 – 9), _ int number_Of_people1 = 0; // valid int people@home = 5; // invalid
![Page 7: Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.](https://reader036.fdocuments.us/reader036/viewer/2022082510/5a4d1b2c7f8b9ab05999959d/html5/thumbnails/7.jpg)
XuanTung Hoang 7
Java Language: Important concepts Data type:
Primitive data type: int, short, long, float, double, boolean, char, byte Built-int data type
class (object/reference): Provided by class libraries (E.g.: String) or made by users
Object: instance of a class Created with new Accessed through reference
Using “.”
![Page 8: Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.](https://reader036.fdocuments.us/reader036/viewer/2022082510/5a4d1b2c7f8b9ab05999959d/html5/thumbnails/8.jpg)
XuanTung Hoang 8
Java Language: Important concepts Variable:
4 properties: Name: identifier Type: Primitive data type or reference (class, object reference) Size: depends on type Value: specific value in a certain context
Two type of variables Instance variable: member of a class
Non-static instance variable is associated with a specific object Static instance variable is associated with a class (do not need a
specific object) Local variable
Declaration and initialization Non-static instance variable can ONLY be initialized in constructor
Scope of a variable Variable can be shadowed by other variable (with the same name)
![Page 9: Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.](https://reader036.fdocuments.us/reader036/viewer/2022082510/5a4d1b2c7f8b9ab05999959d/html5/thumbnails/9.jpg)
XuanTung Hoang 9
Java Language: Important concepts Class:
Instance variables Static/non-static Constants: define with final
Methods Static/non-static 3 ways to call a methods Static methods cannot “directly call” non-static methods Return type and return expression agreement Constructors: special method for initializing object’s instance
variables (no return type, name = class name) Get/set methods Why main method should be static?
![Page 10: Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.](https://reader036.fdocuments.us/reader036/viewer/2022082510/5a4d1b2c7f8b9ab05999959d/html5/thumbnails/10.jpg)
XuanTung Hoang 10
Java Language: Operator Arithmetic: + , - , * , / , %, ++, --, +=, -=, *=, /=,
%= For integers For floating point numbers
Relational: >, <, >=, <=, ==, != Be careful when using = = with floating point numbers
Logical: &, &&, |, ||, ^^, ! !(2 >4) (3 < 4) && (!(4>3))
new operator
![Page 11: Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.](https://reader036.fdocuments.us/reader036/viewer/2022082510/5a4d1b2c7f8b9ab05999959d/html5/thumbnails/11.jpg)
XuanTung Hoang 11
Java language: Control statements if, if … else switch … case
Only for integer expression for, while, do … while
Empty statement can be allowed Be careful when putting “;”
if( x < 2) ; { … } for (int k ; k < 10; k++) ; { … } …
![Page 12: Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.](https://reader036.fdocuments.us/reader036/viewer/2022082510/5a4d1b2c7f8b9ab05999959d/html5/thumbnails/12.jpg)
XuanTung Hoang 12
Arrays Declaration / creation / initialization Array of primitive type Array of object references
When an array of references is created, each element of the array will be a reference that is pointing to null
Multi dimensional array Array of arrays