L1-2:CSC210 2014-2015 ©Dr. Basheer M. Nasef Lecture #1 By Dr. Basheer M. Nasef.

Slides:



Advertisements
Similar presentations
University of Palestine software engineering department Introduction to data structures Introduction to java application instructor: Tasneem Darwish.
Advertisements

Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Excerpts from Introduction to Java Programming, 4E Author: Y. Daniel Liang (Copyright by Prentice Hall)
Introduction to Java Programming, 4E
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
1 Chapter 1 Introduction to Computers, Programs, and Java.
Unit2: Object-oriented programming Getting started with Java Jin Sa.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
L EC. 01: J AVA FUNDAMENTALS Fall Java Programming.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Advanced OOP MCS-3 OOP BSCS-3 Lecture # 1
BASIC JAVA PROGRAMMING TUTORIAL. History  James Gosling and Sun Microsystems  Oak  Java, May 20, 1995, Sun World  Hot Java –The first Java-enabled.
CTIS251-Week 1 Engineering Software and Java Dr. Ozlem Albayrak.
Introduction to Java Programming with JBuilder 4
S.W. Ma/CIM/LWL41211/2 Prog. IIA Page 1 HKIVE (Lee Wai Lee Campus) Department of CIM Course : Year 2 Module : Programming IIA Textbook : Introduction.
Chapter 1 Introduction to Computers, Programs, and Java 1.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Programming Languages Machine.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
CPCS  Problem Solving in Everyday Life  Types of Problems  Problem Solving with Computers  Difficulties with Problem Solving 0-3.
1 Chapter 1 Introduction to Computers, Programs, and Java.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Programs,
Introduction to Java Programming. History F James Gosling and Sun Microsystems F Oak F Java, May 20, 1995, Sun World F HotJava –The first Java-enabled.
1.  At the end of this slide, student can:  Explore tools, features, properties and interface of the Textpad.  Creating a new project.  Open and run.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
1 Chapter 3 Programs and Java. 2 Objectives F To review computer programs, and operating systems. F To represent numbers in binary, decimal, and hexadecimal.
ECOM 2314 Computer Programming I
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
1 Chapter 1 Java –Originally for intelligent consumer-electronic devices –Then used for creating Web pages with dynamic content –Now also used for: Develop.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
Chapter 1: Introduction to Programs, and Java 1. Objectives To review programs (§ ). To understand the relationship between Java and the World Wide.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Programs.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Introduction to Java Programming with Forte Y. Daniel Liang.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved What is a Computer? A computer.
Object Oriented Rabie A. Ramadan, PhD Slides are exerted from different sources.
Introduction to Java Programming. Introduction Course Objectives Organization of the Book.
Introduction To JAVA By Ihtesham Ul Haq. Course Objectives Upon completing the course, you will understand Upon completing the course, you will understand.
1 Chapter 3 Introduction to Computers, Programs, and Java.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Session 1 Introduction to Java. Objectives Java Simplified / Session 1 / 2 of 32 Explain the history of Java Explain Java in brief List the types of Java.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Application Architecture Using Java Hong Li. Introduction Developed by a team led by James Gosling at Sun Microsystem. Originally called Oak, designed.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Introduction to Java Programming. 2 Chapter 1 Introduction to Java and Forte F What Is Java? F Getting Started With Java Programming –Create, Compile.
introductory lecture on java programming
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
1 Chapter 1 Introduction to Computers, Programs, and Java.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
Introduction to JAVA Programming
Introduction to Java Programming, 4E Y. Daniel Liang.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
GC101 Introduction to computer and program
Chapter 1 Introduction to Computers, Programs, and Java
Introduction to Programming
Chapter 1 Introduction to Computers, Programs, and Java
آشنایی با جاوا Introduction to Java
CPCS 202 – Programming I Computer Science Department College of Computing and Information Technology King Abdul Aziz University.
Chapter 1 Introduction to Computers, Programs, and Java
Anatomy of a Java Program
Presentation transcript:

L1-2:CSC ©Dr. Basheer M. Nasef Lecture #1 By Dr. Basheer M. Nasef

L1-2:CSC ©Dr. Basheer M. Nasef Agenda Introduction to Java Programming Examples 2

L1-2:CSC ©Dr. Basheer M. Nasef Learning Strategies A programming course is quite different from other courses.  In a programming course, you learn from examples, from practice, and from mistakes.  You need to devote a lot of time to writing programs, testing them, and fixing errors. 3

L1-2:CSC ©Dr. Basheer M. Nasef JDK & JRE ? JRE (Java Runtime) is needed for running Java programs. JDK (Java Development Kit), which includes JRE plus the development tools (such as compiler and debugger), is need for writing as well as running Java programs. To write Java Programs, you should install JDK, which includes JRE. 4

L1-2:CSC ©Dr. Basheer M. Nasef JDK Versions JDK Alpha and Beta (1995): Sun announced Java in September 23, JDK 1.0 (January 23, 1996): Originally called Oak (named after the oak tree outside James Gosling's office). Renamed to Java 1 in JDK JDK 1.1 (February 19, 1997): Introduced AWT event model, inner class, JavaBean, JDBC, and RMI. J2SE 1.2 (codename Playground) (December 8, 1998): Re- branded as "Java 2" and renamed JDK to J2SE (Java 2 Standard Edition). Also released J2EE (Java 2 Enterprise Edition) and J2ME (Java 2 Micro Edition). Included JFC (Java Foundation Classes - Swing, Accessibility API, Java 2D, Pluggable Look and Feel and Drag and Drop). Introduced Collection Framework and JIT compiler. J2SE 1.3 (codename Kestrel) (May 8, 2000): Introduced Hotspot JVM. 5

L1-2:CSC ©Dr. Basheer M. Nasef JDK Versions J2SE 1.4 (codename Merlin) (February 6, 2002): Introduced assert, non-blocking IO (nio), logging API, image IO, Java webstart, regular expression support. J2SE 5.0 (codename Tiger) (September 30, 2004): Officially called 5.0 instead of 1.5. Introduced generics, autoboxing/unboxing, annotation, enum, varargs, for-each loop, static import. Java SE 6 (codename Mustang) (December 11, 2006): Renamed J2SE to Java SE (Java Standard Edition). Java SE 7 (codename Dolphin) (July 28, 2011): First version after Oracle purchased Sun (called Oracle JDK). Java SE 8 (March 18, 2014): included support for Lambda expressions, default methods, and JavaScript runtime. 6

L1-2:CSC ©Dr. Basheer M. Nasef JDK Editions Java Standard Edition (J2SE) J2SE can be used to develop client-side standalone applications or applets. Java Enterprise Edition (J2EE) J2EE can be used to develop server-side applications such as Java servlets and Java ServerPages. Java Micro Edition (J2ME). J2ME can be used to develop applications for mobile devices such as cell phones. This Course (CSC210) uses J2SE to introduce Java programming. 7

L1-2:CSC ©Dr. Basheer M. Nasef Popular Java IDEs (Integrated development environment ) NetBeans Open Source by Sun Eclipse Open Source by IBM Borland JBuilder 2007 (Based on Eclipse) JCreator. 8

L1-2:CSC ©Dr. Basheer M. Nasef Java Program 9 Java programs consist of pieces called classes. Classes include pieces called methods that perform tasks and return information when they complete them. Programmers can create each piece they need to form Java programs. However, most Java programmers take advantage of the rich collections of existing classes in the Java class libraries, which are also known as the Java APIs (Application Programming Interfaces).

L1-2:CSC ©Dr. Basheer M. Nasef Java Program 10 Thus, there are really two aspects to learning the Java "world." The first is the Java language itself, so that you can program your own classes. The second is the classes in the extensive Java class libraries. Throughout this course, we discuss many library classes.

L1-2:CSC ©Dr. Basheer M. Nasef Creating, Compiling, and Executing a Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } 11

L1-2:CSC ©Dr. Basheer M. Nasef Creating and Editing Using NotePad To use NotePad, type notepad Welcome.java from the DOS prompt. 12

L1-2:CSC ©Dr. Basheer M. Nasef Creating, Compiling, and Running Programs 13

L1-2:CSC ©Dr. Basheer M. Nasef Trace a Program Execution 14 //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } Enter main method

L1-2:CSC ©Dr. Basheer M. Nasef Trace a Program Execution 15 //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } Execute statement

L1-2:CSC ©Dr. Basheer M. Nasef Trace a Program Execution 16 //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } print a message to the console

L1-2:CSC ©Dr. Basheer M. Nasef Supplements on the Companion Website See Supplement I.B for installing and configuring JDK See Supplement I.C for compiling and running Java from the command window for details 17

L1-2:CSC ©Dr. Basheer M. Nasef Compiling and Running Java from the Command Window  Set path to JDK bin directory  set path=c:\Program Files\java\jdk1.8.0_25\bin  Set classpath to include the current directory  set classpath=.  Compile  javac Welcome.java  Run  java Welcome 18

L1-2:CSC ©Dr. Basheer M. Nasef Compiling and Running Java from JCreator 19

L1-2:CSC ©Dr. Basheer M. Nasef Anatomy of a Java Program Comments Package Reserved words Modifiers Statements Blocks Classes Methods The main method 20

L1-2:CSC ©Dr. Basheer M. Nasef Comments I. Line comment: A line comment is preceded by two slashes (//) in a line. II. Paragraph comment: A paragraph comment is enclosed between /* and */ in one or multiple lines. 21 javadoc comment: javadoc comments begin with /** and end with */. They are used for documenting classes, data, and methods. They can be extracted into an HTML file using JDK's javadoc command. Three types of comments in Java.

L1-2:CSC ©Dr. Basheer M. Nasef 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. 22

L1-2:CSC ©Dr. Basheer M. Nasef 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 above program are public, static, and void. Their use will be introduced later. 23

L1-2:CSC ©Dr. Basheer M. Nasef 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.” 24

L1-2:CSC ©Dr. Basheer M. Nasef Statements A statement represents an action or a sequence of actions. The statement System.out.println("Welcome to Java!") is a statement to display the greeting "Welcome to Java!" Every statement in Java ends with a semicolon (;). 25

L1-2:CSC ©Dr. Basheer M. Nasef Blocks 26 A pair of braces in a program forms a block that groups components of a program.

L1-2:CSC ©Dr. Basheer M. Nasef 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. For now, though, understand that a program is defined by using one or more classes. 27

L1-2:CSC ©Dr. Basheer M. Nasef 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 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. 28

L1-2:CSC ©Dr. Basheer M. Nasef 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; } 29

L1-2:CSC ©Dr. Basheer M. Nasef 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.” WelcomeInMessageDialogBox 30 Run IMPORTANT NOTE: To enable the buttons, you must store the entire slide file Link_Files files into a directory (e.g., e:\Link_Files_CSC210).

L1-2:CSC ©Dr. Basheer M. Nasef The showMessageDialog Method JOptionPane.showMessageDialog(null, "Welcome to Java!", "Display Message", JOptionPane.INFORMATION_MESSAGE); 31

L1-2:CSC ©Dr. Basheer M. Nasef Two Ways to Invoke the Method There are several ways to use the showMessageDialog method. For the time being, all you need to know are two ways to invoke it. One is to use a statement as shown in the example: JOptionPane.showMessageDialog(null, x, y, JOptionPane.INFORMATION_MESSAGE); where x is a string for the text to be displayed, and y is a string for the title of the message dialog box. The other is to use a statement like this: JOptionPane.showMessageDialog(null, x); where x is a string for the text to be displayed. 32

L1-2:CSC ©Dr. Basheer M. Nasef PROGRAMMING EXERCISES (Displaying a pattern) Write a program that displays the following pattern: 33

L1-2:CSC ©Dr. Basheer M. Nasef PROGRAMMING EXERCISES (Displaying a pattern) Write a program that displays the following pattern: 34

L1-2:CSC ©Dr. Basheer M. Nasef PROGRAMMING EXERCISES (Displaying a pattern) Write a program that displays the following pattern: 35

L1-2:CSC ©Dr. Basheer M. Nasef PROGRAMMING EXERCISES 36

L1-2:CSC ©Dr. Basheer M. Nasef PROGRAMMING EXERCISES 37 Write a program that asks the user to enter two numbers, then prints the sum, product, and difference of the two numbers.