CIT 590 Intro to Programming First lecture on Java.

Slides:



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

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,
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.
Java Syntax Primitive data types Operators Control statements.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
CIT 590 Intro to Programming First lecture on Java.
Java Unit 9: Arrays Declaring and Processing Arrays.
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
© 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.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Intro to Programming Lecture 13
Java Language and SW Dev’t
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Basic Java Syntax CSE301 University of Sunderland Harry R Erwin, PhD.
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.
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.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Introduction to Java Java Translation Program Structure
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
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.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Everything is an object (CH-2) Manipulating Objects with References. Manipulating Objects with References. String s; String s = “IS2550” String s = new.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
CIT 590 Intro to Programming Lecture 13. Some Eclipse shortcuts CTRL + SHIFT + F – format file (proper indentation etc). Please do this before you submit.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Chapter 4Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapters 4 and 5: Excerpts l Class and Method Definitions l Information.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Eastside Robotics Alliance / Newport Robotics Group 1 T/Th, 6:30 – 8:30 PM Big Picture School Day 3 · 10/9/2014.
The need for Programming Languages
JAVA MULTIPLE CHOICE QUESTION.
Working with Java.
Some Eclipse shortcuts
Internet and Java Foundations, Programming and Practice
University of Central Florida COP 3330 Object Oriented Programming
CompSci 230 Software Construction
Chapter 1: Computer Systems
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Applying OO Concepts Using Java
Programs and Classes A program is made up from classes
Tonga Institute of Higher Education
Object Oriented Programming in java
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Java Programming Language
Java Basics Data Types in Java.
In this class, we will cover:
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

CIT 590 Intro to Programming First lecture on Java

Can we forget about Python? Syntactically yes! The concepts are being built upon though You cannot afford to forget about Modularization What is a class TDD Commenting your code Style (Java is stricter in many ways) Copy pasted code is a bad thing in any language Recursion

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 Introduction to Programming in Java – Sedgewick (Used in the undergrad intro class) Head first Java Java in a nutshell (O’Reilly book) is a good desktop reference (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

Customize Eclipse Can you run HelloWorld.java? Window -> Preferences Line numbers Please turn these on. It makes it easier to discuss your code if you can point to a line number

Java Been around for over 15 years Class-based, object-oriented Initially called Oak 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 }

Datatypes int, float, double boolean char String You also have the ability to do byte, short and long (8, 16, 64 bits) for an integer (generally not needed for this course). You might come across Integer, Boolean, Double etc. Do not worry about them for week one.

Style (please follow these) While indentation will not make the program fail the way it does in Python, do not stop indenting your programs CTRL + SHIFT + F CTRL + A, CTRL + I Those two shortcuts should fix most of your indentation issues 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 } }

Classes, methods public class Animal{ String name; int age; void birthday(){ age = age + 1; } String speak(String dialogue){ return dialogue + name; } } Return type has to be specified. Void means nothing is being returned Basic rule in Java – cannot put anything down without telling the reader its type.

Types! A method has to have a return type. Every argument to the method has to have a type. Every new variable has to declare its type Remember making a class is kind of like defining a datatype So a variable can of the type Animal for instance

Private, public, protected??? Do not worry about them for your first assignment These are called access modifiers You do not HAVE to specify them and Java’s defaults are ok initially

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 Java documentation /*** and then hit Enter fill in each item

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 students; declares but does NOT create an ArrayList final int CLASS_LIMIT = 38; // constant

The new keyword and constructors In Java everything(almost) is a class To create an instance of a class Animal a = new Animal(“Dog”) How do we know what arguments to pass? Special method called constructor Named the exact same as the class The Python word ‘self’ gets replaced by ‘this’ in Java. We will cover constructors in more detail

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 are also java ArrayList ArrayList languages = new ArrayList (); 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.