Download presentation
Presentation is loading. Please wait.
Published byNora Briggs Modified over 9 years ago
1
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang tung_hx@icu.ac.kr Lecture No. 8
2
Review
3
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
4
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
5
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, …
6
XuanTung Hoang 6 Java Language: Things to remember One file = one class File name = class name Compile: javac Run: java 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
7
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 “.”
8
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)
9
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 variabl es (no return type, name = class name) Get/set methods Why main method should be static?
10
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 3)) new operator
11
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++) ; { … } …
12
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.