PDF Learning Computer Programming Using Java with 101 Examples

[Pages:396] Learning Computer Programming using

JAVA

101with Examples

Atiwong Suchato

LEARNING COMPUTER PROGRAMMING USING JAVA WITH 101 EXAMPLES Atiwong Suchato

1. Java (Computer program language).

005.133

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.

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. 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. 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:

I

Typographical Conventions

The following typographical conventions are used in this book:

Italic indicates new terms, class names, method names, and arithmetic variables.

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. 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.

II

Table of Contents

Chapter 1: Introduction to Computer Systems .............................. 1

Hello Computer, my dear friend!................................................................1 Computers in Our Lives ...............................................................................2 What Computers do ......................................................................................4 Hardware ........................................................................................................ 6

Central Processing Unit................................................................................6 Memory ........................................................................................................7 I/O Devices...................................................................................................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 Measure..........................................................................................13 Problem Solving Using Computer Program............................................14 Exercise ......................................................................................................18

Chapter 2: Programming Concepts .............................................21

Programming Languages ...........................................................................21 Running a Java Program.............................................................................22 Typical Programming Cycle ......................................................................23 Preparing Java Computing Environment ................................................24

Getting the required software .....................................................................24 Letting Your OS Know Where to Find Java...............................................25 Compiling and Running Java Programs ..................................................27 Integrated Development Environment (IDE) ..........................................28 Basic Program Structure in Java ................................................................29 Syntax, Keywords, and Identifiers ............................................................31 Comments..................................................................................................... 32 Be Neat and Organized...............................................................................33 A First Look at Methods .............................................................................33 Escape Sequences.........................................................................................36 Variable at a Glance.....................................................................................37 Naming Rules and Styles............................................................................38 Statements and Expressions.......................................................................40

III

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download