DOC PREVIEW
SJSU CS 146 - Java Array, Game of Life

This preview shows page 1-2-3-20-21-22-41-42-43 out of 43 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 43 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Java Array, Game of LifePowerPoint PresentationSlide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13ArraysSlide 15Slide 16SOME VARIATIONS IN DECLARING ARRAYSSlide 18Slide 19Slide 20Slide 21Slide 22Slide 23Limits of ArraySlide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33MULTI DIMENSIONED ARRAYSSlide 35Slide 36Slide 37Slide 38Slide 39Slide 40Slide 41Slide 42Slide 43Java Array, Game of LifeProf. Sin-Min LeeDepartment of Computer ScienceSan Jose State UniversityOverview - 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 programsHistory 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 1995Highlights 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-threadedJava - 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 conversionsJava - 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 interpretingJava - 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 cyclesArrays•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];orint [] 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] = { 134.362, 1913.248 };• double radians[1000];#include <stdio.h> main() { int x; static int values[] = { 1,2,3,4,5,6,7,8,9 }; static char word[] = { 'H','e','l','l','o' }; for( x = 0; x < 9; ++x ) printf(" Values [%d] is %d\n", x, values[x]); } Samp le Program Output Values[0] is 1 Values[1] is 2 .... Values[8] is 9•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 <stdio.h> 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 ]; •


View Full Document

SJSU CS 146 - Java Array, Game of Life

Download Java Array, Game of Life
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Java Array, Game of Life and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Java Array, Game of Life 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?