Java Array, Game of Life Prof. Sin-Min Lee Department of Computer Science San Jose State University.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
Lab#1 (14/3/1431h) Introduction To java programming cs425
The Java Language. Topics of this Course  Introduction to Java  The Java Language  Object Oriented Programming in Java  Exceptions Handling  Threads.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Java: History and Introduction (Lecture # 1). History… Java – Based on C and C++ – Developed in 1991 for intelligent consumer electronic devices – Green.
Introduction to Java Kiyeol Ryu Java Programming Language.
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.
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.
01 Introduction to Java Technology. 2 Contents History of Java What is Java? Java Platforms Java Virtual Machine (JVM) Java Development Kit (JDK) Benefits.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
JAVA v.s. C++ Programming Language Comparison By LI LU SAMMY CHU By LI LU SAMMY CHU.
CSC 142 A 1 CSC 142 Introduction to Java [Reading: chapter 0]
Introduction to Java CSIS 3701: Advanced Object Oriented Programming.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Programming Languages and Paradigms Object-Oriented Programming.
CSCI 224 Introduction to Java Programming. Course Objectives  Learn the Java programming language: Syntax, Idioms Patterns, Styles  Become comfortable.
Java Workshop for Teachers May 6, 2005 A Brief Look at the Java Programming Language.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Java Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
Why Java? A brief introduction to Java and its features Prepared by Mithat Konar.
Introduction to Java CSIS 3701: Advanced Object Oriented Programming.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
University of Houston-Clear Lake Proprietary© 1997 Evolution of Programming Languages Basic cycle of improvement –Experience software difficulties –Theory.
Introduction and Features of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++
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.
What Is Java? According to Sun in a white paper: Java: A simple, object-oriented, network-savvy, interpreted, robust, secure, architecture-neutral, portable,
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
Chapter 2: A Brief History Object- Oriented Programming Presentation slides for Object-Oriented Programming by Yahya Garout KFUPM Information & Computer.
Computer Programming 2 Why do we study Java….. Java is Simple It has none of the following: operator overloading, header files, pre- processor, pointer.
We will talking about story of JAVA language. By Kristsada Songpartom.
J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition D.S. Malik D.S. Malik.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Java L1 Array Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Object Oriented Software Development 4. C# data types, objects and references.
JAVA INTRODUCTION. What is Java? 1. Java is a Pure Object – Oriented language 2. Java is developing by existing languages like C and C++. How Java Differs.
Introduction Mehdi Einali Advanced Programming in Java 1.
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
Duke CPS From C++ to Java l Java history: Oak, toaster-ovens, internet language, panacea l What it is ä O-O language, not a hybrid (cf. C++)
Java – in context Main Features From Sun Microsystems ‘White Paper’
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Overview of Programming.
Introduction to JAVA Programming
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
 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.
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
Applications Active Web Documents Active Web Documents.
Object Oriented Programming in
Done By: Ashlee Lizarraga Ricky Usher Jacinto Roches Eli Gomez
Chapter 1 Introduction to Computers, Programs, and Java
Internet and Java Foundations, Programming and Practice
Introduction Enosis Learning.
Introduction Enosis Learning.
Advanced Programming Fall 2017.
Units with – James tedder
Units with – James tedder
From C++ to Java Java history: Oak, toaster-ovens, internet language, panacea What it is O-O language, not a hybrid (cf. C++) compiled to byte-code, executed.
(Computer fundamental Lab)
CSC 142 Introduction to Java [Reading: chapters 1 & 2]
Java Evolution Java History. Java Features.
Outcome of the Lecture Upon completion of this lecture you will be able to understand Fundamentals and Characteristics of Java Language Basic Terminology.
Presentation transcript:

Java Array, Game of Life Prof. Sin-Min Lee Department of Computer Science San Jose State University

Overview - What is Java New, general purpose object-oriented programming language from Sun Microsystems Allows users to interact with Web pages beyond simply: reading them filling out a form answering questions Allows interaction with program running as an extension to your Web browser May be used to augment web page with both a new protocol and the program which implements that protocol May be used for writing both network-oriented and local application programs

History of the development of Java Started out in 1991 as Project Green focussed on O/S software for consumer electronic devices James Gosling recognized inadequacy of C++ and initiated development of Oak language Green went through several false starts before dissolving Small group decided to adapt Oak (later named Java) to a web technology -- result was a new web browser, WebRunner (later named HotJava), operational in 1994 Paper on Oak byte codes presented by Gosling at Programming Language Design and Implementation (PLDI) conference in 1995

Highlights of the Java Language It's Simple It's Object Oriented It's Safe It's Secure It's Portable It's Fast (potentially) It's Multi-threaded

Java - It's Simple Java has only the necessary functionality needed to implement its feature set. It has omitted the features of C and C++ which have been considered to be "unsafe" pointer "forging" operator overloading static objects Memory is managed automatically, relieving the programmer from being responsible for freeing unused space There is no Java preprocessor - the program that you see is the same program that the Java compiler sees.

Java - It's Object Oriented Syntax and semantics inherited from C and C++, but many of its object management features come from Objective C (e.g. interfaces). Unlike C and C++, there are no stand-alone functions, but only methods associated with a class. Everything (except for the built-in primitive types) is either a class, a method, or an object. Extensive class library comes with Java, to interface with: host operating system

window manager network Java Applications and Applets may provide their own class library support May not replace "system" classes (for security purposes)

Java - It's Safe Four different levels of safety checks and enforcement to prevent the introduction of viruses protect against deleting or modifying files protect against corrupting the operator of user's computer More strict type model than either C or C++ Arrays are first class objects always range checked no visible conversion to pointer plus offset No implicit declarations in Java Only a minimum number of implicit conversions

Java - It's Fast (potentially) Currently, all mainstream implementations of Java are running Java programs interpretively port of the interpreter developed by Sun alternative implementation built from the Java Language and Virtual Machine specifications Java byte code is similar to functionality to P-code or U-code Several experimental projects translating Java byte codes to either C or native machine code Slower than C or C++, due to mandatory run-time checks For many small Java programs, no advantage of compiling over interpreting

Java - It's Multi-threaded Threads of control are an integral part of the Java language, not a run-time library "add-on" Java offers preemptive multi-threading, implemented via the Thread class Especially important when developing applets provide the proper dynamics between the Java applet and the host browser prevent applet from usurping most of the compute cycles

Arrays One of the most basic data structures, is an array. An array is just a number of items, of same type, stored in linear order, one after another. Arrays have a set limit to their size, they can’t grow beyond that limit. An array in Java is noted as: int array[] = new int [10]; or int [] array = new int [10]; This would create an array of integers of size 10. Any element in that array can be accessed by: int value = array[5]; This would put the value of the 5’th (counting from 0) element into the variable ‘value’.

Arrays are very often manipulated in loops. For example, if you have an array named "myNumbers" and you'd like to print all of them, one per line, you'll do something like this: for(int i = 0;i<myNumbers.length;i++) System.out.println(myNumbers[i]); Arrays are not just restricted to being int type, they can be of any type, even of your own created class. Arrays are nice structures, which are generally faster than other data structures, but they do have limits.

SOME VARIATIONS IN DECLARING ARRAYS int numbers[10]; static int numbers[10] = { 34, 27, 16 }; static int numbers[] = { 2, -3, 45, 79, -14, 5, 9, 28, -1, 0 }; static char text[] = "Welcome to New Zealand."; static float radix[12] = { , }; double radians[1000];

The following program shows how to initialise all the elements of an integer based array to the value 10, using a for loop to cycle through each element in turn. #include main() { int count; int values[100]; for( count = 0; count < 100; count++ ) values[count] = 10; }

5.Arrays and pointers are very closely connected. The name of the array is also a pointer to the beginning of the memory associated with the array (which is why (1) arrays are passed as reference parameters and (2) you can pass an array using only its name.)

Arrays int vec [ 9 ]; float mat [ 9] [ 20 ]; vec [ k ] = vec [ k ] * 2; mat [ k ] [ j ] := mat [ k ] [ j ] * vec [ k ]; Often when solving problems on the computer you would like to represent and manipulate a set of data values having similar characteristics Arrays provide this capability

Limits of Array One of the major limits, is that they're fixed in size, and can't grow or shrink to accomodate the data. The Vector class in java, uses an array, and does make it seem that the array is growing or shrinking. In reality, Vector class checks to see if more space is needed, if it is, then it creates a new array, copies the old array to the new array, and makes the new array, it's primary array, thus, giving the impression that the array "grew" to fit the data. This approach can get rather slow, if a lot of growing & shrinking is needed.

Generating a Random Number The following code snippet demonstrates how to generate a pseudo- random integer number that falls within a specific range. Random random, random1; int nbr; random = new Random(); nbr = someMinValue + Math.abs(random.nextInt()) % (someMaxValue - someMinValue); random1 = new Random(nbr); // create another randon number generator using // a specific seed value There are two constructors for Random(). When invoked with no argument, then a new pseudo-random number generator is created using the current time of day as a seed; otherwise, a pseudo-random number generator can be created using a specific seed.

MULTI DIMENSIONED ARRAYS Multi-dimensioned arrays have two or more index values which specify the element in the array. multi[i][j] In the above example, the first index value i specifies a row index, whilst j specifies a column index.