IT258 Foundation of Programming Using Java

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

Programming Logic and Design Fourth Edition, Introductory
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
MC697 Object-Oriented Programming Using Java. In this class, we will cover: How the class will be structured Difference between object-oriented programming.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 1: Introduction
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Excerpts from Introduction to Java Programming, 4E Author: Y. Daniel Liang (Copyright by Prentice Hall)
Introduction to Java Programming, 4E
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
01 Introduction1June Introduction CE : Fundamental Programming Techniques.
 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.
Java Programming, 3e Concepts and Techniques Chapter 1 An Introduction to Java and Program Design.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Getting Started with Java
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Java Programming, 2E Introductory Concepts and Techniques Chapter 1 An Introduction to Java and Program Design.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Chapter 1: Java Fundamentals 1 (c) Gary R. Smith, MS.
A First Program Using C#
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.
Microsoft Visual Basic 2005: Reloaded Second Edition
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Object Oriented Systems Lecture 01 First Java Programming Jaeki Song.
Chapter 1: Creating Java Programs
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
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.
The Java Programming Language
Computer Concepts 2014 Chapter 12 Computer Programming.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Chapter 1: Introduction to Programs, and Java 1. Objectives To review programs (§ ). To understand the relationship between Java and the World Wide.
POS 406 Java Technology And Beginning Java Code
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.
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.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
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.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use Swing components to build the GUI Use proper naming conventions for classes.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Chapter 4 Software. Chapter 4: Software Generations of Languages Each computer is wired to perform certain operations in response to an instruction. An.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
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.
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
Lecture1 Instructor: Amal Hussain ALshardy. Introduce students to the basics of writing software programs including variables, types, arrays, control.
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.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use simple Output statements Understand the different types and uses of comments.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
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.
GC101 Introduction to computer and program
Introducing Java.
Computer Programming-1 CSC 111
Presentation transcript:

IT258 Foundation of Programming Using Java Unit 2 Seminar : (Chapter 1 ) Instructor : Vladimir Gubanov, PhD Email : vgubanov@kaplan.edu

they will be each Thursday , from 9 PM to 10 PM EST A reminder: Our Seminars : they will be each Thursday , from 9 PM to 10 PM EST My Office Hours : Mondays, 7PM to 8PM Saturdays, 9AM to 10 AM My email : vgubanov@kaplan.edu

Java Programming, Fifth Edition Chapter One: Creating Your First Java Classes

Objectives Object-oriented programming concepts Learn about Java Analyze a Java application that uses console output Save, compile, run, and modify a Java application Create a Java application using GUI output Java Programming, Fifth Edition

Object-Oriented Programming Concepts Procedural programming Sets of operations executed in sequence Variables hold values Procedures group operations in logical units Object-oriented programs Create classes first Create objects from classes when a functionality of the class needs to be used Object-oriented programming includes: Encapsulation Inheritance Polymorphism Java Programming, Fifth Edition

Understanding Objects and Classes Made up of attributes, methods, events Attributes Characteristics that define object Value of attributes is object’s state Class Describes objects with common properties Definition – template for objects Instance of a class – an object to use Java Programming, Fifth Edition

OBJECT Represents something you would find in the “real-world” Objects can be described by their attributes(properties) and behaviors(methods) In Java, an object is represented by a software module, which contains a collection of related data and procedures Object: Car

PROPERTY (or field) Attribute which describes the object: In Java, a property is represented by a variable associated with the object Property: Color Make Year VIN

METHOD Behavior of the object or what the object can do In Java, a method is represented by a public subroutine or function related to the object Method: Start Accelerate Turn Left Stop

STATE The collection of an object’s property values determine its state The object’s state can affect its behavior Object: Car Property: GasolineLevel OilLevel Speed State

CLASS A category of objects – “abstraction” Template for the object, also called “factory” Allows multiple objects to have common methods and properties An object is an “instance” of a class Objects: VIN: 323422344 Class: Car VIN: 323422345 VIN: 323422346

INTERFACE The set of public methods and properties which are available to access or manipulate the object An object may have many interfaces Object: Car Properties: Color GasolineLevel Make OilLevel Model Speed Year Methods: Stop Turn Left Start Turn Right Accelerate Interface

room window door CLASS : elaborate A blueprint is the specification of a House. This blueprint specifies a house with room, door, and window. room There are several means of explaining object-oriented concepts. Weber chapter 5 (assumes syntax understanding) Farrel the first few chapters (covers the concepts from a coding perspective and not so much a conceptual one) http://webopedia.internet.com/TERM/o/object_oriented.html The particular faculty member might want to use his/her own methods/analogies for explaining object-oriented concepts and forgo all or parts of this explanation. window door

class object A class is the specification from which a developer A blueprint is the specification from which a builder generates houses class object A class is the specification from which a developer generates objects Analogies seem to be the easiest way to explain object-oriented principles, but be very careful that the analogy is not misinterpreted.

ENCAPSULATION Hides the internal workings of an object from the rest of the application. You may change Implementation while interface remains constant In Java properties and methods are used to get information and perform actions in an application that are hidden within classes: you do not know how they are implemented , but can use then as “black box”

INHERITANCE: Very Important Ability to reuse functionality in a class. A base class defines the common functionality: Subclasses inherit that functionality and may add new functionality i.e.: A general class of Sport Car is used to create sub-classes of Camaro and FireBird. They have many similar (re-used) features but are different cars, because they have other properties (methods) different.

Learning About Java Java Developed by Sun Microsystems Object-oriented language Advantages : Simple, Distributed , Interpreted, Secure Architecture neutral, Portable, Multithreaded Can be run on wide variety of computers Runs on hypothetical computer known as Java virtual machine (JVM) Java Programming, Fifth Edition

Learning About Java (continued) Can be run on wide variety of computers Does not execute instructions on computer directly Runs on hypothetical computer known as Java virtual machine (JVM) Source code Programming statements written in high-level programming language Java Programming, Fifth Edition

The Java Virtual Machine – special “basic computer” Java is platform independent. What this means is that a program written in Java should be executable in any computer with any chipset. This is done by means of the Java Virtual Machine (JVM). The JVM interacts with a computer through bytecode. Computer JVM Program

Java Program Types Applets Java applications Programs embedded in Web page Java applications Called Java stand-alone programs Console applications Support character output GUI based applications Menus Toolbars Dialog boxes Java Programming, Fifth Edition

Java Programming Process: Write a specification for the program (what the program is supposed to do) Design the program Choose algorithms and decide how data will be stored , develop pseudocode and/or flowchart Write the program (Java language, indeed!) Compile the program (to lower-level language) Execute the program Debug the program Maintenan the program in a workable condition

Analyzing a Java Application That Uses Console Output Even simplest Java application Involves fair amount of confusing syntax Goal of the first application : Print “First Java application” on screen Java Programming, Fifth Edition

Analyzing a Java Application That Uses Console Output : Java Programming, Fifth Edition

Understanding the First Class Everything used within Java program must be part of a class Define Java class using any name or identifier Requirements for identifiers Must begin with: Letter of English alphabet Or non-English letter (such as α or π) Cannot begin with digit Java Programming, Fifth Edition

Understanding the First Class Requirements for identifiers Can only contain: Letters Digits Underscores Dollar signs Cannot be Java reserved keyword Cannot be true, false, or null Access modifier Defines how class can be accessed Java Programming, Fifth Edition

Understanding the First Class Java Programming, Fifth Edition

Understanding the Statement That Prints the Output Java Programming, Fifth Edition

Some Illigal in Java Class names Java Programming, Fifth Edition

Understanding the First Class (continued) Java Programming, Fifth Edition

Understanding the main() Method static Means method accessible and usable Even though no objects of class exist void Use in main() method header Indicates main() method does not return value when called Doesn’t mean main() doesn’t produce output Java Programming, Fifth Edition

Another Java Program: Example.java /* This is a simple Java program. Call this file Example.java */ class Example { //A Java program begins with a call to main(). public static void main(String[] args) System.out.println("Java drives the Web."); // System.out : console output } // println() displays the string } // passed to it Change .println to Println and compile Here: Java is case sensitive language!! a source file : the same name as class with .java extension comments(ignored by the compiler): single line and multiline a subroutine is called a method; main() method is the entry point public: access specifier ; static – can be called before an object is created from a class ; void - does not return a value

Shell Code – create and use as a template for any class Do not forget to same in the file AnyClassName.java Java Programming, Fifth Edition

Adding Comments to a Java Class Types of Java comments Line comments Start with two forward slashes (//) Continue to end of current line Do not require ending symbol Block comments Start with forward slash and asterisk (/*) End with asterisk and forward slash (*/) Java Programming, Fifth Edition

Saving, Compiling, and Running and Modifying a Java Application Saving a Java class Save class in file with exactly same name and.java extension For public classes Class name and filename must match exactly Compiling a Java class Compile source code into bytecode Translate bytecode into executable statements Using Java interpreter Type javac First.java Java Programming, Fifth Edition

Running a Java Application Run application from command line Type java First Shows application’s output in command window Class stored in folder named Java on C drive Java Programming, Fifth Edition

Running a Java Application In order javac and java programs be able to find First.java and First.class files - set up Environmental Path variable Java Programming, Fifth Edition

Modifying a Java Class Modify text file that contains existing class Save file with changes Using same filename Compile class with javac command Interpret class bytecode and execute class using java command Java Programming, Fifth Edition

Creating a Java Application Using GUI Output JOptionPane Produce dialog boxes Dialog box GUI object resembling window Messages placed for display Package Group of classes import statement Use to access built-in Java class Java Programming, Fifth Edition

Creating a Java Application Using GUI Output Java Programming, Fifth Edition

Correcting Errors First line of error message displays: Name of file where error found Line number Nature of error Next lines identify: Symbol Location Compile-time error Compiler detects violation of language rules Refuses to translate class to machine code Do not expect miracles : an error message will only approximately indicate where an error is and what it could be – no guarantee that these are 100% correct Java Programming, Fifth Edition

Correcting Errors and Finding Help (continued) Parsing Process compiler uses to divide source code into meaningful portions Logic error Syntax correct but produces incorrect results when executed Usually more difficult to find and resolve Java API Also called the Java class library Prewritten Java classes Java Programming, Fifth Edition

You Do It Your first application Adding comments to a class Modifying a class Creating a dialog box Java Programming, Fifth Edition

Don’t Do It File’s name must match name of class Don’t confuse names parentheses, braces, brackets, curly braces, square brackets, and angle brackets Don’t forget to end a block comment Don’t forget that Java is case sensitive End every statement with semicolon Do not end class or method headers with semicolon Recompile when making changes Java Programming, Fifth Edition

Summary Computer program Set of instructions that tells a computer what to do Object-oriented programs Classes Objects Java virtual machine (JVM) Standardized hypothetical computer Everything in a Java program must be part of a class Java Programming, Fifth Edition

Summary (continued) Access modifier Word that defines circumstances under which class can be accessed All Java applications must have method named main() Program comments Nonexecuting statements Add to file for documentation javac Compile command Java Programming, Fifth Edition

Summary (continued) java JOptionPane Execute command GUI Provides methods for creating dialogs Java Programming, Fifth Edition

Quiz True or False: Object-oriented programming is a style of programming in which sets of operations are executed one after another in sequence. Answer: False Writing ____ programs involves creating classes, creating objects from those classes, and creating applications. Answer: object-oriented Answer: False A(n) ____ of a class is an existing object of a class. Answer: instance Programming statements written in a high-level programming language are called ____. Answer: source code

Quiz (cont.) Stand-alone programs are called Java ____. Answer: applications Answer: True True or False: Not all classes have a main() method. Line comments start with ____. Answer: two forward slashes (//)

Quiz (cont.) True or False: In Java, if a class is public (that is, if you use the public access modifier before the class name), you must save the class in a file with exactly the same name and a .class extension. Answer: False and *= To compile a file named First.java, you type ____ First.java and then press Enter. Answer: javac To run the First application from the command line, you type ____ First. Answer: java

Quiz (cont.) A(n) ____ is a GUI object resembling a window in which you can place messages you want to display. Answer: dialog box

This is the end of our Unit 2 Seminar Any questions ?