Jaeki Song Lecture 01 Introduction to Java Programming.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Chapter 1: Computer Systems
 2005 Pearson Education, Inc. All rights reserved Introduction.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
The Java Programming Language
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Introduction to Java Programming, 4E
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
Outline Java program structure Basic program elements
Chapter 2 - Introduction to Java Applications
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Introducing Java.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
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.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Object Oriented Systems Lecture 01 First Java Programming Jaeki Song.
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
1 Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
Java: Chapter 1 Computer Systems Computer Programming II.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
Introduction to Computer Systems and the Java Programming Language.
Chapter 1: Introduction to Programs, and Java 1. Objectives To review programs (§ ). To understand the relationship between Java and the World Wide.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Introduction to Java Programming with Forte Y. Daniel Liang.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Jaeki Song ISQS6337 Lecture 01 Introduction. Jaeki Song ISQS6337 Instructor Name: Jaeki Song Office: BA 712 Office Hours Tuesday & Thursday 2:00-3:20.
Week 1 Algorithmization and Programming Languages.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 COMP 241: Object-Oriented Programming with Java Fall 2004 Lecture 1 September 27, 2004 Serdar Taşıran.
Jaeki Song JAVA Lecture 02 Introduction to Java -The First Java Application-
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Creating a Java Application and Applet
Introduction to Java Programming. 2 Chapter 1 Introduction to Java and Forte F What Is Java? F Getting Started With Java Programming –Create, Compile.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Elementary Programming.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Introduction to Java Programming, 4E Y. Daniel Liang.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
1.  Algorithm: 1. Read in the radius 2. Compute the area using the following formula: area = radius x radius x PI 3. Display the area 2.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Working with Java.
Java programming lecture one
Chapter 2 - Introduction to Java Applications
Chapter 1: Computer Systems
Units with – James tedder
Units with – James tedder
Focus of the Course Object-Oriented Software Development
Chapter 2 Primitive Data Types and Operations
Presentation transcript:

Jaeki Song Lecture 01 Introduction to Java Programming

Instructor Name: Jaeki Song Office: BA 712 Office Hours Tuesday & Thursday 10:00-Noon or by appointment Office Phone: (806) Website:

Course Materials Required Textbook Deitel and Deitel, Java How to Program, 4 th Edition, Prentice Hall

Course Objectives Objectives –Introduce OOP using JAVA –Understand JAVA programming –Understand the issues related to web- programming using JAVA –Emphasize critical thinking about new developments

Grading First Exam:20% Second Exam:20% Third Exam:30% Assignments:30%

Course Structure Fundamentals of programming Object-oriented programming Graphics programming Developing comprehensive programming

Objectives B asics of Programming Language W hat is Java? I ntroduction to Java Applications

Program Development Life Cycle (PDLC) 1. Analyze Problem - Review program specification - Meet with users - Identify program components 2. Design Program - Group activity into modules - Devise solution algorithms - Test solution algorithms 3. Code Program - Translate solution algorithm - Enter program code into computer 4. Test Program - Remove any syntax error - Remove any logic error 5. Formalize Solution - Review program code - Review documentation - Implement program 6. Maintain Program - Identify errors - Identify enhancements

Structured Programming Hierarchical Input Process Output (HIPO) chart Algorithmic Thinking –Pseudocode –Flowchart –Storyboard

Top-Down Design One method that is useful when defining the procedures to be used is termed Top-Down Design. With Top-Down Design you –break down a problem down into functional tasks or parts; –break each part, or task, into sub-parts; –continue the ‘chunking-up’ process until the sub-parts, or sub-tasks, are very simple and easily described.

HIPO Chart Main Process Initialization Declare Variable Print Report Read a record Calculate Accumulate total Print Detail Calculate average Print total And averages Wrap-up Calculate discount Calculate Gross amount Calculate net Amount due

Algorithmic Thinking Correct –Using logical constructs and valid data in an organized way The steps will be carried out correctly The program will make suitable response Efficient –The program’s ability to deliver a results in a time short enough to be useful and in a space small enough An algorithm can be defined in various ways. Two common ways include the use of pseudocode and flowchart

Pseudocode uses English-like phrases to describe the instructions –List the actions using keywords –Depicts logical grouping or structures using indentation MAIN MODULE: Call Initialization Call Process Call Output END PROCESS MODULE: Do While not End of File Read a record Call Calculate Call Accumulate Print Detail Line End Do RETURN CALCULATE MODULE: If Hours > 40 then Call overtime Else Call Regular time End If RETURN

Flow Chart Process Symbol Represent process I/O Symbol Makes data available for processing (input) or Displaying (output) of process information Decision symbol Represents a decision that determines which Of number of alternative paths is to be followed Connector symbol Represents any entry form, or exit to, another part of the flow chart Terminal symbol Represents the beginning, the end, or a point of Interruption or delay in a program

Storyboard Interest Calculator Principal: Interest Rate: Months: Amount Paid: Calculate Clear principalField amtlField clearButton monthslField calButton monthsLabel intLabel principalLabel intField amtLabel

What is Java? Computer programming language –Computer program A set of instructions –Programming language A set of words, symbols, and codes –Syntax A set of grammar or rules that specify how the instructions are to be written

History of Java Designed in the early of 1990s by Sun Microsystems Provide animation and interactivity on the World Wide Web –Web browsers have provided the opportunities to run Java applets The fastest growing language

Java Language Standard language used for programming, creating applets, servlets, JavaBeans, and enterprise components Java is simple Java is object-oriented language Java is distributed

Java Language Java is interpreted –Need an interpreter to run Java program –The program are compiled into Java Virtual Machine (JVM) code called bytecode Java Source Code Java compiler Java Bytecode Code Java Interpreter CPU JVM

Java Language Java is robust –Reliabile Detect many problems Java is secure Java is platform-independent Java is portable –Can be run on any platform without being recompiled Java is multithreaded

Java Virtual Machine (JVM) Interpreter for the Java programming language –a simple platform that all Java applications run on. Comes with Java Development Kit (JDK) –Contains JVM and run-time system –Java 2 SDK

Java Environment Editor –Integrated Development Environment (IDE) Jbuilder, J++, Forte, Visual Cafe Compiler –Translate into bytecode For Sun Microsystems- javac (included in SDK) Class loader produces.class file Loading –Applications loaded and executed using Java Interpreter java example.class –Applet loaded in the browser and could be viewed by applet viewer using the html file in which the applet is placed.

Creating First Application The Java 2 Platform, Standard Edition JBuilder4 or 5

JBuilder: Interface Main menu Project toolbar Project pane Structure pane Content pane File tab File view tab

Example /* Assignment 1 Printing on the screen Programmer: Jaeki Song Student ID : Date : September 2001 Program Name: Address */ public class Address { public static void main(String[] args) //method header { System.out.println(“ Jaeki Song”); System.out.println(“ th Street”); System.out.println(“ Lubbock, TX, 79413”); }

Documentation Comments –Block comment /* ….. */ –Line comment: // – e.g. /* Assignment 1 Printing on the screen Programmer: Jaeki Song Student ID : Date : September 2001 Program Name: Address */

Java Class Java program consists of pieces called classes –Existing classes in Java Class Libraries Known as Java APIs (Applications Programming Interfaces) Classes consists of pieces called methods –Perform tasks and return information

Java Class A single class resides in a single Java source file with extension.java public class Address { …. } The source code is Address.java. –The name of the class is the name of the file Class name and file name must match

Main Method The class which contains the main() method is the class that starts running the program Every Java application (not applet) has a main class public class Address { public static void main(String[] args) { … }

Access Modifier Specifies the circumstances in which the class can be accessed –E.g.: public class Address { ……. } Public indicates that this code can be access by all objects and can be extended or used as a basis for another class The contents of the class must be enclosed in braces { }

Methods and Method Header public static void main(String[] args) //method header { …… } The method as accessible to all classes This method is for class Three parts return value method name arguments lists Void means that this method does not return a value when it is called Method name is main. Main method is the usual starting point for all stand-alone Java program Piece of data. args is an identifier for any string or character argument

Body Code { System.out.println(“ Jaeki Song”); System.out.println(“ th Street”); System.out.println(“ Lubbock, TX, 79413”); } Out is the object that represents the default display System is the name of the class (program-defined class) Println is the name of a method that takes a string argument. It returns its value to the System.out device

Variable Used to store data –Variable declaration To use a variable, you declare it by telling the compiler the name of the variable as well as what type of data it represents datatype variableName e.g int x; //Declare x to be an integer variable double interest; char a; //Declare a to be a character value int x, y, z;

Assignment After a variable is declared, you can assign a value to it by using an assignment statement variable = expression; e.g. x = 1; //Assing 1 to variable x x = y + 1 ; //assign the addition of y and 1 to x –You can declare variable and initialize it in one step int x; x = 1 int x = 1;

Constant A constant represents permanent data that never changes final datatype CONSTANTNAME = VALUE; In java, the world final means that the constant cannot be changed. e.g. final double PI = ;

Numeric Data Types The Java Built-In data type –int: always 32-bit signed integer. –short: 16-bit integer. –byte: 8-bit integer (new). –long: 64-bit singed integer. –float: 32-bit floating-point number. –double; 64-bit floating-point number. –char: Unicode (16-bit, language independent character value, international standard. –boolean: true or false, false is not 0 in Java

Numeric Operators OperatorExampleEquivalent +=i+=8i = i+8 -=f-=8.0f = f-8.0 *=i*=8i = i*8 /=i/=8i = i/8 %=i%=8i = i%8

Increment and Decrement Operators Increment or decrement a variable by 1 X++ or X--; suffix ++X or –X; prefix Suffix operator: the variable is used in the expression first, then incremented or decremented by 1 Prefix operator: the variable is first incremented or decremented by 1, then used in the expression

Relational Operators Relational operator Operator Name Example Answer < less than 1 < 2 true <= less than or equal to 1 <=2 true > greater than 1 > 2 false >= greater than or equal to 1 >= 2 false = = equal to 1 = = 2 false != not equal to 1 != 2 true

Boolean Operators Boolean variable –A variable that holds a Boolean value (true or false) Operator Name Example !Not && andtrue && true  true | |orfalse | | false  false

Programming Style and Documentation Appropriate Comments –Every program has the following block comment appear at the top of the source code file: /*Programmer: Jaeki Song Course:ISQS 6337 File Name:Assign1XXXX.java Description:A brief description of the program */

Programming Style and Documentation Naming conventions –Make sure the meanings of the descriptive means you choose are straightforward –Names are case-sensitive For variables and methods –Use lowercase –If the name consists of several words, concatenate them into one, making the first word lowercase and capitalizing the first letter of each subsequent word e.g: calculateSalary For class names –Capitalize the first letter of each word e.g; ComputeSalary For constants –All letters are capitalized e.g.: MAX_VALUE = 10

Programming Style and Documentation Proper indentation and spacing –Clear and easy to read e.g.: public class Test { public static void main(String args[]) { System.out.println(“Example”); }

Programming Errors Syntax error –Result from errors in cod construction E.g.: mistyping, omitting some necessary punctuation, using an opening brace without a corresponding closing brace Logical error –Occur when a program does not perform the way it was intended to Run-time error –Cause a program to terminate abnormally E.g. –Input error: the user enters an unexpected input value that the program cannot handle –Division by zero

Formatting Output Escape characters CodeConceptResult \t Horizontal tab Moves insertion point eight spaces to the right \b Backspace Moves insertion point one space to the left \n New line Moves insertion point down one line and to the left margin \r Carriage return Moves insertion point to the left margin \” Double quote Used to print a double quote character

Using Java Swing Class Refers to the new library of GUI –A component set that makes up all the objects of GUI Displays output using windows or dialog boxes –Input Dialog and Output Dialog Use packages –Predefined classes grouped into categories of related classes called packages (sometimes called java class libraries or java applications programming interface (API)) –JOptionPane Defined in a package called javax.swing

Output Dialog showMessageDialog ( null, “string”); –A method of class JOptionPane –Two arguments Syntax JOptionPane.showMessageDialog(null, “string”);

Example: Output Dialog import javax.swing.JOptionPane; //import class JOptionPane public class Address { public static void main(String[] args) //method header { JOptionPane.showMessageDialog( null, " Jaeki Song\n th Street\n Lubbock, TX, 79413"); System.exit(0); //terminate program }

Output

Input Dialog Uses predefined dialog box from class JOptionPane called input dialog –Allows the user to input a value for use in the program –Syntax JOptionPane.showInputDialog(“ Enter first integer”);

Example: Add Integer import javax.swing.JoptionPane; public class AddInt { public static void main (String args[]) { String number1, number2; //first and second string entered by user int numInt1, numInt2, sum; number1 = JOptionPane.showInputDialog(“Enter first number”); number2 = JOptionPane.showInputDialog(“Enter second number”); numInt1 = Integer.parseInt(number1); numInt2 = Integer.parseInt(number2); sum = numInt1 + numInt2; JOptionPane.showMessageDialog(null, “The sum is “ + sum, “Results”, JOptionPane.PLAIN_MESSAGE); System.exit(0); }

Output

JDK Packages Package NameDescription java.appletClasses to facilitate using applets java.awt Abstract Window Toolkit; classes to Facilitate graphics user interfaces java.net Classes used for networking and client/ Server applications java.ioClasses to facilitate input and output java.lang Classes to facilitate data types, threads, Strings, and others java.utilClasses used for dates, vectors, and others