Example: bachelor of science

Learning Computer Programming Using Java with 101 Examples

Learning Computer Programming usingwithExamplesJAVA101 Atiwong Suchato Learning Computer Programming Using JAVA WITH 101 Examples Atiwong Suchato 1. Java ( Computer program language). ISBN 978-616-551-368-5 First Printing: July, 2011 All rights reserved. No part of this publication may be reproduced or distributed in any forms or by any means without the prior written consent of the author. Published by Department of Computer Engineering Faculty of Engineering, Chulalongkorn University Phayathai, Bangkok, 10330 THAILAND This book is a creation of the Knowledge Collection and Contribution Initiatives by the Department of Computer Engineering, Chulalongkorn University To my parents, who have always committed to providing the best education for me.

LEARNING COMPUTER PROGRAMMING USING JAVA WITH 101 EXAMPLES Atiwong Suchato 1. Java (Computer program language). 005.133 ISBN 978-616-551-368-5

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Learning Computer Programming Using Java with 101 Examples

1 Learning Computer Programming usingwithExamplesJAVA101 Atiwong Suchato Learning Computer Programming Using JAVA WITH 101 Examples Atiwong Suchato 1. Java ( Computer program language). ISBN 978-616-551-368-5 First Printing: July, 2011 All rights reserved. No part of this publication may be reproduced or distributed in any forms or by any means without the prior written consent of the author. Published by Department of Computer Engineering Faculty of Engineering, Chulalongkorn University Phayathai, Bangkok, 10330 THAILAND This book is a creation of the Knowledge Collection and Contribution Initiatives by the Department of Computer Engineering, Chulalongkorn University To my parents, who have always committed to providing the best education for me.

2 I Preface Computer Programming skills are currently must-have skills for every university graduate in any fields of Science and Engineering. This book is aimed to be a textbook suitable to be used in a first Programming course for university-level students. The primary goals of this book are to introduce students to creating Computer programs to solve problems with high-level languages.

3 Programming concepts appearing in modern Programming languages are presented through writing Java programs. Java is selected as the language of choice due to its relatively simple grammars. It is also a good choice for introducing students to the concept of object-oriented Programming which is one of the most popular paradigms in the current days. Furthermore, Java is one of the most widely-adopted Programming languages by the industries. This book is developed from the class notes that the author wrote for the introductory Computer Programming course offered to students in the International School of Engineering, Chulalongkorn University. The writing style and the content organization of this book is designed to be straight-forward.

4 Details not crucial to understanding the main materials presented in their related sections are usually omitted in order to relieve the readers from worrying about having to know too much . References for further readings will be given along the way. The author hopes that this book would introduce readers to the joy of creating Computer programs and, with Examples given in this book, writing Computer programs would appear to be more realizable, especially for beginners with absolutely no Programming background. The source code used in all 101 Examples , as well as possible list of errata, can be found on the Facebook page of this book: II Typographical Conventions The following typographical conventions are used in this book: Italic indicates new terms, class names, method names, and arithmetic variables.

5 Bold constant width indicates Java keywords, source codes, expressions used in their related source codes. About the Author Dr. Atiwong Suchato is currently an assistant professor at the department of Computer Engineering, Faculty of Engineering, Chulalongkorn University. He earned his bachelor degree in Electrical Engineering with the first-class honor from Chulalongkorn University while being ranked in the 1st among the graduated class. Dr. Suchato received the Anandamahidol foundation scholarship in 1997 to pursue his advanced degrees at Massachusetts Institute of Technology (MIT). In 2004, he received his doctoral degree in Electrical Engineering and Computer Science from MIT and joined the Department of Computer Engineering, Faculty of Engineering, Chulalongkorn University.

6 Since then, Dr. Suchato has been teaching Computer Programming courses to students in several programs including programs in the International Engineering School (ISE), Chulalongkorn University. He was appointed an assistant dean position overlooking the Information Technology strategies and their implementation in 2008. He was also a key member in the team that initiated the Information and Communication Engineering (ICE) program for the faculty in 2005 as well as the committee revising its curriculum in 2010. His research interests are in the area of computerized speech and language technologies and their applications to assistive technology. III Table of Contents Chapter 1: Introduction to Computer Systems.

7 1 Hello Computer , my dear friend!.. 1 Computers in Our Lives .. 2 What Computers do .. 4 6 Central Processing Unit .. 6 Memory .. 7 I/O 8 Software .. 9 Application Software Vs. System Software .. 10 Operating System (OS).. 11 Binary Representation of Data .. 11 The Power of Two .. 12 Units of 13 Problem Solving Using Computer 14 Exercise .. 18 Chapter 2: Programming Concepts ..21 Programming Languages .. 21 Running a Java 22 Typical Programming Cycle .. 23 Preparing Java Computing Environment .. 24 Getting the required software .. 24 Letting Your OS Know Where to Find 25 Compiling and Running Java Programs .. 27 Integrated Development Environment (IDE) .. 28 Basic Program Structure in Java .. 29 Syntax, Keywords, and Identifiers .. 31 32 Be Neat and 33 A First Look at Methods.

8 33 Escape 36 Variable at a 37 Naming Rules and 38 Statements and Expressions .. 40 IV Simple Representing Algorithms Using Manual Decisions and Subroutines ..49 More Shapes ..51 Exercise ..52 Chapter 3: Working with Data .. 55 Strong Data Typing ..55 Data Types in Java ..56 Primitive Data Type for Integers ..56 Primitive Types for Floating-Point Values ..57 Primitive Type for Characters ..58 Primitive Type for Logical Values ..59 String ..59 Assigning Data to Variables ..60 Final Un-initialized Variables.

9 64 Operators ..65 String and the addition operator (+) ..67 Math methods ..68 Precedence and Exercise ..76 Chapter 4: More Issues on Data Manipulation .. 79 Numeric Data Type Data Type Conversion ..80 Automatic Type Conversion and Explicit Type Expressions with Multiple Data Types ..83 Limitation on Floating Point Computation ..85 An Issue on Floating Point Value Comparison ..87 Overflow and Underflow ..87 Numbers Divided by Zero ..90 Compound Increment and Decrement ..94 Exercise ..96 V Chapter 5: Using Objects.

10 101 Classes and Objects .. 101 Using Data and Methods provided in Classes .. 103 Useful String methods .. 107 charAt() .. 107 length() .. 107 concat() .. 108 indexOf() .. 109 lastIndexOf() .. 110 startsWith() .. 113 endsWith() .. 113 trim().. 113 substring().. 114 toLowerCase() .. 114 toUpperCase() .. 114 valueOf() .. 116 Reading Input String from Keyboards .. 116 Converting Strings to 118 parseInt() .. 118 parseDouble() .. 119 Useful Methods and Values in Class Integer and Class Double .. 119 Reading Formatted Input Using Scanner .. 127 next() .. 128 nextBoolean() .. 130 nextByte() .. 130 nextDouble().. 130 nextFloat() .. 130 nextInt() .. 130 nextLong() .. 130 nextShort().. 131 Exercise .. 132 Chapter 6: Decisions ..137 Controlling the Flow of Your 137 If 138 If-else 142 Nested 145 If-else-if Construct.


Related search queries