Essential Java for Scientists and Engineers Essential Java for Scientists and Engineers

Total Page:16

File Type:pdf, Size:1020Kb

Essential Java for Scientists and Engineers Essential Java for Scientists and Engineers Essential Java for Scientists and Engineers Essential Java for Scientists and Engineers Brian D. Hahn Department of Mathematics & Applied Mathematics University of Cape Town Rondebosch South Africa Katherine M. Malan Department of Computer Science University of Cape Town Rondebosch South Africa OXFORD AMSTERDAM BOSTON LONDON NEW YORK PARIS SAN DIEGO SAN FRANCISCO SINGAPORE SYDNEY TOKYO Butterworth-Heinemann An imprint of Elsevier Science Linacre House, Jordan Hill, Oxford OX2 8DP 225 Wildwood Avenue, Woburn, MA 01801-2041 First published 2002 Copyright c 2002 Brian D. Hahn and Katherine M. Malan. All rights reserved The right of Brian D. Hahn and Katherine M. Malan to be identified as the authors of this work has been asserted in accordance with the Copyright, Designs and Patents Act 1988 All rights reserved. No part of this publication may be reproduced in any material form (including photocopying or storing in any medium by electronic means and whether or not transiently or incidentally to some other use of this publication) without the written permission of the copyright holder except in accordance with the provisions of the Copyright, Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licensing Agency Ltd, 90 Tottenham Court Road, London, England W1T 4LP. Applications for the copyright holder’s written permission to reproduce any part of this publication should be addressed to the publishers British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library Library of Congress Cataloguing in Publication Data A catalogue record for this book is available from the Library of Congress ISBN 0 7506 5422 8 For information on all Butterworth-Heinemann publications visit our website at www.bh.com Typeset by Laserwords Private Limited, Chennai, India. Printed and bound in Martins the Printers of Berwick Upon Tweed Contents Preface xiii Acknowledgements xvi Part I Essentials 1 1 Getting going 3 1.1 Introduction to programming 3 Java as a programming language 3 1.2 Setting up your computer for programming in Java 4 Installing Java 2 4 Jikes as an alternative compiler 5 Installing the essential package 6 1.3 Writing your first Java program 6 What happens when a program is compiled? 7 Understanding FirstProgram 7 Commands for printing to the screen 8 1.4 Input and output 9 How input from the keyboard works 10 Reading in numbers from the keyboard 10 Input without the Keyboard class (optional) 10 Example: calculating compound interest 11 1.5 Comments 11 1.6 Using objects 12 Using the Turtle class 12 Help on the essential package 13 Using the Graph class 14 1.7 Java on the WWW (optional) 15 2 Java programming basics 20 2.1 Compound interest again 20 2.2 Primitive data types 23 Bits and bytes 23 v vi Contents Numeric constants 24 double is default 24 2.3 Names 25 Identifiers 25 Case sensitivity 25 Variables 25 2.4 Vertical motion under gravity 26 2.5 Operators, expressions and assignments 27 Arithmetic operators 27 Precedence 27 Increment and decrement operators 28 Assignments and assignment operators 29 Cast operators 30 2.6 Repeating with for 30 Turtle spirals 30 Growing an investment 33 The for statement 34 Alternative ways of counting with for 35 Square rooting with Newton 35 Factorials! 36 Limit of a sequence 37 Reading data from a text file 37 2.7 Deciding with if 38 The if-else statement 40 The if-else-if statement 40 The if-else-if ladder 40 for and if: counting passes 41 Rolling dice 41 Logical operators 42 Boolean variables 43 Nested ifs 44 The switch statement 44 2.8 Characters 45 Escape sequences 45 2.9 Math methods 46 2.10 Programming style 46 3 Solving a problem in Java 55 3.1 Introduction 55 3.2 The class provider, class user and end user 56 3.3 What are objects and classes? 56 Looking at the Turtle class in more depth 57 3.4 Writing and using a simple class 58 3.5 How memory works 59 What is memory? 59 How objects and primitives are stored in memory 60 The null keyword 60 3.6 The String class 62 Equality testing of strings 63 3.7 Understanding methods 63 Method arguments 63 Return types 64 Signature of a method 64 Contents vii Constructors 64 More on the import statement 65 3.8 Example: simulating a rabbit colony 66 Data members of RabbitColony 66 Methods of RabbitColony 66 Using the RabbitColony class 67 Defining the grow() method 68 Defining the grow(int n) method 68 Defining the getNumRabbits() method 68 Tracing UseRabbitColony 69 3.9 Access modifiers 70 The public and private keywords 70 Other access modifiers 70 3.10 Example: simulating the growth of trees 71 Data members for the Tree class 71 Methods of the Tree class 71 A main method to test the class 72 Writing the methods 72 When to define a default constructor 73 The this keyword 74 3.11 Scope 74 3.12 More on object handles 75 Passing objects to methods 75 Object handles and assignment 78 3.13 The static keyword 80 Understanding static 80 Constants 81 Static methods 81 The main method revisited 83 3.14 Naming conventions 83 3.15 Using the Java API 84 3.16 Making your own package (optional) 84 4 More on loops 89 4.1 Determinate repetition with for 89 Binomial coefficient 89 for loops with non-unit increments 90 Plotting a projectile trajectory with Essential Grapher 91 Update processes 93 The nested for loop 96 4.2 Indeterminate repetition with while 98 Rolling a dice for a six 98 The while statement 99 A guessing game 100 Prime numbers 101 Projectile trajectory 102 Reading an unknown amount of data 103 The do-while statement 104 while versus do-while 105 5 Debugging 114 5.1 Compilation errors 114 5.2 Run-time errors 117 viii Contents 5.3 Errors in logic 119 Debugging logical errors 119 5.4 Rounding errors 119 6 Arrays and matrices 123 6.1 Introduction 123 Why bother with arrays? 123 6.2 The basics of arrays 125 Declaring and initializing an array 125 Indexing elements of an array 125 Looping through an array 126 6.3 Passing arrays to methods 128 6.4 Frequency distributions: a simple bar chart 128 6.5 Multi-dimensional arrays 129 A concrete example 130 Matrix multiplication 131 6.6 Arrays of objects 133 6.7 Sorting an array 134 Part II More advanced topics 141 7 Inheritance 143 7.1 Introduction 143 What is inheritance? 143 Generalization and specialization 144 7.2 Inheritance in Java 145 Reusing code through specialization 146 Overriding methods 148 The protected keyword 150 7.3 Constructors and inheritance 150 Default constructors 151 The super keyword 151 Parameterized constructors 152 7.4 The Object class 152 The toString method 153 7.5 Abstract classes and interfaces 154 Why bother with abstract classes? 155 Interfaces 155 8 Graphical user interfaces (GUIs) 160 8.1 Introduction 160 GUIs in Java 160 Understanding events 161 8.2 Building a Swing application 161 A first version 161 Shutting down the application properly 161 Components and containers 162 Adding a button to the application 162 Organizing the code in a better way 163 Adding a label 164 Getting the button to do something 165 Listeners as nested classes 165 Contents ix 8.3 Arranging components 167 The FlowLayout manager 167 The BorderLayout manager 168 Adding borders to components 169 8.4 A colour chooser application 170 Planning the GUI 170 Defining the colour 170 Adding the components 170 Adding the sliders and labels 172 Programming the behaviour 173 8.5 Painting 174 PacMan and the Blocks 176 8.6 Drawing mathematical graphs 185 8.7 Fractals 189 The Julia set 189 The Mandelbrot set 192 9 Input/output 197 9.1 Introduction 197 9.2 Input through command line parameters 198 9.3 Input from the keyboard without the essential package 198 9.4 Streams 199 Output redirection 199 The System class 200 The InputStream and InputStreamReader classes 200 The BufferedReader class 201 Reading in numbers 201 9.5 File input/output 201 Types of files 202 File handling 202 Reading in from a text file 203 Writing to files 203 9.6 Manipulating data 204 Tokenizing strings 204 9.7 Streams and the Internet 205 10 Exceptions 209 10.1 Introduction 209 10.2 Exceptions in Java 209 Exception classes 210 10.3 Throwing exceptions 211 When to specify the throws clause in a method header 213 10.4 Handling exceptions 214 Example: finding averages 214 Catching an exception 215 What happens when an exception is thrown 217 10.5 Exceptions and file input 217 Groups of exceptions 218 Forcing the exceptions 218 Catching FileNotFoundException and EOFException 219 Looping while file not found 220 The finally statement 221 x Contents Part III Some applications 225 11 Simulation 227 11.1 Random number generation 227 The Math.random method 227 Seeding the random number generator 228 The Random class 228 Normal (Gaussian) random numbers 229 11.2 Spinning coins 229 11.3 Rolling dice 230 11.4 Bacteria division 230 11.5 Radioactive decay 230 Estimation of half-life 232 11.6 A random walk 233 11.7 Traffic flow 236 12 Modelling with matrices 242 12.1 Using the Matrix class 242 The identity matrix 244 12.2 Networks 244 A spy ring 244 The reachability matrix 246 12.3 Leslie matrices: population growth 248 12.4 Markov processes 252 A random walk 253 12.5 Linear equations 256 Limitations of the invert method of Matrix 258 The residual 258 Ill-conditioned systems 258 13 Introduction to numerical methods 262 13.1 Equations 262 Newton’s method 262 A Function class 263 Defining a new exception 266 Complex roots 267 The Bisection method 269 13.2 Numerical differentiation 270 13.3 Integration 272 The Trapezoidal rule 272 Simpson’s rule 274 13.4 First-order differential equations 274 Euler’s
Recommended publications
  • A Service-Oriented Framework for Model-Driven Development of Software Architectures
    Universidad Rey Juan Carlos Escuela Técnica Superior de Ingeniería Informática Departamento de Lenguajes y Sistemas Informáticos II ArchiMeDeS: A Service-Oriented Framework for Model-Driven Development of Software Architectures Doctoral Thesis by Marcos López Sanz Thesis Supervisor: Dr. Esperanza Marcos Martínez Thesis Co-Advisor: Dr. Carlos E. Cuesta Quintero February 2011 La Dra. Dª. Esperanza Marcos Martínez, Catedrática de Universidad, y el Dr. D. Carlos E. Cuesta Quintero, Profesor Titular Interino, ambos del Departamento de Lenguajes y Sistemas Informáticos II de la Universidad Rey Juan Carlos de Madrid, directora y co-director, respectivamente, de la Tesis Doctoral: ―ArchiMeDeS: A SERVICE-ORIENTED FRAMEWORK FOR MODEL-DRIVEN DEVELOPMENT OF SOFTWARE ARCHITECTURES‖ realizada por el doctorando D. Marcos López Sanz, HACEN CONSTAR QUE: Esta tesis doctoral reúne los requisitos para su defensa y aprobación. En Madrid, a 25 de febrero de 2011 Fdo.: Esperanza Marcos Martínez Fdo.: Carlos E. Cuesta Quintero Entia non sunt multiplicanda praeter necessitatem 1 (William of Ockham, c. 1288 – c. 1348) Quod est inferius, est sicut quod est superius, et quod est superius est sicut quod est inferius, ad perpetranda miracula rei unius 2 (Tabula Smaragdina, Hermes Trismegistus) 1 Entities must not be multiplied beyond necessity. 2 That which is below is as that which is above, and that which is above is as that which is below, to perform the miracles of the one thing. RESUMEN I RESUMEN La dependencia de la industria en las tecnologías de la información se ha acentuado en los últimos años conforme lo han hecho sus necesidades de buscar nuevas fórmulas de negocio.
    [Show full text]
  • An Introduction to the SAS System
    An Introduction to the SAS System Dileep K. Panda Directorate of Water Management Bhubaneswar-751023 [email protected] Introduction The SAS – Statistical Analysis System (erstwhile expansion of SAS) - is the one of the most widely used Statistical Software package by the academic circles and Industry. The SAS software was developed in late 1960s at North Carolina State University and in 1976 SAS Institute was formed. The SAS system is a collection of products, available from the SAS Institute in North Carolina. SAS software is a combination of a statistical package, a data – base management system, and a high level programming language. The SAS is an integrated system of software solutions that performs the following tasks: Data entry, retrieval, and management Report writing and graphics design Statistical and mathematical analysis Business forecasting and decision support Operations research and project management Applications development At the core of the SAS System is the Base SAS software. The Base SAS software includes a fourth-generation programming language and ready-to-use programs called procedures. These integrated procedures handle data manipulation, information storage and retrieval, statistical analysis, and report writing. Additional components offer capabilities for data entry, retrieval, and management; report writing and graphics; statistical and mathematical analysis; business planning, forecasting, and decision support; operations research and project management; quality improvement; and applications development. In general, the Base SAS software has the following capabilities A data management facility A programming language Data analysis and reporting utilities Learning to use Base SAS enables you to work with these features of SAS. It also prepares you to learn other SAS products, because all SAS products follow the same basic rules.
    [Show full text]
  • Information Technology Laboratory Technical Accomplishments
    CONTENTS Director’s Foreword 1 ITL at a Glance 4 ITL Research Blueprint 6 Accomplishments of our Research Program 7 Foundation Research Areas 8 Selected Cross-Cutting Themes 26 Industry and International Interactions 36 Publications 44 NISTIR 7169 Conferences 47 February 2005 Staff Recognition 50 U.S. DEPARTMENT OF COMMERCE Carlos M. Gutierrez, Secretary Technology Administration Phillip J. Bond Under Secretary of Commerce for Technology National Institute of Standards and Technology Hratch G. Semerjian, Jr., Acting Director About ITL For more information about ITL, contact: Information Technology Laboratory National Institute of Standards and Technology 100 Bureau Drive, Stop 8900 Gaithersburg, MD 20899-8900 Telephone: (301) 975-2900 Facsimile: (301) 840-1357 E-mail: [email protected] Website: http://www.itl.nist.gov INFORMATION TECHNOLOGY LABORATORY D IRECTOR’S F OREWORD n today’s complex technology-driven world, the Information Technology Laboratory (ITL) at the National Institute of Standards and Technology has the broad mission of supporting U.S. industry, government, and Iacademia with measurements and standards that enable new computational methods for scientific inquiry, assure IT innovations for maintaining global leadership, and re-engineer complex societal systems and processes through insertion of advanced information technology. Through its efforts, ITL seeks to enhance productivity and public safety, facilitate trade, and improve the Dr. Shashi Phoha, quality of life. ITL achieves these goals in areas of Director, Information national priority by drawing on its core capabilities in Technology Laboratory cyber security, software quality assurance, advanced networking, information access, mathematical and computational sciences, and statistical engineering. utilizing existing and emerging IT to meet national Information technology is the acknowledged engine for priorities that reflect the country’s broad based social, national and regional economic growth.
    [Show full text]
  • Fortran Programming Guide
    Sun Studio 12: Fortran Programming Guide Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. Part No: 819–5262 Copyright 2007 Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A. All rights reserved. Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is described in this document. In particular, and without limitation, these intellectual property rights may include one or more U.S. patents or pending patent applications in the U.S. and in other countries. U.S. Government Rights – Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supplements. This distribution may include materials developed by third parties. Parts of the product may be derived from Berkeley BSD systems, licensed from the University of California. UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open Company, Ltd. Sun, Sun Microsystems, the Sun logo, the Solaris logo, the Java Coffee Cup logo, docs.sun.com, Java, and Solaris are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc. The OPEN LOOK and SunTM Graphical User Interface was developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computer industry.
    [Show full text]
  • Java Tutorial for Beginners - a Cheat Sheet
    Java Tutorial For Beginners - A Cheat Sheet Review Java 9 Concepts at Jet Speed. Complete Java Course Introduction Background Popularity of Java Platform Independent or Portable Object Oriented Language Security Rich API Great IDE's Omnipresent Web Applications (Java EE (JSP, Servlets), Spring, Struts..) Mobile Apps(Android) Microservices (Spring Boot) Platform Independence Build once, run anywhere Java bytecode is the instruction set of the Java virtual machine graph TD A[Java Code] -->|Compiled| B(Bytecode) B --> C{Run} C -->|bytecode| D[Windows JVM] D --> K[Windows Instructions] C -->|bytecode| E[Unix JVM] E --> L[Unix Instructions] C -->|bytecode| F[Linux JVM] F --> M[Linux Instructions] C -->|bytecode| G[Any other platform JVM] G --> N[Linux Instructions] JDK vs JVM VS JRE JVM (Java Virtual Machine) runs the Java bytecode. JRE JVM + Libraries + Other Components (to run applets and other java applications) JDK JRE + Compilers + Debuggers ClassLoader Find and Loads Java Classes! Three Types System Class Loader - Loads all application classes from CLASSPATH Extension Class Loader - Loads all classes from extension directory Bootstrap Class Loader - Loads all the Java core files Order of execution of ClassLoaders JVM needs to find a class, it starts with System Class Loader. If it is not found, it checks with Extension Class Loader. If it not found, it goes to the Bootstrap Class Loader. If a class is still not found, a ClassNotFoundException is thrown. First Java Program public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } } Notes Every line of code we write in Java is part of something called Class.
    [Show full text]
  • 1. Output of a Java Compiler Is Non Executable Code I.E Bytecode
    Q.1. Write the features of Java Programming. Ans: The primary objective of Java programming language creation was to make it portable, simple and secure ​ programming language. Apart from this, there are also some excellent features which play an important role in the popularity of this language. The features of Java are also known as java buzzwords. ​ ​ A list of most important features of Java language is given below- 1. Simple 2. Object-Oriented 3. Portable 4. Platform independent 5. Secured 6. Robust 7. Architecture neutral 8. Interpreted 9. High Performance 10. Multithreaded 11. Distributed 12. Dynamic Q.2. Why we say Java is a Portable Language. Ans: Java is Considered as Platform independent because of many different reasons which are listed below – 1. Output of a Java compiler is Non Executable Code i.e Bytecode. ​ ​ 2. Bytecode is a highly optimized set of instructions ​ 3. Bytecode is executed by Java run-time system, which is called the Java Virtual Machine (JVM). ​ ​ Q. 3. Short Notes on JVM. Ans: JVM (Java Virtual Machine) is an abstract machine. It is called a virtual machine because it doesn't physically exist. It is a specification that provides a runtime environment in which Java bytecode can be executed. It can also run those programs which are written in other languages and compiled to Java bytecode. JVMs are available for many hardware and software platforms. JVM, JRE, and JDK are platform dependent because the configuration of each OS is different from each other. However, Java is platform independent. ​ There are three notions of the JVM: specification, implementation, and instance.
    [Show full text]
  • Creating Telephony Applications for Both Windows® and Linux
    Application Note Dialogic Research, Inc. Dual OS Applications Creating Telephony Applications for Both Windows® and Linux: Principles and Practice Application Note Creating Telephony Applications for Both Windows® and Linux: Principles and Practice Executive Summary To help architects and programmers who only have experience in a Windows® environment move their telephony applications to Linux, this application note provides information that aims to make the transition easier. At the same time, it takes into account that the original code for Windows may not be abandoned. The ultimate goal is to demonstrate how to create flexible OS-agnostic telephony applications that are easy to build, deploy, and maintain in either environment. Creating Telephony Applications for Both Windows® and Linux: Principles and Practice Application Note Table of Contents Introduction .......................................................................................................... 2 Moving to a Dual Operating System Environment ................................................. 2 CMAKE ......................................................................................................... 2 Boost Jam .................................................................................................... 2 Eclipse .......................................................................................................... 3 Visual SlickEdit ............................................................................................. 3 Using Open Source Portable
    [Show full text]
  • R in a Nutshell
    R IN A NUTSHELL Second Edition Joseph Adler Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo R in a Nutshell, Second Edition by Joseph Adler Copyright © 2012 Joseph Adler. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more infor- mation, contact our corporate/institutional sales department: 800-998-9938 or [email protected]. Editors: Mike Loukides and Meghan Blanchette Indexer: Fred Brown Production Editor: Holly Bauer Cover Designer: Karen Montgomery Proofreader: Julie Van Keuren Interior Designer: David Futato Illustrators: Robert Romano and Re- becca Demarest September 2009: First Edition. October 2012: Second Edition. Revision History for the Second Edition: 2012-09-25 First release See http://oreilly.com/catalog/errata.csp?isbn=9781449312084 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trade- marks of O’Reilly Media, Inc. R in a Nutshell, the image of a harpy eagle, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
    [Show full text]
  • Java Programming Language Keywords
    Color profile: Generic CMYK printer profile Composite Default screenCertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 1 Blind Folio 1:1 Part I The Programmer’s Exam CHAPTERS 1 Language Fundamentals 6 Java.lang—The Math Class, Strings, and Wrappers 2 Declarations and Access Control 7 Objects and Collections 3 Operators and Assignments 8 Inner Classes 4 Flow Control, Exceptions, and Assertions 9 Threads 5 Object Orientation, Overloading and Overriding, Constructors, and Return Types P:\010Comp\CertPrs8\684-6\ch01.vp Thursday, November 14, 2002 3:38:51 PM Color profile: Generic CMYK printer profile Composite Default screen CertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 Blind Folio 2 P:\010Comp\CertPrs8\684-6\ch01.vp Thursday, November 14, 2002 3:38:51 PM Color profile: Generic CMYK printer profile Composite Default screenCertPrs8(SUN) / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 1 Blind Folio 1:3 1 Language Fundamentals CERTIFICATION OBJECTIVES • Java Programming Language Keywords • Literals and Ranges of All Primitive Data Types • Array Declaration, Construction, and Initialization • Using a Variable or Array Element That Is Uninitialized and Unassigned • Command-Line Arguments to Main ✓ Two-Minute Drill Q&A Self Test P:\010Comp\CertPrs8\684-6\ch01.vp Thursday, November 14, 2002 3:38:52 PM Color profile: Generic CMYK printer profile Composite Default CertPrs8(SUN)screen / Sun Certified Programmer & Developer for Java 2 Study Guide / Sierra / 222684-6 / Chapter 1 4 Chapter 1: Language Fundamentals his chapter looks at the Java fundamentals that you need to pass the Java 1.4 Programmer exam.
    [Show full text]
  • Introduction to Java Programming — Comprehensive Version, 10H Ed
    59 Lecture Notes in Programming Foundations Elvis C. Foster Lecture 02: Introduction to Java This chapter contains: . Overview of Java . Compilation Process . Anatomy of a Java Program . Outputting Information on Screen . Primitive Data Types & Variables . Operations . Expressions . Object-Oriented Programming Conventions . Getting Input From Input Dialogs . Getting Input From the Console . The String Class . The Character Class . Formatted Output . Keeping Track of Date and Time . Java Keywords . Commonly Used Java Packages . Summary and Concluding Remarks . Review Questions . Recommended Readings Copyright © 2004 – 2016 by Elvis C. Foster All rights reserved. No part of this document may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, or otherwise, without prior written permission of the author. 60 Lecture 2: Introduction to Java E. C. Foster 2.1 Overview of Java Java is a purely object-oriented programming language (OOPL), originally developed by Sun Microsystems, and currently marketed by Oracle (after acquiring Sun Microsystems). The language, though relatively new, has been through several iterations of refinement. The currently available version is Java 8 Standard Edition (SE). Oracle markets various software packages including the Java language. The ones of immediate interest are: . Java Development Kit 8u25 . Java SE 8u25 . Java SE Run-time Environment 8u25 . Java Development Kit 8.0 with NetBeans 8.0.2 In addition, Oracle markets several other Java-based products. Each product line is marketed with a comprehensive set of documentation, which is accessible via the Oracle website. There are several third- party Java development kits that are available. One such product is Eclipse.
    [Show full text]
  • PDF for Printing
    Topic 16 The keyword list thus far: Complete list of Java keywords: Creating Correct Programs abstract default if private this boolean do implements protected throw "It is a profoundly erroneous truism, repeated by all the break double import public throws byte else instanceof return transient copybooks, and by eminent people when they are making case extends int short try speeches, that we should cultivate the habit of thinking about catch final interface static void char finally long strictfp volatile what we are doinggp. The precise o pposite is the case. class float native super while Civilization advances by extending the number of const for new switch operations which we can perform without thinking about continue goto package synchronized assert enum them. Operations of thought are like cavalry charges in a battle -they are strictly limited in number, they require fresh horses, and must only be made at decisive moments." -Alfred North Whitehead Based on slides for Building Java Programs by Reges/Stepp, found at httppyg://faculty.washington.edu/stepp /book/ CS305j Introduction to Odds and Ends 1 CS305j Introduction to Odds and Ends 2 Computing Computing The Random class Generating "Random" Java has a class named Random whose objects generate Numbers pseudo-random numbers. MthdMethod name DitiDescription nextInt() returns a random integer nextInt(max) returns a random integer in the range [0, max) in other words, from 0 up through one less than the max nextDouble() returns a random real number in the range [0.0, 1.0) –Example: Random rand = new Random(); int randomNumber = rand.nextInt(10); // randomNumber has a random value between 0 and 9 – Class Random is found in the java.util package.
    [Show full text]
  • An Introduction to R Notes on R: a Programming Environment for Data Analysis and Graphics Version 4.1.1 (2021-08-10)
    An Introduction to R Notes on R: A Programming Environment for Data Analysis and Graphics Version 4.1.1 (2021-08-10) W. N. Venables, D. M. Smith and the R Core Team This manual is for R, version 4.1.1 (2021-08-10). Copyright c 1990 W. N. Venables Copyright c 1992 W. N. Venables & D. M. Smith Copyright c 1997 R. Gentleman & R. Ihaka Copyright c 1997, 1998 M. Maechler Copyright c 1999{2021 R Core Team Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into an- other language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the R Core Team. i Table of Contents Preface :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 1 1 Introduction and preliminaries :::::::::::::::::::::::::::::::: 2 1.1 The R environment :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 1.2 Related software and documentation ::::::::::::::::::::::::::::::::::::::::::::::: 2 1.3 R and statistics :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 1.4 R and the window system ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    [Show full text]