Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-

Slides:



Advertisements
Similar presentations
Chapter 1 Introduction to JAVA. Why Learn JAVA? Java is one of the fastest growing programming language in the world. Java is one of the fastest growing.
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Chapter 2 - Introduction to Java Applications
Object Orientated Programming
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
Excerpts from Introduction to Java Programming, 4E Author: Y. Daniel Liang (Copyright by Prentice Hall)
Introduction to Java Programming, 4E
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.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
L EC. 01: J AVA FUNDAMENTALS Fall Java Programming.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
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.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CSCI 224 Introduction to Java Programming. Course Objectives  Learn the Java programming language: Syntax, Idioms Patterns, Styles  Become comfortable.
Object Oriented Systems Lecture 01 First Java Programming Jaeki Song.
Chapter 1: Creating Java Programs
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
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 Part I : Chapter 01 Introduction to Java Programming.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
© 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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Programs.
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.
Clement Allen, PhD Florida A&M University SUMMER 2006.
Jaeki Song Lecture 01 Introduction to Java Programming.
The Joy of Programming (also known as) Introduction to Object-Oriented Programming.
Java Programming, 2E Introductory 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.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Introduction to Java Programming. Introduction Course Objectives Organization of the Book.
1 Chapter 3 Introduction to Computers, Programs, and Java.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
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.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
1 COMP 241: Object-Oriented Programming with Java Fall 2004 Lecture 1 September 27, 2004 Serdar Taşıran.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Jaeki Song JAVA Lecture 02 Introduction to Java -The First Java Application-
J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition D.S. Malik D.S. Malik.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Introduction to Java Applications Part I. In this chapter you will learn:  Why Java?  History of Java.  To write simple Java applications. 2.
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.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
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.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Introduction to JAVA Programming
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.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
GC101 Introduction to computer and program
Java programming lecture one
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 2 - Introduction to Java Applications
Chapter 1 Introduction to Computers, Programs, and Java
F II 2. Simple Java Programs Objectives
Computer Programming-1 CSC 111
Outcome of the Lecture Upon completion of this lecture you will be able to understand Fundamentals and Characteristics of Java Language Basic Terminology.
Presentation transcript:

Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-

Jaeki Song ISQS6337 JAVA Outline Object Oriented Programming Class Object Important Concepts Java Application

Jaeki Song ISQS6337 JAVA What is 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

Jaeki Song ISQS6337 JAVA 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

Jaeki Song ISQS6337 JAVA 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

Jaeki Song ISQS6337 JAVA 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

Jaeki Song ISQS6337 JAVA 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

Jaeki Song ISQS6337 JAVA 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.

Jaeki Song ISQS6337 JAVA Creating First Application The Java 2 Platform, Standard Edition JBuilder4 or 5

Jaeki Song ISQS6337 JAVA JBuilder: Interface Main menu Project toolbar Project pane Structure pane Content pane File tab File view tab

Jaeki Song ISQS6337 JAVA 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”); }

Jaeki Song ISQS6337 JAVA 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 */

Jaeki Song ISQS6337 JAVA 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

Jaeki Song ISQS6337 JAVA 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

Jaeki Song ISQS6337 JAVA 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) { … }

Jaeki Song ISQS6337 JAVA 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 { }

Jaeki Song ISQS6337 JAVA 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

Jaeki Song ISQS6337 JAVA 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

Jaeki Song ISQS6337 JAVA 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

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

Jaeki Song ISQS6337 JAVA 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 }

Jaeki Song ISQS6337 JAVA Output

Jaeki Song ISQS6337 JAVA 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”);

Jaeki Song ISQS6337 JAVA 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); }

Jaeki Song ISQS6337 JAVA Output