Presentation is loading. Please wait.

Presentation is loading. Please wait.

CTIS251-Week 1 Engineering Software and Java Dr. Ozlem Albayrak.

Similar presentations


Presentation on theme: "CTIS251-Week 1 Engineering Software and Java Dr. Ozlem Albayrak."— Presentation transcript:

1 CTIS251-Week 1 Engineering Software and Java Dr. Ozlem Albayrak

2 2 Menu F Introduction to the CTIS251 elements F What is Engineering? –Can we engineer software? F Introduction to the java language programming concepts F Primitive Data Types and Operations

3 3 Introduction to CTIS251 Course Elements: - Instructor - Students - Course Material

4 4 Instructor F Dr. Ozlem Albayrak –Computer Eng. Bilkent, 1992 –M.B.A., Bilkent, 1994 –M.S., UMCP, 1998 –Phd., Ankara, 2002 Room# 212 Phone: 290 5039 E-mail: ozlemal@bilkent.edu.tr

5 5 The Students F Attendance - Bonuses F Get to Know F Why are you here? F Expectations F Interests

6 6 Office Hour? Tuesday 14:40 – 15:30 Thursday 8:40 – 10:30 via e-mail or phone for appointment

7 7 Course Material Not limited to: F Syllabus F The main text book F References F All related high quality sources

8 8 Syllabus F Distributed syllabus will be reviewed –Subjects –Grading (bonus questions) –Labs

9 9 Syllabus (1) WeekChapters 1Introduction to the course, basic java language programming concepts: Primitive Data Types and Operations 1, 2 2Methods, Control Statements, Arrays4, 3, 5 3Object Oriented Programming: Objects and Classes6 4Data Member, Member Method, Static and final members. Constructor 6 5Visibility Modifiers, Acessors, and Mutators6 6Inheritance, Object Class8 7Review + Array of Objects, Some handy Java Classes; Arrays, String, StringBuffer, StringTokenizer, Vector 7 8MIDTERM

10 10 Syllabus (2) 9 Array of Objects, Some handy Java Classes; Arrays, String, StringBuffer, StringTokenizer, Vector 7 10 Concrete class, Abstract Class, Interface 9 11 Polymorphism 8 12 Error Handling, Exception Classes and Custom Java Exceptions 15 13 GUI Programming, event driven programming, components and containers, AWT (Abstract Window Toolkit), swing 11, 12, 13 14 GUI Programming, event driven programming, components and containers, AWT (Abstract Window Toolkit), swing 11, 12, 13 15 GUI Programming, Applet 14 16 Review 17 FINAL

11 11 What is Engineering?

12 12 Webster’s Definitions en·gi·neer·ing ( n j -nîr ng) n. The application of scientific and mathematical principles to practical ends such as the design, manufacture, and operation of efficient and economical structures, machines, processes, and systems. Problem solvers

13 13 How is engineering software different from engineering bridges?

14 14 F Continuous –Calculus –Testing/analysis is easy: if the bridge holds for 1M kg, it also probably holds 0.99Mkg F Discrete –Logic, Discrete Mathematics –Testing/analysis is difficult Bridges Software

15 15 F Made of physical stuff –Some costs are obvious –Changes after construction are hard F Made of virtual stuff –All costs are non- obvious –Changes should be easy (but they’re not) Bridges Software for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { nextStates [i][j] = getCellAt (i, j).getNextState (); }

16 16 F Obvious when it fails –Bridge makers get sued –Architects need licenses F Falls down quietly (usually) –Software vendors blame user, charge for upgrades –Anyone can make software, no one gets sued Bridges Software

17 17 F Requirements are (usually) obvious and easy to describe F A good design is apparent to everyone immediately F Requirements are mysterious and hard to describe F A good design is only apparent to “experts” but has impact later on Bridges Software Grid CellAutomata Cell CellState GridDisplay ConwayLifeCell is a subtype of (extends)

18 18 JAVA

19 19 Google search about Java.... F Returns approximately yaklaşık 307.000.000 result !

20 20 Java Sources on the net F http://en.wikipedia.org/wiki/Java_%28progr amming_language%29 F http://java.net/ F http://java.sun.com/docs/books/tutorial/ F http://www.javaturkiye.com/ http://www.javaturkiye.com/ F Books: http://www.oreilly.com/pub/topic/java

21 21 What is Java? A. Island in Indonesia known for coffee and volcanoes B. A Programming Language (Java  ) C. A Portable Low-Level Language (JVML) D. A Platform (JavaVM) E. A (semi-)successful marketing strategy –JavaScript is not related to Java or Java  F. All of the above

22 22 Compiling C++ Programs #include main( int argc, char *argv[]) { // do something }

23 23 The Java Virtual Machine class Hello { public static void main(String[] args) { System.out.println( “Hello World” ); } Hello.java … Method Hello() 0 aload_0 1 invokespecial #1 4 return Method void main(java.lang.String[]) 0 getstatic #2 3 ldc #3 5 invokevirtual #4 8 return Hello.class javac

24 24 The Java Virtual Machine class Hello { public static void main() { // do something } Mac JVMLinux JVM Win JVM Hello.class

25 25 Java  : Programming Language “A simple, object-oriented, distributed, interpreted, robust, secure, architecture neutral, portable, high- performance, multithreaded, and dynamic language.” [Sun95] By the end of the course, you should have a good idea if this is a true statement.

26 26 Platform Independence F C++ compiles to native code for a specific architecture (Linux, Windows…) F Java compiles to Java bytecode F Same bytecode runs on virtual machine for any platform –Only VM is platform specific –Good for downloadable code –Applets etc

27 27 Java F Syntax –Similar to C++ –Designed to be easy for C and C++ programmers to learn F Semantics (what programs mean) –Similar to Scheme –Designed to make it easier to reason about properties of programs

28 28 Programming Systems Scheme Interpreter Scheme Program C++ Compiler C++ Program Machine Object Files

29 29 Java VM F Portability –If you can implement a Java VM on your machine, then you can run all Java programs F Security –A VM can limit what programs can do to the real machine F Simplicity –VM instructions can be simpler than machine instructions Java Compiler Java Program Java Virtual Machine Class Files Machine Why use a virtual machine?

30 30 Programming in Java F Program is divided into classes F A class: –Defines a new datatype –Defines methods and state associated with that datatype F We call a value of a class datatype an object –Objects package state and code

31 Introduction to Java Programming with JBuilder, 3E Y. Daniel Liang

32 32 Sequence of the Topics

33 33 Course Objectives F Upon completing the course, you will understand –Create, compile, and run Java programs –Primitive data types –Java control flow –Methods –Arrays (for teaching Java in two semesters, this could be the end) –Object-oriented programming –Core Java frameworks (Swing, exception, I/O, collections, multithreading, multimedia, )

34 34 Course Objectives, cont. F You will be able to –Develop programs using various tools –Write simple programs using primitive data types, control statements, methods, and arrays –Understand object-oriented concepts and principles: abstraction, encapsulation, inheritance, and polymorphism –Develop a GUI interface and Java applets –Deal with exceptions in the program –Store and retrieve data using Java I/O –Use data structures from the Java Collections framework –Establish a firm foundation on Java concepts

35 35 Chapter Dependency Chart

36 36 Book Chapters F Part I: Fundamentals of Programming –Chapter 1 Introduction to Java and JBuilder –Chapter 2 Primitive Data Types and Operations –Chapter 3 Control Statements –Chapter 4 Methods –Chapter 5 Arrays

37 37 Book Chapters, cont. F Part II: Object-Oriented Programming –Chapter 6 Objects and Classes –Chapter 7 Strings –Chapter 8 Inheritance and Polymorphism –Chapter 9 Abstract Classes and Interfaces –Chapter 10 Object-Oriented Analysis and Design

38 38 Book Chapters, cont. F Part III: GUI Programming –Chapter 11 Getting Started with GUI Programming –Chapter 12 Event-Driven Programming –Chapter 13 Creating User Interfaces –Chapter 14 Applets

39 39 Book Chapters, cont. F Part IV: Developing Comprehensive Projects –Chapter 15 Exceptions and Assertions –Chapter 16 Input and Output –Chapter 17 Java Data Structures –Chapter 18 Multithreading –Chapter 19 Multimedia

40 40 Bonus Chapters on the CD-ROM F Part V: Bonus Chapters –Chapter 20 Internationalization –Chapter 21 Networking –Chapter 22 Database Programming –Chapter 18 Servlets –Chapter 19 JavaServer Pages

41 41 Chapter 1 Introduction to Java and JBuilder F What Is Java? F Getting Started With Java Programming –Create, Compile and Running a Java Application

42 42 What Is Java? F History F Characteristics of Java

43 43 History F James Gosling and Sun Microsystems F Oak F Java, May 20, 1995, Sun World F HotJava –The first Java-enabled Web browser F JDK Evolutions F J2SE, J2ME, and J2EE (not mentioned in the book, but could discuss here optionally)

44 44 Characteristics of Java F Java is simple F Java is object-oriented F Java is distributed F Java is interpreted F Java is robust F Java is secure F Java is architecture-neutral F Java is portable F Java’s performance F Java is multithreaded F Java is dynamic

45 45 JDK Versions F JDK 1.02 (1995) F JDK 1.1 (1996) F Java 2 SDK v 1.2 (a.k.a JDK 1.2, 1998) F Java 2 SDK v 1.3 (a.k.a JDK 1.3, 2000) F Java 2 SDK v 1.4 (a.k.a JDK 1.4, 2002) F...

46 46 JDK Editions F Java Standard Edition (J2SE) – J2SE can be used to develop client-side standalone applications or applets. F Java Enterprise Edition (J2EE) – J2EE can be used to develop server-side applications such as Java servlets and Java ServerPages. F Java Micro Edition (J2ME). – J2ME can be used to develop applications for mobile devices such as cell phones. This book uses J2SE to introduce Java programming.

47 47 Java IDE Tools F Forte by Sun MicroSystems F Borland JBuilder F Microsoft Visual J++ F WebGain Café F IBM Visual Age for Java F IBM WSAD

48 48 Getting Started with Java Programming F A Simple Java Application F Compiling Programs F Executing Applications

49 49 A Simple Application Example 1.1 //This application program prints Welcome //to Java! package chapter1; public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } Run Source IMPORTANT NOTE: To run the program from the Run button, (1) set c:\jbuilder9\jdk1.4\bin on your path, and (2) copy both the slide directory and the example directory from the IR-CD to a directory (e.g., c:\LiangIR-CD).

50 50 Anatomy of a Java Program F Comments F Package F Reserved words F Modifiers F Statements F Blocks F Classes F Methods F The main method

51 51 Comments In Java, comments are preceded by two slashes (//) in a line, or enclosed between /* and */ in one or multiple lines. When the compiler sees //, it ignores all text after // in the same line. When it sees /*, it scans for the next */ and ignores any text between /* and */.

52 52 Package The second line in the program (package chapter1;) specifies a package name, chapter1, for the class Welcome. Forte compiles the source code in Welcome.java, generates Welcome.class, and stores Welcome.class in the chapter1 folder.

53 53 Reserved Words Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. For example, when the compiler sees the word class, it understands that the word after class is the name for the class. Other reserved words in Example 1.1 are public, static, and void. Their use will be introduced later in the book.

54 54 Modifiers Java uses certain reserved words called modifiers that specify the properties of the data, methods, and classes and how they can be used. Examples of modifiers are public and static. Other modifiers are private, final, abstract, and protected. A public datum, method, or class can be accessed by other programs. A private datum or method cannot be accessed by other programs. Modifiers are discussed in Chapter 6, “Objects and Classes.”

55 55 Statements A statement represents an action or a sequence of actions. The statement System.out.println("Welcome to Java!") in the program in Example 1.1 is a statement to display the greeting "Welcome to Java!" Every statement in Java ends with a semicolon (;).

56 56 Blocks A pair of braces in a program forms a block that groups components of a program.

57 57 Classes The class is the essential Java construct. A class is a template or blueprint for objects. To program in Java, you must understand classes and be able to write and use them. The mystery of the class will continue to be unveiled throughout this book. For now, though, understand that a program is defined by using one or more classes.

58 58 Methods What is System.out.println? It is a method: a collection of statements that performs a sequence of operations to display a message on the console. It can be used even without fully understanding the details of how it works. It is used by invoking a statement with a string argument. The string argument is enclosed within parentheses. In this case, the argument is "Welcome to Java!" You can call the same println method with a different argument to print a different message.

59 59 main Method The main method provides the control of program flow. The Java interpreter executes the application by invoking the main method. The main method looks like this: public static void main(String[] args) { // Statements; }

60 60 Creating, Compiling, and Running Programs

61 61 Executing Applications F On command line –java classname

62 62 Example javac Welcome.java java Welcome output:...

63 63 JBuilder Basics F Installing JBuilder F JBuilder IDE Interface F Create a JBuilder project F Create Java programs F Compile and run Java programs

64 64 JBuilder IDE Interface

65 65 Creating a JBuilder project Choose File, New Project to display the project wizard

66 66 Creating a JBuilder project, cont. Set output path, backup path, working directory, and source path

67 67 Creating a JBuilder project, cont. Optional project description

68 68 Creating a Java Program Choose File, New Class to display the class wizard

69 69 Compiling and Running a Program Where are the files stored in the directory?

70 70 Displaying Text in a Message Dialog Box you can use the showMessageDialog method in the JOptionPane class. JOptionPane is one of the many predefined classes in the Java system, which can be reused rather than “reinventing the wheel.” Run Source IMPORTANT NOTE: To run the program from the Run button, (1) set c:\jbuilder9\jdk1.4\bin on your path, and (2) copy both the slide directory and the example directory from the IR-CD to a directory (e.g., c:\LiangIR-CD).

71 71 The showMessageDialog Method JOptionPane.showMessageDialog(null, "Welcome to Java!", "Example 1.2", JOptionPane.INFORMATION_MESSAGE));

72 72 The exit Method Use Exit to terminate the program and stop all threads. NOTE: When your program starts, a thread is spawned to run the program. When the showMessageDialog is invoked, a separate thread is spawned to run this method. The thread is not terminated even you close the dialog box. To terminate the thread, you have to invoke the exit method.

73 73 Review F Introducttion to course elements F Introduction to Java basics F Review F Next: –Primitive Data Types and operations


Download ppt "CTIS251-Week 1 Engineering Software and Java Dr. Ozlem Albayrak."

Similar presentations


Ads by Google