Intro to Programming Lecture 13

Slides:



Advertisements
Similar presentations
CS324e - Elements of Graphics and Visualization A Little Java A Little Python.
Advertisements

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Program development.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. OBJECTIVES FOR THIS UNIT Upon completion of this unit, you should be able to: Explain the Java virtual machine.
CIT 590 Intro to Programming Java lecture 3. Hashmaps The equivalent of python dictionaries. With both ArrayLists and Hashmaps, the syntax only allows.
CIT 590 Intro to Programming Java lecture 4. Agenda Types Collections – Arrays, ArrayLists, HashMaps Variable scoping Access modifiers – public, private,
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
11-Jun-15 Just Enough Java. 2 What is Java? Java is a programming language: a language that you can learn to write, and the computer can be made to understand.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Structure of.
Introduction to Computers and Programming Lecture 5 Boolean type; if statement Professor: Evan Korth New York University.
Outline Java program structure Basic program elements
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
1 Programming Languages Translation  Lecture Objectives:  Be able to list and explain five features of the Java programming language.  Be able to explain.
Unit2: Object-oriented programming Getting started with Java Jin Sa.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
CIT 590 Intro to Programming First lecture on Java.
The Ruby Programming Language
Winter 2006CISC121 - Prof. McLeod1 Welcome to CISC121 Prof. (Alan) McLeod – Web site at: All.
Introducing Java.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Hello AP Computer Science!. What are some of the things that you have used computers for?
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
COMP 110 Spring Announcements Computers in class on Friday: Lab Office Hours: Monday 12-2 New students see me after class Administrative Changes.
CS107 Introduction to Computer Science Java Basics.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
Chapter 2: Everything is an Object ● C++ has many non object oriented features inherited from C. It is a hybrid language meaning that it support different.
Effective Java: Generics Last Updated: Spring 2009.
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
JAVA JAVA is an object-oriented programming (OOP) language introduced by Sun Microsystems in In the Java programming language: A program is made.
Programming in C#. I. Introduction C# (or C-Sharp) is a programming language. C# is used to write software that runs on the.NET Framework. Although C#
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
CIT 590 Intro to Programming Lecture 4. Agenda Doubts from HW1 and HW2 Main function Break, quit, exit Function argument names, scope What is modularity!
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Style Guidelines. Why do we need style?  Good programming style helps promote the readability, clarity and comprehensibility of your code.
CIT 590 Intro to Programming First lecture on Java.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
Introduction to Java Java Translation Program Structure
Fall 2015CISC124 - Prof. McLeod1 CISC124 Have you filled out the lab section survey? (As of last night 54 left to fill out the survey.) TA names have been.
1 Java Review Outline Java Primitives, Program Structure Operators, Control Flow, Loops Classes and Objects Most of these slides are based on “Intro to.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
Hello Computer Science!. Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening.
Java FilesOops - Mistake Java lingoSyntax
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
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.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
1 Java Review Outline Java Primitives, Program Structure Operators, Control Flow, Loops Classes and Objects Arrays and ArrayList Most of these slides are.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Eastside Robotics Alliance / Newport Robotics Group 1 T/Th, 6:30 – 8:30 PM Big Picture School Day 3 · 10/9/2014.
Dept of Computer Science University of Maryland College Park
Chapter 3 GC 101 Java Fundamentals.
Lecture 5: Some more Java!
Internet and Java Foundations, Programming and Practice
Java Review Most of these slides are based on
CompSci 230 Software Construction
Tonga Institute of Higher Education
Chapter 1: Computer Systems
Coding Concepts (Standards and Testing)
Java Review Most of these slides are based on
Anatomy of a Java Program
Just Enough Java 17-May-19.
Presentation transcript:

Intro to Programming Lecture 13 CIT 590 Intro to Programming Lecture 13

Topics for midterm Lecture notes Chapters 1 through 9 The book is really good. Do not worry about reading from any place else Some concepts like recursion are explained in greater detail in slides Read the unit testing page at http://www.cis.upenn.edu/~matuszek/cit590-2013/Pages/unit-testing-in-python.html In the files chapter, the concepts of reading from a URL and persistence and pickle can be safely ignored

Topics for midterm Ignore the starred portions of the Classes chapter (chapter 7) Functional programming – skip the last 2 pages Pay special attention to list comprehensions If you want a more detailed example of classes http://code.activestate.com/recipes/286239-binary-ordered-tree/ Today’s lecture is included in the midterm While studying, if you have questions please post on Piazza Turn to the internet only as a last resort – mainly because unless you are an experienced programmer the internet tends to confound more than explain

Agenda Intro to Eclipse Java Python to Java translation http://www.cis.upenn.edu/~matuszek/cit590-2013/Pages/python-to-java.html has most of the content of today’s lecture

Java reference books No need to purchase any book I will use Dr Dave’s slides from this point forth and they have most/all required content Unlike the Python book, there isn’t a compact Java book Popular books Head first Java Java in a nutshell (O’Reilly book) is a good desktop reference http://docs.oracle.com/javase/7/docs/api/ (Javadocs) Do not buy ‘Java – the complete reference’. It is rarely used ….

Eclipse IDE (integrated development environment) – way more fully featured than Python IDLE Installation involves installing Java and then installing Eclipse Remember to have either only 32 bit installs or only 64 bit installs

Java Been around for over 15 years Class-based, object-oriented Named after the large amounts of Java coffee consumed by the creators Portability was a big goal when Java was made. Computer programs written in the Java language must run similarly on any hardware/operating-system platform Achieved by compiling down to Java bytecode as opposed to machine specific bytecode

Making the transition from Python Every variable has a type int x = 0; Statements end with a semi colon Everything is within a class! Statements are written within a method and a method is written within a class Braces used instead of indentation for (int x =0; x<10; x++){ //do something }

Style (please follow these) While indentation will not make the program fail the way it does in Python, do not stop indenting your programs Variables and method names begin with a lower case letter, and are camelCase. Names of classes and interfaces begin with a capital letter, and are CamelCase Constants (final variables) are written in ALL_CAPS_WITH_UNDERSCORES. Opening braces, {, go at the end of a line, not on a line by themselves. This differs from the C/C++ convention

General program outline package myPackage; // optional package declaration import java.util.*; // imports go here; util is needed for ArrayList, HashSet public class MyClass { // file must be named myPackage/MyClass.java (note capitalization!) int myInstanceVar; // declare instance variables here public static void main(String[] args) { new MyClass().myStartingMethod(); } void myStartingMethod() { // declare local variables here // statements go here; can call other methods

Strings and comments “arvind” is a string ‘a’ is a character There is a difference between a single character and a single character string. Unlike Python, please be careful about when you are using single versus double quotes String concat still works via the + operator docStrings – just use Eclipse to generate the template and you will never make a mistake Single line comments are made with //

Variables and types double distance; String firstName; int count = 0; char[][] letters = new char[5][5]; declares an array of arrays AND creates it ArrayList<String> students; declares but does NOT create an ArrayList final int CLASS_LIMIT = 38; // constant

Python lists = java arrays int[] numbers = {1, 2, 3, 4};  new int[] {1, 2, 3, 4} Indexing works in the same manner as Python However there is no slicing

Python lists = java ArrayList ArrayList<String> languages = new ArrayList<String>(); languages.add("Python"); languages.set(0, "Java"); You do not have to declare the size of an ArrayList You can append to an existing ArrayList More flexible but if you have use cases where you have specific dimensions you will use an array.

Sets in python = java hashset When making a new HashSet you will start getting warning messages if you declare it without a type. What do these angle brackets actually really mean? These correspond to Java Generics More detailed discussion at http://www.angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html

Dictionaries in python = Hashmap Hashmap<String,Integer> map = new Hashmap<String,Integer>() Put (key, value) Get(key)