Lec2_Java1 4 Data Types 4 Operators 4 Control Flow Statements 4 Arrays 4 Functions -- Static Methods 4 View Classes as modules Introduction to the Java.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Session 3 Algorithm. Algorithm Algorithm is a set of steps that are performed to solve a problem. The example below describes an algorithm Example Check.
Introduction to Control Statements Presented by: Parminder Singh BCA 5 th Sem. [ Batch] PCTE, Ludhiana 5/12/ Control Statements.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
16-Jun-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
1 2-D Arrays Overview l Why do we need Multi-dimensional array l 2-D array declaration l Accessing elements of a 2-D array l Declaration using Initializer.
Principles of Object-Oriented Software Development The language Java.
Sorting Arrays. Selection Sort  One of the easiest ways to sort the elements of an array is by using the selection sort algorithm.  Assume that the.
Introduction to Programming G51PRG University of Nottingham Revision 2 Essam Eliwa.
16-Aug-15 Java Puzzlers From the book Java Puzzlers by Joshua Bloch and Neal Gafter.
MSc IT Programming Methodology (2). MODULE TEAM Dr Aaron Kans Dr Sin Wee Lee.
Sorting Text Read Shaffer, Chapter 7 Sorting O(N 2 ) sorting algorithms: – Insertion, Selection, Bubble O(N log N) sorting algorithms – HeapSort, MergeSort,
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Control Structures A control structure is simply a pattern for controlling the flow of a program module. The three fundamental control structures of a.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Passing Other Objects Strings are called immutable which means that once a String object stores a value, it never changes –recall when we passed a message.
Java ProgrammingtMyn1 Java Programming Timo Mynttinen Mikkeli University of Applied Sciences.
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.
Problem Solving using the Java Programming Language May 2010 Mok Heng Ngee Day 5: Arrays.
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.
CSC 172 DATA STRUCTURES. SORTING Exercise : write a method that sorts an array. void mysort(int [] a) { }
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Methods (a.k.a. Functions)
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
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.
Repetition Statements while and do while loops
Apr, 2011 Dating with Java Larry Li. Objective Hello world program Setup development environment Data types and variables Operators and Expressions Control.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
Programs That Calculate. Arithmetic Expressions +addition -subtruction *multiplication /division  Order of Operations BEDMAS (brackets, exponentiation,
Java Nuts and Bolts Variables and Data Types Operators Expressions Control Flow Statements Arrays and Strings.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
1 Insertion sort [ ] i=1 j=1 i=2 j=2 insert i=3 at j=1 [ ] i=3 j=1 insert i=4 at j=0 [
Java Part I By Wen Fei, HAO. Program Structure public class ClassName { public static void main(String[] args) { program statements } user defined methods.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
CS001 Introduction to Programming Day 6 Sujana Jyothi
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
Array Sort. Sort Pass 1 Sort Pass 2 Sort Pass 3.
3/21/2016IT 2751 Tow kinds of Lists Array What can be done? What can be easily done? student 1 student 2 student 3 student 4 Linked List student 2 student.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Midterm 2 Review Notes on the CS 5 midterm Take-home exam due by 5:00 pm Sunday evening (11/14) Hand in your solutions under the door of my office, Olin.
Object Oriented Programming Lecture 2: BallWorld.
Introduction to Programming using Java Day 3 and 4 Java Language Basics Review The “For” loop Subroutines The “String” class.
Exercise Java programming
Unit-1 Introduction to Java
Function Call Trace public class Newton {
An Introduction to Java – Part I
Decision statements. - They can use logic to arrive at desired results
An Introduction to Java – Part I, language basics
מבוא למדעי המחשב תרגול 4 – פונקציות.
מבוא למדעי המחשב תרגול 4 – פונקציות.
Recursive GCD Demo public class Euclid {
class PrintOnetoTen { public static void main(String args[]) {
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Control Structure.
Introduction to java Part I By Shenglan Zhang.
PROGRAMMING ASSIGNMENT I
Presentation transcript:

Lec2_Java1 4 Data Types 4 Operators 4 Control Flow Statements 4 Arrays 4 Functions -- Static Methods 4 View Classes as modules Introduction to the Java Language

Lec2_Java2 Exampe1: Hello.java class Hello { public static void main(String[] args){ System.out.println("Hello World!"); }

Lec2_Java3 Data Types 4 byte,short,int,long 4 float,double 4 char 4 boolean 4 reference array object

Lec2_Java4 Operators 4 Arithmetic operators +, -, *, /, %, ++, -- 4 Relational operators >, >=, <, <=, ==, != 4 Conditional operators &&, ||, ! 4 Bitwise operators >>, >>, &, |, ^, ~

Lec2_Java5 Control Flow Statements 4 decision making –if-else, switch-case 4 loop –for, while, do-while 4 exception –try-catch-finally, throw 4 miscellaneous –break, continue, label:, return

Lec2_Java6 Type[] a = new Type[n] a[0]a[1]a[n-1] Arrays 4 Dynamic 4 Array initialization 4 a.length Type[] a;... a = new Type[expn] a = new Type[]{e1,e2,...,en}; A = {e1,e2,…,en}

Lec2_Java7 Example 2: Max.java class Max { public static void main(String[] args){ int[] a = new int[]{5,6,1,2,7,9,0,10}; int max; max = a[0]; for (int i=1; i<a.length; i++){ if (a[i]>max) max = a[i]; } System.out.println(" max="+max); }

Lec2_Java8 Example 3: PrintArray class PrintArray { public static void main(String[] args){ int[][] a = new int[][]{{1,2,3}, {4,5,6}, {7,8,9}}; for (int i=0; i<a.length; i++){ for (int j=0; j< a[0].length; j++){ System.out.print(a[i][j]+" "); } System.out.println(); }

Lec2_Java9 Functions -- Static Methods class Max { public static void main(String[] args){ int[] a = new int[]{5,6,1,2,7,9,0,10}; System.out.println(" max="+max(a)); } static int max(int[] a){ int max = a[0]; for (int i=1; i<a.length; i++){ if (a[i]>max) max = a[i]; } return max; }

Lec2_Java10 Functions -- Static Methods class PrintArray { public static void main(String[] args){ int[][] a = new int[][]{{1,2,3}, {4,5,6}, {7,8,9}}; printArray(a); } static void printArray(int[][] a){ for (int i=0; i<a.length; i++){ for (int j=0; j< a[0].length; j++){ System.out.print(a[i][j]+" "); } System.out.println(); }

Lec2_Java11 View Classes as Modules class Sort { public static void selectionSort(int a[]){ int tmp; for (int i=0; i<a.length; i++) for (int j=i+1; j<a.length; j++) if (a[i]>a[j]){ tmp = a[i]; a[i] = a[j]; a[j] = tmp; }

Lec2_Java12 View Classes as Modules public class TestSort { public static void main(String[] args){ int[] a = new int[]{5,6,1,2,7,9,0,10}; Sort.selectionSort(a); for (int i=0; i<a.length; i++){ System.out.print(a[i]+" "); }