Java by Example

32
234321 Java by Exa mple Created by Ron Begleiter 1 Java by Example Introducing IDE, Eliza, UI, IO and other creatures

description

Java by Example. Introducing IDE, Eliza, UI, IO and other creatures. Developer Needs. Why not use command-line and notepad?. integrated development environment. - PowerPoint PPT Presentation

Transcript of Java by Example

Page 1: Java by Example

234321 Java by Example

Created by Ron Begleiter 1

Java by Example

Introducing IDE, Eliza, UI, IO and other creatures

Page 2: Java by Example

234321 Java by Example

2

Developer Needs

Why not use command-line and

notepad?

Page 3: Java by Example

234321 Java by Example

3

integrated development environment

integrated development environment (IDE) is an application or set of tools that allows a programmer to write, compile, edit, and in some cases test and debug within an integrated, interactive environment.

Page 4: Java by Example

234321 Java by Example

4

Borland’s JBuilder

• Availability: Free (Foundation version)

• Functionality: integrated editor, debugger, compiler, visual designers, wizards, refactorings, code formatting, and much more.

• Supported OS: Windows, Linux, Unix and Mac

• Other Java IDEs: Eclipse, IntelliJ

Page 5: Java by Example

234321 Java by Example

5

JBuilder’s Hands-on

Page 6: Java by Example

234321 Java by Example

6

Java toy example - Eliza

Who is Eliza?Eliza was “born” in the early 1960s in MIT’s

labs. It is viewed as the first intelligent machine. Its creator is Prof. Joseph Weizenbaum.

המשורר דויד אבידן נסע בשנות השבעים . בארה"ב לשוחח עם אליזהIBMלמעבדות

שיחות אלו פורסמו בספרו בשם ''הפסיכיאטר האלקטרוני שלי: שמונה שיחות אותנטיות עם

.'' מחשב

Page 7: Java by Example

234321 Java by Example

7

What’s next?

• We will browse through a few of Java’s basic capabilities and demonstrate how we used them in the toy example;

• We will focus on the collection framework, In\Out processing and User Interfacing (UI).

• Finally, we will raise a few questions.

Page 8: Java by Example

234321 Java by Example

8

Java Collection Framework

Interfaces:

Page 9: Java by Example

234321 Java by Example

9

Java Collection Framework

Implementations:

Page 10: Java by Example

234321 Java by Example

10

Collections in Eliza

Page 11: Java by Example

234321 Java by Example

11

Java IO

Character Streams - Reader

Page 12: Java by Example

234321 Java by Example

12

Java IO

Character Streams - Writer

PrintWriter

Page 13: Java by Example

234321 Java by Example

13

Java IO

Byte Streams - Input

Page 14: Java by Example

234321 Java by Example

14

Java IO

Byte Streams - Output

Page 15: Java by Example

234321 Java by Example

15

Java IO in Eliza

Page 16: Java by Example

234321 Java by Example

16

Java UI - swings

Page 17: Java by Example

234321 Java by Example

17

Swing (continued)

Page 18: Java by Example

234321 Java by Example

18

Swing (continued)

Page 19: Java by Example

234321 Java by Example

19

Swing (continued)

Page 20: Java by Example

234321 Java by Example

20

Swing (continued)

Page 21: Java by Example

234321 Java by Example

21

Swing (continued)

Page 22: Java by Example

234321 Java by Example

22

Event Listener

Some Events and Their Associated Event Listeners

Act that Results in the Event Listener Type

User clicks a button, presses Enter while typing in a text field, or chooses a menu item

ActionListener

User closes a frame (main window) WindowListener

User presses a mouse button while the cursor is over a component

MouseListener

User moves the mouse over a component MouseMotionListener

Component becomes visible ComponentListener

Component gets the keyboard focus FocusListener

Table or list selection changes ListSelectionListener

Any property in a component changes such as the text on a label

PropertyChangeListener

Page 23: Java by Example

234321 Java by Example

23

The MVC pattern

Swing architecture is rooted in the model-view-controller design that dates back to SmallTalk. MVC architecture calls for a visual application to be broken up into three separate parts:– A Model that represents the data

for the application.– The view that is a visualization of

that data– The controller that manipulates the view and

updates the model

Meet Little SmallTalk in OOP

Page 24: Java by Example

234321 Java by Example

24

UI in Eliza

JLabel

JPanelJTextArea

JTextField

JScrollPane

Page 25: Java by Example

234321 Java by Example

25

UI in Eliza (code 1/3)

Page 26: Java by Example

234321 Java by Example

26

UI in Eliza (code 2/3)

Page 27: Java by Example

234321 Java by Example

27

UI in Eliza (code 3/3)

Page 28: Java by Example

234321 Java by Example

28

MVC in Eliza

ElizaUI<<ElizaModelInterface>>

ElizaModel

implem

ents

Where is the controller?Why use an interface?

Page 29: Java by Example

234321 Java by Example

29

Questions

Page 30: Java by Example

234321 Java by Example

30

Questions (continued)

Page 32: Java by Example

234321 Java by Example

32

Eliza – sample conversationHi thereGreetings from inside the box.what shall we talk aboutDoes that question interest you?yesAre you sure?yes I amDo you enjoy being ?again yesYou seem quite positive.yesPlease elaborateI want to know what you would like to hearSo what's stop you?youWe were discussing you -- not me.damn rightSay, do you have any psychological problems?yesYou seem quite positive.yesWhy do you think so?because i find myself talking with computersDoesn't any other reasons come to mind?nopeCan you elaborate on that?I am spending my days in the Technion in the computers labDo you enjoy being spending my days in the technion in the computers lab ?no! Say again.noAre you sure?yesAre you sure?yesPlease elaborate