Title: CS1101X DG2
1CS1101X DG2
2INTRODUCTION
- My name is Johannes Ardiant Harlie, 3rd year
student majoring in Computer Engineering. - You can call me Jo.
- e-mail johannes_at_nus.edu.sg
- SoC e-mail johannes_at_comp.nus.edu.sg
- Consultation virtually 24hrs ? as Ill check my
e-mails regularly
3- Its time to introduce yourself ?
4DISCUSSION OUTLINE
- Short introduction
- Clarify some admin matters
- CourseMarker
- Lectures Revision (30 mins)
- Discussion of Questions
- Review of Trial Lab
- Any other business
5ADMINISTRATIVE MATTERS
- The discussion will be divided into 2 parts
- First one hour short review of previous lecture,
discussion of tutorial questions, explanation
solution of labs questions - Next hour those who still have queries or
unclear with some concepts, can stay back for
consultation ?
6WHAT DO I EXPECT FROM YOU?
- Ill send you some questions to be prepared
before coming to this discussion session. So
please prepare to answer those questions since
Ill ask some of you to present your answer to
the class. - ASK QUESTIONS if you dont understand! Thats
what this discussion is for.
7What do you expect from me?
8COURSEMARKER
- Make sure that youve installed CM in your
computer since the first lab will be out
tomorrow. - Further info from this site http//www.comp.nus.e
du.sg/cmarker/ - Any difficulties in installation?
9OBJECT ORIENTED PROGRAMMING
- Whats object oriented programming?
- programming paradigm that uses "objects" and
their interactions to design applications and
computer programs (from Wikipedia) - Visualization of object oriented programming
- Car and wheel paradigm
10- Whats the different between class and object?
- An object is a thing, both tangible and
intangible. Account, Vehicle, Employee, etc. - To create an object inside the computer program,
we must provide a definition for objectshow they
behave and what kinds of information they
maintain called a class. - An object is called an instance of a class.
11- Concept of message, method, and argument
- To instruct a class or an object to perform a
task, we send a message to it. - For a class or and object to process the message
it receives, it must posses a matching method. - Class method a method defined for a class
- Instance method a method defined for an object.
- A value we pass to an object is called an
argument of a message.
12- Instance data values and class data values
- An instance data value is used to maintain
information specific to individual instances. For
example, each BankAccount object maintains its
balance. - A class data value is used to maintain
information shared by all instances or aggregate
information about the instances.
13- Inheritance, superclasses, and subclasses
- Inheritance is a mechanism in OOP to design two
or more entities that are different but share
many common features. - Features common to all classes are defined in the
superclass. - The classes that inherit common features from the
superclass are called subclasses. - We also call the superclass an ancestor and the
subclass a descendant.
14GETTING STARTED WITH JAVA
- Object declaration
- Object creation
Customer customer Student jan, jim,
jon Vehicle car1, car2
customer new Customer( ) jon new
Student(John Java) car1 new Vehicle( )
Examples
15- Program Components
- Comments
- Import statement
- Class declaration
16Comment
/ Chapter 2 Sample Program Displaying a
Window File Ch2Sample2.java / import
javax.swing. class Ch2Sample1 public
static void main(String args)
JFrame myWindow myWindow new JFrame(
) myWindow.setSize(300, 200) myWindow.setTit
le(My First Java Program) myWindow.setVisible
(true)
Import Statement
Class Declaration
17- Edit-compile-run cycle
- Type in the program using an editor and save the
program into a file. This file is called a source
file - Compile the source file. The result is called
bytecode file - Execute the bytecode file. Java interpreter will
go through bytecode file and execute instructions
in it.
18NUMERICAL DATA
19 20- Important concept
- Increment and Decrement
double r 8.32 double s s 2
r-- System.out.println("r "
r) System.out.println("s " s)
double r 8.32 double s s 2
--r System.out.println("r "
r) System.out.println("s " s)
21- Type Casting
- Explicit type casting
- using this syntax
- ( ltdata typegt ) ltexpressiongt
- example
- (float) x / 3
- (int) (x / y 3.0)
- Implicit type casting
- double x 3 5 //promotion is ok
- int x 3.5 //demotion is not allowed
22 23DISCUSSION OF SELECTED QUESTIONS
- Q.1
- Q.2.1, -.2, -.13, -.15
- Q.4
- Q.5.a, -.b
- Q.6
- Q.7
24REVIEW OF TRIAL LABS
- // CS1101 (AY2007/8 Semester 1)
- // Trial lab
- // Cube.java
- import java.util.
- public class Cube
- public static void main(String args)
- Scanner scanner new Scanner(System.in)
- System.out.print("Enter length ")
- int length scanner.nextInt()
- System.out.print("Enter width ")
- int width scanner.nextInt()
- System.out.print("Enter height ")
- int height scanner.nextInt()
25NEXT LAB?
- Comprises of 4 easy tasks
- Will be released on 28 August 2007, Tuesday,
2359 - Advise start doing your lab as soon as possible!
26