Data Structures Lecture 1

Similar documents
Introduction to Java

AP Computer Science Static Methods, Strings, User Input

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

1001ICT Introduction To Programming Lecture Notes

Basics of Java Programming Input and the Scanner class

JAVA ARRAY EXAMPLE PDF

Install Java Development Kit (JDK) 1.8

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Sample CSE8A midterm Multiple Choice (circle one)

Introduction to Programming

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Using Files as Input/Output in Java 5.0 Applications

Building Java Programs

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Contents. Java - An Introduction. Java Milestones. Java and its Evolution

Java applets. SwIG Jing He

Topic 11 Scanner object, conditional execution

6.1. Example: A Tip Calculator 6-1

Building Java Programs

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

Comp 248 Introduction to Programming

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

More on Objects and Classes

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

An Overview of Java. overview-1

Building Java Programs

Chapter 5 Aspect Oriented Programming

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

Chapter 3. Input and output. 3.1 The System class

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

SE 450 Object-Oriented Software Development. Requirements. Topics. Textbooks. Prerequisite: CSC 416

Part I. Multiple Choice Questions (2 points each):

Course Intro Instructor Intro Java Intro, Continued

Java Programming Unit 1. Your first Java Program Eclipse IDE

WHAT ARE PACKAGES? A package is a collection of related classes. This is similar to the notion that a class is a collection of related methods.

Programming Languages CIS 443

Chapter 2 Basics of Scanning and Conventional Programming in Java

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

13 File Output and Input

Object-Oriented Programming in Java

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

9/11/15. What is Programming? CSCI 209: Software Development. Discussion: What Is Good Software? Characteristics of Good Software?

How to use the Eclipse IDE for Java Application Development

Programmierpraktikum

Java Crash Course Part I

CS 106 Introduction to Computer Science I

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Lab 1A. Create a simple Java application using JBuilder. Part 1: make the simplest Java application Hello World 1. Start Jbuilder. 2.

A Short Introduction to Writing Java Code. Zoltán Majó

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

Homework/Program #5 Solutions

Introduction to programming

Building Java Programs

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

Lecture 1 Introduction to Java

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

J a v a Quiz (Unit 3, Test 0 Practice)

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

Problem Solving. Software Engineering. Behavior. OCD in a Nutshell. Behavior. Objects Operations Algorithm. Object-Centered Design

COS 217: Introduction to Programming Systems

Quick Introduction to Java

Tutorial 5: Developing Java applications

For live Java EE training, please see training courses

CS 209 Programming in Java #1

CS170 Lab 11 Abstract Data Types & Objects

How to Install Java onto your system

Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output

Konzepte objektorientierter Programmierung

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

LAB4 Making Classes and Objects

Introduction to Object-Oriented Programming

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

Android Programming and Security

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

CS 253: Intro to Systems Programming

02 B The Java Virtual Machine

JAVA.UTIL.SCANNER CLASS

Principles of Programming Languages Topic: Introduction Professor Louis Steinberg

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

CS 121 Intro to Programming:Java - Lecture 11 Announcements

CPLEX Tutorial Handout

Interactive Applications (CLI) and Math

Visit us at

Introduction to Java. CS 3: Computer Programming in Java

Interactive Programs and Graphics in Java

CSC 551: Web Programming. Spring 2004

AP Computer Science File Input with Scanner

Selenium Automation set up with TestNG and Eclipse- A Beginners Guide

Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion

Transcription:

Fall 2015 Fang Yu Software Security Lab. Dept. Management Information Systems, National Chengchi University Data Structures Lecture 1

A brief review of Java programming

Popularity of Programming Languages

History of PL Popularity

About Java Java is One of the most popular languages in the past years: Simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, multi-threaded, dynamic, and more. (http://www.tiobe.com/index.php/ content/paperinfo/tpci/index.html) Classes, Types, and Objects An object is the basic unit in Java A class defines the type of an object

Java Programming Basics A class consists of fields (to store data) methods (to define operations that can act on data) public class Hello { public static int var; public static void say(string s) { System.out.print( Hello +s); public static void main(string[] argv) { say( World!"); The class name (Save this code as Hello.java) A field A method The main method (The entry point while executing the program)

Modifiers public indicates that anyone can run/extend/ import this class static indicates the field/method belongs to the class, public class Hello { not objects public static int var; public static void say(string s) { System.out.print( Hello +s); public static void main(string[] argv) { say( World!"); void indicates that the method returns nothing

How Java works Compile Interpret Java source code Java bytecode result Hello.java Hello.class Java Virtual Machine Execute your code on command line javac Hello.java to generate Hello.class java Hello to execute the bytecode

Example: Operator Operators are similar to C++ E.g., =, +, -, *, /, % A simple example: Sum 1 to 100 using a formula javac Example.java java Example 1+2+...+100 = 5050 public class Example { public static void main(string[] argv) { int n = 100; System.out.println("1+2+...+"+n+" = " + ( n * (n + 1) / 2));

Example: Loop Sum 1 to 100 using a method with for-loop public class Example { public static int sum(int n) { return n*(n+1)/2; public static void main(string[] argv) { int n = 100; System.out.println("1+2+...+"+n+" = " + sum(n)); javac Example.java java Example 1+2+...+100 = 5050

Example: Loop Sum 1 to 100 using a method with for-loop public class Example { public static int sum(int n) { int total = 0; for (int i = 1; i <= n; i++) { total += i; return total; public static void main(string[] argv) { int n = 100; System.out.println("1+2+...+"+n+" = " + sum(n)); javac Example.java java Example 1+2+...+100 = 5050

Use pre-defined class library Use java.util.scanner for getting inputs The Scanner class reads the input stream and divides it into tokens by delimiters (whitespace) The Scanner class includes the following methods: hasnext() next() hasnexttype() nexttype() Return true if there is another token Return the next token Return true if there is another token that can be interpreted as the Type Return the next token that can be interpreted as the Type

Use pre-defined class library Import the package import java.util.scanner; Construct a Scanner object: Scanner in = new Scanner(System.in); Call its method: e.g., in.nextint() or in.hasnext()

Example: Get a user input Sum using java.util.scanner class import java.util.scanner; public class Example { public static int sum(int n) { int total = 0; for (int i = 1; i <= n; i++) { total += i; return total; public static void main(string[] argv) { Scanner in = new Scanner(System.in); System.out.print( Enter n: ); int n = in.nextint(); System.out.println("1+2+...+"+n+" = " + sum(n)); javac Example.java java Example Enter n: 100 1+2+...+100 = 5050

Example: Get user inputs Sum using java.util.scanner class import java.util.scanner; public class Example { public static int sum(int n) { int total = 0; for (int i = 1; i <= n; i++) { total += i; return total; public static int sum(int n1, n2) { int total = 0; for (int i = n1; i <= n2; i++) { total += i; return total; public static void main(string[] argv) { Scanner in = new Scanner(System.in); System.out.print( Enter n1 n2: ); int n1 = in.nextint(); int n2 = in.nextint(); System.out.println(n1+ +...+"+n2+" = " + sum(n1,n2)); javac Example.java java Example Enter n1 n2: 10 100 10+...+100 = 5005

About Eclipse Eclipse is An Integrated Development Environment (IDE) for Java and also many other languages An open source platform (free!) maintained by many software development leaders like IBM and Borland

Eclipse Extension Furthermore, Eclipse provides a common environment that companies can modify and customize by creating plug-ins These plug-ins can add functionality to Eclipse like modeling, UML, XML, metrics, reliability reports, and other information. The Eclipse web site has a list of links to many popular plug-in repositories

A tutorial A nice introduction to eclipse by L. Willaims et al. NCSU. http://agile.csc.ncsu.edu/sematerials/tutorials/eclipse/ A nice java/eclipse tutorial on youtube: http://www.youtube.com/watch?v=ugmhks4k13g

Homework 1 (Due on 9/24) BMI Calculator: BMI = ( Weight in Kilograms / ( Height in Meters x Height in Meters ) ) Enter Height and Weight, return BMI and Alert! You are way out of shape if BMI >= 30 Warning! Watch your weight if 30 > BMI >= 26 Healthy if 26 > BMI >= 20 Slim if 20 > BMI Use Eclipse to write/execute/debug your java code Upload your code using WM3 (no direct copy accepted) TAs will show you clear hints to do so in tomorrow s lab

Coming up We will discuss object oriented design and abstract data type next week Read TB Chapter 1 and Chapter 2