Introduction to Java Programming (gnv64).pdf

(20994 KB) Pobierz
All rights reserved. No part of this book may be reproduced or transmitted in any
form or by any means, electronic or mechanical, including photocopying, recording,
or any information storage and retrieval system, without permission in writing
from the publisher and Nagaraj Rao and John Yoon in 2015.
Book Team
President : Vijay Sharma
Sr. Vice President : Puneet Singh (London) Vice President : Kanika Sharma (London) Pre‐Press : P. K. Mishra
Vice‐President Marketing : Agnel Henry
ISBN : 93‐82661‐26‐3
Published and Digitally Printed in India in 2016 with permission from the copyright holder by:
Indo American Books (IA Books)
2261, Ground Floor, Hudson Line, Kingsway Camp Delhi 110009, INDIA. Ph.: 91‐011‐42870094
Email: sales@iabooks.com
Web: www.iabooks.com
ii
Contents
Chapter 1 – Introduction 1
1.1 JDK and IDE installation 1
1.1.1 Install JSE, aka jdk 1
1.1.2 Download IDE Eclipse 4
1.1.3 Creating and Running Java Programs 7
1.2 First Java Programs 8
1.2.1 What is Java Language? 8
1.2.2 Create and Run Welcome Program 10
1.2.3 Examples 10
1.3 Graphics 13
1.3.1 Chapter Exercises 17
1.3.a What did you learn? 18
Chapter 2 – Data Types, Assignment, Output 19
2.1 Data Types and Identifiers 19
2.2 Expressions 21
2.3 Assignment Statement 24
2.4 Input from the Keyboard 26
2.5 Chapter Exercises 34
Chapter 3 – Conditional Statements 37
3.1 Case for variables 37
3.2 If – else Statement 40
3.3 Switch Case Statement 45
3.4 Comparison between if…else and switch…case statements 48
3.5 Chapter Exercises 49
iii
Chapter 4 – Repetition Statements 55
4.1 for Loop 55
4.2 while Loop 65
4.3 do-while Loop 69
4.4 Formatting Output Data 70
4.5 Reading from a Text File 72
4.6 Chapter Exercises 77
Chapter 5 – Java Application Programming Interfaces (API) 85
5.1 Introduction 85
5.2 Math Class 86
5.3 String Class 90
5.4 Writing to a Text File 93
5.5 What did you learn? 95
5.6 Chapter Exercises 96
Chapter 6 – Classes and Objects 99
Zgłoś jeśli naruszono regulamin