AP Refresher Module Introduction to Java Advanced Programming. All slides copyright: Chetan Arora.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

A Programmer's Introduction to Java - from a S/370 user (c) IDMS/SQL News
1 pritisajja.info Unlocking the World of Java Programming….. Priti Srinivas Sajja February, 2014 Visit pritisajja.info for detail Future Technology for.
Date: Subject:Distributed Data Processing Name:Maria Br ü ckner.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
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.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
Introduction to Java.
Introduction to Java Programming Language Junji Zhi University of Toronto 1.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
A Short Introduction to JAVA
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
DAT602 Database Application Development Lecture 5 JAVA Review.
Introduction to Java CSIS 3701: Advanced Object Oriented Programming.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
May 9, 2002Serguei A. Mokhov, 1 Kickstart Intro to Java Part I COMP346/ Operating Systems Revision 1.6 February 9, 2004.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
CS591x A very brief introduction to Java. Java Developed by Sun Microsystems was intended a language for embedded applications became a general purpose.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
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.
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
1 Introduction to Java. 2 What is Java? A programming language. A platform –A virtual machine (JVM) definition. –Runtime environments in diverse hardware.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
By Mr. Muhammad Pervez Akhtar
introductory lecture on java programming
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
SOFTWARE DEVELOPMENT FOUNDATIONS, 1/12/12 J. Yates Monteith, Clemson University.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Features of JAVA PLATFORM INDEPENDENT LANGUAGE JAVA RUNTIME ENVIRONMENT (JRE) JAVA VIRTUAL MACHINE (JVM) JAVA APP BYTE CODE JAVA RUNTIME ENVIRONMENT.
Object Oriented Programming Lecture 2: BallWorld.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
CS202 Java Object Oriented Programming Review of Language Basics Chengyu Sun University of California, Santa Barbara.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Object Oriented Programming in
Information and Computer Sciences University of Hawaii, Manoa
Intro to ETEC Java.
Java Basics Introduction to Java.
Chapter No. : 1 Introduction to Java.
Java Course Review.
Internet and Java Foundations, Programming and Practice
Programming Language Concepts (CIS 635)
Getting Started ARCS Lab..
Introduction to Programming in Java
CET 3640 – Lecture 2 Java Syntax Chapters 2, 4, 5
Introduction to Java.
Units with – James tedder
(Computer fundamental Lab)
Chap 1. Getting Started Objectives
Presentation transcript:

AP Refresher Module Introduction to Java Advanced Programming. All slides copyright: Chetan Arora

11 Buzzwords for Java Simple Object Oriented Network Savvy Robust Secure Architecture Neutral Portable Interpreted High performance Multithreaded Dynamic Advanced Programming. All slides copyright: Chetan Arora

Java: Simple Syntax is cleaned up version of C++ No need of header files No pointer arithmetic/syntax No operator overloading … Advanced Programming. All slides copyright: Chetan Arora

Java: Object Oriented Object Oriented Design: Focus on Data (objects) and interfaces. Object oriented features comparable to C++ More simplified because of different handling of multiple inheritance using ‘interfaces’. Java: Network Savvy Much easier network programming compared to C++ Simpler remote method invocation mechanism. Advanced Programming. All slides copyright: Chetan Arora

Java: Robust No pointer model Improved compiler Java: Secure Stack overrun, Memory corruption and Reading/Writing files without permission are much more difficult in Java. Advanced Programming. All slides copyright: Chetan Arora

Java: Architecture Neutral and Portable Java Virtual Machine Java: High Performance Just in time compilation. Advanced Programming. All slides copyright: Chetan Arora

Java: Multithreading C++: Different multi-threading models exist for difference operating systems, Java: Consistent API. Different implementations for JVMs Java: Dynamic Support for libraries etc. Possible to find runtime type information. Advanced Programming. All slides copyright: Chetan Arora

Java Programming Environment JDK JRE.java.class.jar We will use JDK 1.8.0_45 in this course Java Code Byte Code Windows JVM Linux JVM Mac JVM Java Compiler (JDK) Java Loader (JRE) WORA: Write Once Run Everywhere Advanced Programming. All slides copyright: Chetan Arora

Java Programming Environment IDE: Eclipse, Netbeans etc. In this course, we will use Eclipse Version: Mars Release: Build id: For developing/compiling/running from command line use ‘javac’ and ‘java’ commands Advanced Programming. All slides copyright: Chetan Arora

Your First Java Program: Hello World public class MainClass { public static void main(String[] args) { //comment 1 /* * more comment formats */ System.out.println("Hello World"); } Advanced Programming. All slides copyright: Chetan Arora Note: 1.Naming Convention a.Class b.File 2.Braces 3.Comments 4.Console output Ignore for now: 1.Class 2.Access Modifier

Java Variable Types Java is a strongly typed language Every variable must have a type. Restrictions on types intermixing: string can not added to a int or double. Java basic types: Platform independent Integers: int (4 bytes), short(2 bytes), long (8 bytes), byte (1 bytes) Reals: float (4), double (8). Default is double precision. Use ‘f’ for floats: 1.234f Boolean: boolean (true/false) Character: char (Unicode: UTF 16) Advanced Programming. All slides copyright: Chetan Arora

Java Operators Basic: +, -, *, / Incremental: ++, -- Difference between b = a++ and b = ++a Combined: +=, -=, *=, /= Remainder (Mod): % Relational:, >=, <=, ==, != Logical: ||, && Bitwise: |, &, ^ (XOR) Advanced Programming. All slides copyright: Chetan Arora

Sample Program public class MainClass { public static void main(String[] args) { int a = 10; a++; float f = 20.0f; ++f; System.out.printf("int: %d, float: %.3f",a, f); } Advanced Programming. All slides copyright: Chetan Arora

Type Conversion Implicit conversion Conversion of value from one type to another without any directive from the programmer. Example: char to int implicit conversion char c = 'a'; int k = c; long x = c; Explicit conversion Casting double d = 5.6; int k = (int)d; Advanced Programming. All slides copyright: Chetan Arora

Operator Precedence Advanced Programming. All slides copyright: Chetan Arora OperatorsPrecedence !, ++,-- (unary operators)First (Highest) *, /, %Second +, -Third =, >Fourth ==, !=Fifth &&Sixth ||Seventh = (asignment operator)Last(lowest)

Scope Block Scope Java statements surrounded by a pair of braces Define the scope of your variables Advanced Programming. All slides copyright: Chetan Arora public static void main(String[] args) { int n;... { int k;... } // k is only defined up to here } public static void main(String[] args) { int n;... { int k; int n; // ERROR--can't redefine n in inner block... }

Control Statements: If-else conditions if (yourSales >= 2 * target) { performance = "Excellent"; } else if (yourSales >= target) { performance = "Satisfactory"; } else { System.out.println("You're fired"); } Advanced Programming. All slides copyright: Chetan Arora

Control Statements: Switch case condition Advanced Programming. All slides copyright: Chetan Arora public class Test { public static void main(String args[]){ char grade = 'C'; switch(grade) { case 'A' :System.out.println("Excellent!"); break; case 'B' : case 'C' :System.out.println("Well done"); break; case 'D' :System.out.println("You passed"); case 'F' :System.out.println("Better try again"); break; default :System.out.println("Invalid grade"); } } }

Control Statements: while, do-while loops Advanced Programming. All slides copyright: Chetan Arora while (balance < goal) { balance += payment; double interest=balance*interestRate/100; balance+= interest; years++; } System.out.println(years + " years."); do { balance += payment; double interest=balance*interestRate/100; balance += interest; year++; // print current balance... // ask if ready to retire and get input... } while (input.equals("N"));

Control Statements: for loop for (int i = 10; i > 0; i--) { System.out.println("Counting down... " + i); } System.out.println("Time up!"); int i; for (i = 10; i > 0; i--) { System.out.println("Counting down... " + i); } System.out.println("Time up!"); Scope of i ?

Strings in Java operations on strings Formatting (printf) Advanced Programming. All slides copyright: Chetan Arora public class StringDemo { public static void main(String args[]) { String palindrome = "Dot saw I was Tod"; int len = palindrome.length(); System.out.println( "String Length is : " + len ); } }

Arrays 1D, 2D array(array of arrays).length Array class Forloop on arrays Advanced Programming. All slides copyright: Chetan Arora public class TestArray { public static void main(String[] args) { double[] myList = {1.9, 2.9, 3.4, 3.5}; // Print all the array elements for (double element: myList) { System.out.println(element); } } }

Input output from/to console Scanner Print, println Advanced Programming. All slides copyright: Chetan Arora public class InputTest { public static void main(String[] args) { Scanner in = new Scanner(System.in); // get first input System.out.print("What is your name? "); String name = in.nextLine(); // get second input System.out.print("How old are you? "); int age = in.nextInt(); // display output on console System.out.println("Hello, " + name + ". Next year, you'll be " + (age + 1)); }

Functions in Java public class MainClass { public MainClass() { } public int Mult(int a, int b) { return a*b; } public static void main(String[] args) { MainClass m = new MainClass(); System.out.println("Function output = " + m.Mult(10, 20)); } Advanced Programming. All slides copyright: Chetan Arora Ignore access modifier for now Parameter passing return