Introduction Richard Soden ECET-370 Data Structures and Algorithms
Topics <ul><li>Course Introduction </li></ul><ul><ul><li>Abstract Data Types (ADTs) </li></ul></ul><ul><ul><li>Terminology...
Organizing Our Lives <ul><li>For each of the above examples, consider how the objects are organized </li></ul>
Organizing Computer Data <ul><li>Computer stores/organizes items in similar manners as the examples </li></ul><ul><li>Ways...
ADT Terminology  <ul><li>An ADT specifies: </li></ul><ul><ul><li>Kind of data that is stored </li></ul></ul><ul><ul><li>Op...
Types of ADTs <ul><li>Bag </li></ul><ul><ul><li>Unordered collection, may contain duplicates </li></ul></ul><ul><li>List <...
Brief History of Java <ul><li>James Gosling and Sun Microsystems 1991 </li></ul><ul><li>Originally called Oak </li></ul><u...
JDK Versions <ul><li>JDK 1.02 (1/1996) </li></ul><ul><li>JDK 1.1 (2/1997) </li></ul><ul><li>J2SE 1.2 (12/1998) </li></ul><...
JDK Editions <ul><li>Java Standard Edition (J2SE) </li></ul><ul><ul><li>J2SE can be used to develop client-side standalone...
Characteristics of Java <ul><li>Java is simple </li></ul><ul><li>Java is object-oriented </li></ul><ul><li>Java is distrib...
Free Java Development Tools <ul><li>Editors: </li></ul><ul><ul><li>TextPad </li></ul></ul><ul><li>Integrated Development E...
A Simple Application <ul><li>Example </li></ul><ul><li>/** This application program prints  </li></ul><ul><li>*  Welcome t...
Creating and Compiling Programs <ul><li>On command line: </li></ul><ul><li>javac  filename .java </li></ul><ul><li>Compili...
Executing Applications <ul><li>On command line: </li></ul><ul><ul><li>java  classname </li></ul></ul>
Example <ul><li>javac Welcome.java </li></ul><ul><li>java Welcome </li></ul><ul><li>output:... </li></ul>
Anatomy of a Java Program <ul><li>Comments </li></ul><ul><li>Reserved words </li></ul><ul><li>Modifiers </li></ul><ul><li>...
Comments <ul><li>Line comments are preceded by two slashes ( // ) in a line, and Block comments are enclosed between  /*  ...
Reserved Words <ul><li>Reserved words  or  keywords  are words that have a specific meaning to the compiler and cannot be ...
Modifiers <ul><li>Java uses certain reserved words called  modifiers  that specify the properties of the data, methods, an...
Statements <ul><li>A  statement  represents an action or a sequence of actions. The statement: </li></ul><ul><li>System.ou...
Blocks A pair of braces in a program forms a block that groups components of a program.
Classes <ul><li>The  class  is the essential Java construct. </li></ul><ul><li>A class is a template or blueprint for  obj...
Methods <ul><li>System.out.println  is a  method : a collection of statements that performs a sequence of operations.  </l...
main Method <ul><li>The  main  method provides the control of program flow. The Java interpreter executes the application ...
Getting User Input <ul><li>The Java class Scanner is one of the many predefined classes in the Java system, which can be r...
<ul><li>/** InputExample.java: This application program repeatedly  </li></ul><ul><li>asks the user if he wants to learn J...
Getting User Input <ul><li>Three things are needed to get user input with Scanner: </li></ul><ul><li>1.  Import the Java S...
Scanner Functions <ul><li>next()   Returns next word as a String  </li></ul><ul><li>nextLine()   Returns next line as a St...
Thank you!
Upcoming SlideShare
Loading in …5
×

Introduction

675 views

Published on

Intro for ECET370 Data Structures & Algorithms

  • Be the first to comment

  • Be the first to like this

Introduction

  1. 1. Introduction Richard Soden ECET-370 Data Structures and Algorithms
  2. 2. Topics <ul><li>Course Introduction </li></ul><ul><ul><li>Abstract Data Types (ADTs) </li></ul></ul><ul><ul><li>Terminology </li></ul></ul><ul><ul><li>Types of ADTs </li></ul></ul><ul><li>Introduction to Java </li></ul><ul><ul><li>Background and Characteristics </li></ul></ul><ul><ul><li>Java Program Development </li></ul></ul><ul><ul><li>Anatomy of a Simple Output Program </li></ul></ul><ul><ul><li>Getting User Input: The Scanner Class </li></ul></ul>
  3. 3. Organizing Our Lives <ul><li>For each of the above examples, consider how the objects are organized </li></ul>
  4. 4. Organizing Computer Data <ul><li>Computer stores/organizes items in similar manners as the examples </li></ul><ul><li>Ways of organizing data are represented by specifications called Abstract Data Types (ADTs) </li></ul>
  5. 5. ADT Terminology <ul><li>An ADT specifies: </li></ul><ul><ul><li>Kind of data that is stored </li></ul></ul><ul><ul><li>Operations that can be done on the data </li></ul></ul><ul><li>Data structure: implementation of an ADT within a programming language, sometimes called a Container </li></ul><ul><li>Collection: a Data Structure that contains a group of objects </li></ul>
  6. 6. Types of ADTs <ul><li>Bag </li></ul><ul><ul><li>Unordered collection, may contain duplicates </li></ul></ul><ul><li>List </li></ul><ul><ul><li>A collection that numbers its items </li></ul></ul><ul><li>Stack </li></ul><ul><ul><li>Orders items chronologically (Last In, First out) </li></ul></ul><ul><li>Queue </li></ul><ul><ul><li>Orders items chronologically (First in, First out) </li></ul></ul><ul><li>Dictionary </li></ul><ul><ul><li>Pairs of items – one is a key </li></ul></ul><ul><li>Tree </li></ul><ul><ul><li>Arranged in a hierarchy </li></ul></ul><ul><li>Graph </li></ul><ul><ul><li>Generalization of a tree </li></ul></ul>Match each of these to the pictures ? Click here to return to pictures
  7. 7. Brief History of Java <ul><li>James Gosling and Sun Microsystems 1991 </li></ul><ul><li>Originally called Oak </li></ul><ul><li>Java, May 20, 1995, Sun World </li></ul><ul><li>HotJava </li></ul><ul><ul><li>The first Java-enabled Web browser </li></ul></ul>
  8. 8. JDK Versions <ul><li>JDK 1.02 (1/1996) </li></ul><ul><li>JDK 1.1 (2/1997) </li></ul><ul><li>J2SE 1.2 (12/1998) </li></ul><ul><li>J2SE 1.3 (5/2000) </li></ul><ul><li>J2SE 1.4 (2/2002) </li></ul><ul><li>J2SE 5.0 (9/2004) </li></ul><ul><li>Java SE 6 (12/2006) </li></ul><ul><li>Java SE 7 (Preview versions are available - codename Dolphin) </li></ul>
  9. 9. JDK Editions <ul><li>Java Standard Edition (J2SE) </li></ul><ul><ul><li>J2SE can be used to develop client-side standalone applications or applets. </li></ul></ul><ul><li>Java Enterprise Edition (J2EE) </li></ul><ul><ul><li>J2EE can be used to develop server-side applications such as Java servlets and Java ServerPages. </li></ul></ul><ul><li>Java Micro Edition (J2ME) </li></ul><ul><ul><li>J2ME can be used to develop applications for mobile devices such as cell phones. </li></ul></ul>
  10. 10. Characteristics of Java <ul><li>Java is simple </li></ul><ul><li>Java is object-oriented </li></ul><ul><li>Java is distributed </li></ul><ul><li>Java is interpreted </li></ul><ul><li>Java is robust </li></ul><ul><li>Java is secure </li></ul><ul><li>Java is architecture-neutral </li></ul><ul><li>Java is portable </li></ul><ul><li>Java is multithreaded </li></ul><ul><li>Java is dynamic </li></ul><ul><li>Java performance? </li></ul>
  11. 11. Free Java Development Tools <ul><li>Editors: </li></ul><ul><ul><li>TextPad </li></ul></ul><ul><li>Integrated Development Environments (IDEs): </li></ul><ul><ul><li>Xinox JCreator </li></ul></ul><ul><ul><li>NetBeans </li></ul></ul><ul><ul><li>Eclipse </li></ul></ul><ul><ul><li>Borland JBuilder </li></ul></ul><ul><ul><li>Oracle JDeveloper </li></ul></ul>
  12. 12. A Simple Application <ul><li>Example </li></ul><ul><li>/** This application program prints </li></ul><ul><li>* Welcome to Java! */ </li></ul><ul><li>public class Welcome { </li></ul><ul><li>public static void main(String[] args) { </li></ul><ul><li>System.out.println(&quot;Welcome to Java!&quot;); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Run
  13. 13. Creating and Compiling Programs <ul><li>On command line: </li></ul><ul><li>javac filename .java </li></ul><ul><li>Compiling produces Java Virtual Machine code called Bytecode </li></ul>
  14. 14. Executing Applications <ul><li>On command line: </li></ul><ul><ul><li>java classname </li></ul></ul>
  15. 15. Example <ul><li>javac Welcome.java </li></ul><ul><li>java Welcome </li></ul><ul><li>output:... </li></ul>
  16. 16. Anatomy of a Java Program <ul><li>Comments </li></ul><ul><li>Reserved words </li></ul><ul><li>Modifiers </li></ul><ul><li>Statements </li></ul><ul><li>Blocks </li></ul><ul><li>Classes </li></ul><ul><li>Methods </li></ul><ul><li>The main method </li></ul>
  17. 17. Comments <ul><li>Line comments are preceded by two slashes ( // ) in a line, and Block comments are enclosed between /* and */ in one or multiple lines. </li></ul><ul><li>When the compiler sees // , it ignores all text after // in the same line. When it sees /* , it scans for the next */ and ignores any text between /* and */ . </li></ul>
  18. 18. Reserved Words <ul><li>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 Example 1.1 are public , static , and void . </li></ul>
  19. 19. Modifiers <ul><li>Java uses certain reserved words called modifiers that specify the properties of the data, methods, and classes and how they can be used. </li></ul><ul><li>Examples of modifiers are public and static . Other modifiers are private , final , abstract , and protected . </li></ul><ul><li>A public datum, method, or class can be accessed by other programs. </li></ul><ul><li>A private datum or method cannot be accessed by other programs . </li></ul>
  20. 20. Statements <ul><li>A statement represents an action or a sequence of actions. The statement: </li></ul><ul><li>System.out.println(&quot;Welcome to Java!&quot;) ; </li></ul><ul><li>in the Example program is a statement to display the greeting &quot;Welcome to Java!&quot; </li></ul><ul><li>Every statement in Java ends with a semicolon (;). </li></ul>
  21. 21. Blocks A pair of braces in a program forms a block that groups components of a program.
  22. 22. Classes <ul><li>The class is the essential Java construct. </li></ul><ul><li>A class is a template or blueprint for objects. </li></ul><ul><li>To program in Java, you must understand classes and be able to write and use them. </li></ul>
  23. 23. Methods <ul><li>System.out.println is a method : a collection of statements that performs a sequence of operations. </li></ul><ul><li>It is used by invoking a statement with a string argument enclosed in parentheses. </li></ul><ul><li>In this case, the argument is &quot;Welcome to Java!&quot; </li></ul><ul><li>You can call the same println method with a different argument to print a different message. </li></ul>
  24. 24. main Method <ul><li>The main method provides the control of program flow. The Java interpreter executes the application by invoking the main method. </li></ul><ul><li>  </li></ul><ul><li>The main method looks like this: </li></ul><ul><li>  </li></ul><ul><li>public static void main(String[] args) { </li></ul><ul><li>// Statements; </li></ul><ul><li>} </li></ul>
  25. 25. Getting User Input <ul><li>The Java class Scanner is one of the many predefined classes in the Java system, which can be reused rather than “reinventing the wheel.” </li></ul><ul><li>The Scanner class is used to get user input in a command window as shown in the following program. </li></ul>
  26. 26. <ul><li>/** InputExample.java: This application program repeatedly </li></ul><ul><li>asks the user if he wants to learn Java until the user types “yes”. </li></ul><ul><li>*/ </li></ul><ul><li>import java.util.Scanner; // Note: Need to import Scanner </li></ul><ul><li>public class InputExample { </li></ul><ul><li>public static void main(String[] args) { </li></ul><ul><li> Scanner myInput = new Scanner(System.in); </li></ul><ul><li> String answer; </li></ul><ul><li> do { </li></ul><ul><li>System.out.println(&quot;Do you want to learn Java now?&quot;); </li></ul><ul><li>answer = myInput.next(); </li></ul><ul><li> } while (!answer.equals(&quot;yes&quot;)); </li></ul><ul><li> System.out.println(&quot;Excellent! Let's begin...&quot;); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Getting User Input Run
  27. 27. Getting User Input <ul><li>Three things are needed to get user input with Scanner: </li></ul><ul><li>1. Import the Java Scanner utility: </li></ul><ul><li>import java.util.Scanner; </li></ul><ul><li>2. Create a Scanner object that is attached to the “standard input stream” System.in: </li></ul><ul><li>Scanner myInput = </li></ul><ul><li> new Scanner(System.in); </li></ul><ul><li>3. Capture and store the next input using your Scanner object and appropriate input function: answer = myInput.next(); </li></ul>
  28. 28. Scanner Functions <ul><li>next() Returns next word as a String </li></ul><ul><li>nextLine() Returns next line as a String </li></ul><ul><li>nextInt() Returns next integer as an int </li></ul><ul><li>nextDouble Returns next double as a double </li></ul><ul><li>hasNext() Tests if there is another word </li></ul><ul><li>hasNextInt() Tests if next input is an int </li></ul><ul><li>hasNextDouble Tests if next input is a double </li></ul>
  29. 29. Thank you!

×