Today’s topics Java Syntax and Grammars Sample Programs Upcoming More Java Reading Great Ideas, Chapter 2.

Slides:



Advertisements
Similar presentations
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
Advertisements

Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Java.  Java is an object-oriented programming language.  Java is important to us because Android programming uses Java.  However, Java is much more.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
Excerpts from Introduction to Java Programming, 4E Author: Y. Daniel Liang (Copyright by Prentice Hall)
Introduction to Java Programming, 4E
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
1 Programming Languages Translation  Lecture Objectives:  Be able to list and explain five features of the Java programming language.  Be able to explain.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
Introduction to a Programming Environment
Chapter 1 Program Design
Chapter 10 Application Development. Chapter Goals Describe the application development process and the role of methodologies, models and tools Compare.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
9-Aug-15 Vocabulary. Programming Vocabulary Watch closely, you might even want to take some notes. There’s a short quiz at the end of this presentation!
Getting Started with Java
1 CS101 Introduction to Computing Lecture 19 Programming Languages.
C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine.
BASIC JAVA PROGRAMMING TUTORIAL. History  James Gosling and Sun Microsystems  Oak  Java, May 20, 1995, Sun World  Hot Java –The first Java-enabled.
CS102 Introduction to Computer Programming
Computer Programming 12 Mr. Jean March 3 rd, 2014.
Chapter 9 Interactive Multimedia Authoring with Flash - Introduction to Programming “Computers and Creativity” Richard D. Webster, COSC 109 Instructor.
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.
CS413: Java Programming language Applications Applets
Java Workshop for Teachers May 6, 2005 A Brief Look at the Java Programming Language.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
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.
Java Lecture 16: Dolores Zage. WWW n Was a method for distributing passive information n added forms and image maps n interaction was only a new way to.
Java Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
CS101 Introduction to Computing Lecture Programming Languages.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
CompSci Today’s topics Designing and Implementing Algorithms Problem solving Pseudocode Java Syntax and Grammars Upcoming More Java Acknowledgements.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
University of Houston-Clear Lake Proprietary© 1997 Evolution of Programming Languages Basic cycle of improvement –Experience software difficulties –Theory.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
POS 406 Java Technology And Beginning Java Code
1 2. Program Construction in Java Programming Fundamentals.
Introduction to Java Programming with Forte Y. Daniel Liang.
1 Programming Fundamentals AITI-GP. 2 Introduction to Programming.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
CompSci Today’s topics Java Review Just a bunch of headings meant to trigger questions A contraction of previous notes Upcoming Midterm Exam Reading.
Compiling and the Java Virtual Machine (JVM). The syntax of Pseudocode is pretty loose –visual validation encourages a permissive approach –emphasized.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Introduction To JAVA By Ihtesham Ul Haq. Course Objectives Upon completing the course, you will understand Upon completing the course, you will understand.
Lecture 8 February 29, Topics Questions about Exercise 4, due Thursday? Object Based Programming (Chapter 8) –Basic Principles –Methods –Fields.
What Is Java? According to Sun in a white paper: Java: A simple, object-oriented, network-savvy, interpreted, robust, secure, architecture-neutral, portable,
CPS Today’s topics Algorithms Java Syntax and Grammars Upcoming More Java Reading Great Ideas, Chapter 2.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
CPS Topics l Networks revisited l Java intro l Decision Trees l Problem solving and computing with numbers l Upcoming ä Numeric computation Course.
1 CS161 Introduction to Computer Science Topic #9.
Java Buzzwords.
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
Introduction to Java Programming. 2 Chapter 1 Introduction to Java and Forte F What Is Java? F Getting Started With Java Programming –Create, Compile.
Introduction to OOP CPS235: Introduction.
CHAPTER Agenda Applets Servelets Browsers HelloWorld.
Today’s topics Java Input More Syntax Upcoming Decision Trees More formal treatment of grammers Reading Great Ideas, Chapter 2.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 15: Java Basics Fundamentals of Web Programming.
Lesson 2: First Java Programs. 2.1 Why Java? Java is one of the most popular programming languages in the world. Java is a modern object-oriented programming.
Introduction to Java Programming, 4E Y. Daniel Liang.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Done By: Ashlee Lizarraga Ricky Usher Jacinto Roches Eli Gomez
Chapter 1 Introduction to Computers, Programs, and Java
Introduction Enosis Learning.
Introduction Enosis Learning.
Introducing Java.
Chap 1. Getting Started Objectives
Presentation transcript:

Today’s topics Java Syntax and Grammars Sample Programs Upcoming More Java Reading Great Ideas, Chapter 2

Java! Java is a buzzword-enabled language From Sun (the developers of Java), “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high performance, multi-threaded, and dynamic language.” What do all of those terms mean?

A programming language A vocabulary and set of syntactical (grammatical) rules for instructing a computer to perform specific tasks You can do most anything in any programming language A particular language encourages one to do things in a certain way A Question for the course: Is this a fair characterization? “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high performance, multi-threaded, and dynamic language.” Java!

Based on popular languages called C and C++ C: old, pretty bare bones language C++: newer, more complicated language Start from C and add some of C++’s more useful features From Gosling, the creator, “Java omits many rarely used, poorly understood, confusing features of C++ that in our experience bring more grief than benefits.” Question: Is Java really all that simple? “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high performance, multi-threaded, and dynamic language.” Java!

The object-oriented paradigm Problems and their solutions are packaged in terms of classes The information in a class is the data The functionality in a class is the method A class provides the framework for building objects Object-oriented programming (OOP) allows pieces of programs to be used in other contexts more easily. “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high performance, multi-threaded, and dynamic language.” Java!

A distributed system is one where multiple separate computer systems are involved Electronic card catalogs The web Java was designed for the web “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high performance, multi-threaded, and dynamic language.” Java!

Java a high-level language High-level languages must be translated to a computer’s native tongue, machine language Interpreted high-level languages are translated to an intermediate form and then carried out (run or executed) using an interpreter. Why? We’ll learn more about this later “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high performance, multi-threaded, and dynamic language.” Java!

Programs will have errors, but a good program degrades reasonably A robust program may not do exactly what it is supposed to do, but it should not bring down other unrelated programs down with it “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high performance, multi-threaded, and dynamic language.” Java!

Security: techniques that ensure that data stored on a computer cannot be read or compromised A program is running on your computer. What is to stop it from erasing all of your data, accidentally or otherwise? Question: Is Java really all that secure? “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high performance, multi-threaded, and dynamic language.” Java!

A language is architecture-neutral if it does not prefer a particular type of computer architectures E.g. The Macintosh processor family (PowerPC) and the PC (x86- Pentium) family have their own respective strengths and weaknesses. It is not too hard to construct a program that will run faster on one than an other. A particular program is never entirely architecture neutral though Question: When is being architecturally neutral a bad thing? “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high performance, multi-threaded, and dynamic language.” Java!

A program is portable if it will work the same (roughly) on many different computer systems HTML is also platform-independent or portable A whole lot of effort is currently spent porting non-portable code “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high performance, multi-threaded, and dynamic language.” Java!

Performance: speed in completing some task Performance is everything to most computer and software manufacturers. Story: If the transportation industry kept up with the computer industry, one would be able to now buy a Roll Royce that could drive across country in 5 minutes for $35. Rebuttal: It would crash once a week, killing everyone on board. “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high performance, multi-threaded, and dynamic language.” Java!

A thread is a part of the program that can operate independently of its other parts Multi-threaded programs can do multiple things at once e.g. download a file from the web while still looking at other web pages Question: What is the problem with multiple agents working at the same time? Synchronization “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high performance, multi-threaded, and dynamic language.” Java!

Dynamic refers to actions that take place at the moment they are needed rather than in advance Antonym: static A dynamic program can Ask for more or less resources as it runs Use the most recent version of some code that is available Question: Why is being dynamic a good thing? “Java is a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high performance, multi-threaded, and dynamic language.” Java!

A First Java Program import java.awt.*; public class HelloWorld extends java.applet.Applet { TextField m1, m2; public void init() { m1 = new TextField(60); m2 = new TextField(60); m1.SetText(”Hello World”); m2.SetText(”This is a simple Java test.”); add(m1); add(m2); }

Things to note: Program is a class Class contains data and methods Methods also called functions Programs designed for Web use are called applets Method init( ) always started for applets add statements needed for layout Applet invoked by way of an HTML file Program tested with Web browser or appletviewer We will normally use our web pages Note points of grammar … Semicolons ;, braces { }, parentheses ( ), etc.

Sample html file Can have separate web page: The textfield demo program. This tests the textfield capability. Or can incorporate the following line in any web page:

Definitions Algorithm: ordered set of unambiguous executable steps, defining a terminating process Program: instructions executed by a computer Applet: Java program that is executed in a program such as the appletviewer or a Java-enabled web browser Class: family of components sharing common characteristics consisting of: Data: information Methods: functionality Object: instantiation of a class Variable: represent value stored in computer memory. A variable must be defined or declared before being used Sometimes synonymous with object

Reflect on our progress What good is HelloWorld ? What have we accomplished? Can link to our web page. Want something more. Programs should do something for us. Just putting a message on the screen is pretty lame … Program results need to change or vary as a result of: Our actions Other outside data

Decision trees if statement if (logical expression) { ”true” actions } if-else statement if (logical expression) { ”true” actions } else { ”false” actions } Logical expressions analogous to yes or no questions true or false Statements that are true (5 < 7) (100 = = 100) (100 != 10) (10 <= 10) Statements that are false (-2 > -1) (10 != 10)

Using Buttons with if statements What does it mean to have an interactive program? Computer must be waiting for your actions. Like waiting for the phone to ring for an important call Need something called a “listener” Also need to create Buttons Example will show how With multiple Buttons, need to know which one was pressed Like having different tones for front and back door bell buttons

Program using Buttons: 1 public class TrafficLight extends Applet implements ActionListener { TextField m1, m2; Button b1, b2, b3; public void init () { m1 = new TextField(80); m1.setText ("What are you going to do when the light is:"); b1 = new Button("GREEN"); b2 = new Button("YELLOW"); b3 = new Button("RED"); m2 = new TextField(80); add(m1); add(b1); add(b2); add(b3); add(m2);

Program using Buttons: 2 b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); } Have Invoked the listener with statements above We have “told” the listener about each of the 3 buttons Now: Need to write the listener Listener must be named actionPerformed Using if statements, it will figure out which button was pushed and take the desired action

Program using Buttons: 3 public void actionPerformed(ActionEvent event) { Object cause = event.getSource(); if (cause == b1) { m2.setText("Keep on rolling."); } if (cause == b2) { m2.setText("Step on it! You can make it!"); } if (cause == b3) { m2.setText("I suppose you'll have to stop."); }

Think about Decision Tree Have shown the pieces needed to implement tree such as is shown on next slide Think about how you might accomplish this What are some of the problems you anticipate Why do we have numbers at each “node”? Meanwhile Cover a bit more of Java

A decision tree He received the Physics Price in Try A. Solzhenitsyn, Literature Look up the Peace Prize in Try the Medicine Prize in Would you prefer a humanitarian? Would you like to read about a scientist? Would you like to read about Einstein?

More Java Syntax Assignment statement variable = expression; Method invocation Also called function or procedure Invoking also called “calling” a function Methods can take arguments button.setText(”This text is an argument”); init() Variable declaration VariableType variableName; Button choice;

Tomorrow’s topic More Java Read GI Chapter 2 Lab starts Tomorrow (Tuesday, 05/24) Prelab 1 online (due before lab!) Prelab 2 online too...(due before lab2, Thursday (05/26))