Introduction to Java https://tinyurl.com/y7bvpa9z

Similar documents
Introduction to Programming Using Java (98-388)

CSC Java Programming, Fall Java Data Types and Control Constructs

PROGRAMMING FUNDAMENTALS

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Selected Questions from by Nageshwara Rao

Computer Components. Software{ User Programs. Operating System. Hardware

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Getting started with Java

Java Basic Programming Constructs

Software Practice 1 Basic Grammar

CS 231 Data Structures and Algorithms, Fall 2016

Program Fundamentals

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

An overview of Java, Data types and variables

Java Programming. Atul Prakash

Computer Components. Software{ User Programs. Operating System. Hardware

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

CS 11 java track: lecture 1

CSC 1214: Object-Oriented Programming

Computer Programming, I. Laboratory Manual. Final Exam Solution

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Course Outline. Introduction to java

Introduce C# as Object Oriented programming language. Explain, tokens,

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object Oriented Programming Exception Handling

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Selected Java Topics

Software Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

University of Palestine. Mid Exam Total Grade: 100

Programming Language Concepts: Lecture 2

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Getting started with Java

Name of subject: JAVA PROGRAMMING Subject code: Semester: V ASSIGNMENT 1

Computational Expression

Std 12 Lesson-10 Exception Handling in Java ( 1

Exception Handling in Java. An Exception is a compile time / runtime error that breaks off the

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Java Bytecode (binary file)

( &% class MyClass { }

Introduction to Java

Lec 3. Compilers, Debugging, Hello World, and Variables

CHAPTER 7 OBJECTS AND CLASSES

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Following is the general form of a typical decision making structure found in most of the programming languages:

CISC-124. Passing Parameters. A Java method cannot change the value of any of the arguments passed to its parameters.

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

CS260 Intro to Java & Android 03.Java Language Basics

CS 106 Introduction to Computer Science I

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Lecture Set 2: Starting Java

Chapter 2: Using Data

Chapter 02: Using Data

Lecture Set 2: Starting Java

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010

Fall 2017 CISC124 9/16/2017

Java Notes. 10th ICSE. Saravanan Ganesh

Pace University. Fundamental Concepts of CS121 1

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Exception-Handling Overview

CS 251 Intermediate Programming Java Basics

Software and Programming 1

Zheng-Liang Lu Java Programming 45 / 79

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

CHAPTER 7 OBJECTS AND CLASSES

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Object-Oriented Programming. Topic 2: Fundamental Programming Structures in Java

CS 251 Intermediate Programming Methods and Classes

Full file at

CompSci 125 Lecture 02

About this exam review

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

COMP 202 Java in one week

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Java+- Language Reference Manual

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Introduction to Programming (Java) 2/12

Section 2.2 Your First Program in Java: Printing a Line of Text

Section 2.2 Your First Program in Java: Printing a Line of Text

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

Introduction to. Android Saturday. Yanqiao ZHU Google Camp School of Software Engineering, Tongji University. In courtesy of The Java Tutorials

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Welcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

Index COPYRIGHTED MATERIAL

Software and Programming 1

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS Week 5. Jim Williams, PhD

Midterm Exam CS 251, Intermediate Programming March 12, 2014

Transcription:

Introduction to Java https://tinyurl.com/y7bvpa9z Eric Newhall - Laurence Meyers Team 2849 Alumni

Java Object-Oriented Compiled Garbage-Collected WORA - Write Once, Run Anywhere

IDE Integrated Development Environment Edit Build Debug

Hello World class HelloWorld { public static void main (string[] args) { // Print Hello World to the console System.out.println( Hello World! ); Braces mark code blocks Statements end with semicolon Comments are not compiled

Print Write to console or log Print vs Println

Variables Store values Strongly typed

Primitive Types boolean (1-bit) byte (8-bit integer) short (16-bit integer) int (32-bit integer) long (64-bit integer) float (32-bit decimal) double (64-bit decimal) char (16-bit unicode character) String? (immutable object with special properties)

Objects Objects are a combination of state (data), behavior (methods), and identity (unique existence among other objects) Objects contain properties (other variables stored in the object) Objects are created from a class constructor (using keyword new) Objects may contain methods which modify values or perform other functions Objects can be null

Constructors class Person { int id; String name; int age; Person (int i) { id = i; Person (int i, String n, int a) { id = i; name = n; age = a;

Arrays Collection/List of values of the same type Length is defined when created Accessed by index starting at 0

Operators = (assignment) Left side value equal to value of right side += -= *= /= %= + - * / % Standard arithmetic operations ++ -- a++ ++a a = a + 1 a +=1

Relational (returns boolean value) ==!= > >= < <= Logical (return boolean value) &&!

Bitwise & ^ ~ >> << Conditional? : Value = <boolean>? <true> : <false>;

Program Flow if (<booleana>){ //code when booleana is true else if (<booleanb>) { //code when booleana is false and booleanb is true else { //code when booleana and booleanb are false

switch (<variable>) { case <a>: //code to run when <variable> == <a> break; case <b>: //code to run when <variable> == <b> break; default: //code to run when <variable> not equal to any above values break;

Loops while (<booleana>){ //code to loop while booleana is true //check if booleana is true before starting each loop do { //code to loop while booleana is true //check if booleana is true at the end of each loop while (<booleana>)

for (int i = 0; i < 10; i++) { //code to run 10 times for (obj a : collectionofobjs) { //code to run for each obj a in collectionofobjs

Methods Defined by a method header And body public static void Main (string[] args) { //code in Main method

Public/Private/Protected Public - All can access this method Private - Method can only be accessed within the class in which it is defined Protected - Method can only be accessed within the package in which it is defined

Return Types All methods must have a return type which can be one of the following: Primitive - returns a primitive Object - returns an object Constructors fall in this category Void - no return type

Parameters Can have 0 to n Can be of any type Parameters are passed to the method by value Modifications to a parameter object will not persist outside of the method Can overload a method by creating several of the same name with different parameters

public static void main( String[] args ) { Dog adog = new Dog("Max"); // we pass the object to foo foo(adog); // adog variable is still pointing to the "Max" dog when foo(...) returns adog.getname().equals("max"); // true, java passes by value adog.getname().equals("fifi"); // false public static void foo(dog d) { d.getname().equals("max"); // true // change d inside of foo() to point to a new Dog instance "Fifi" d = new Dog("Fifi"); d.getname().equals("fifi"); // true

public static void main( String[] args ) { Dog adog = new Dog("Max"); foo(adog); // when foo(...) returns, the name of the dog has been changed to "Fifi" adog.getname().equals("fifi"); // true public static void foo(dog d) { d.getname().equals("max"); // true // this changes the name of d to be "Fifi" d.setname("fifi");

Static Methods Method called on the class, not the object Use when the method does not depend on a single instance of an object public static double Sin(double a) public static void Main(string[] args) Static methods can only read and write to Static variables

Errors Syntax Prevents the program from compiling Spelling errors Missing closing ) or ; Runtime Invalid operations Null access Array out of bounds Logic Unexpected result, but no compilation errors

Try-Catch(-Finally) Can be used for safety and debugging Some methods require a try catch Can define multiple exception types to catch Can use generic exception type to catch all errors

try{ //code to run that may cause exceptions catch (ExceptionType OtherExceptionType e){ //code to handle exception of type ExceptionType or OtherExceptionType catch (Exception e){ //code for generic exception //all previously unhandled exceptions will be caught here finally { //finally block is optional //code to run no matter what //this will even run if you return in the try/catch