Principles of Programming: Java Level 1
()
About this ebook
Jonathan Frank
Jonathan Frank grew up and currently lives in the Northeastern United States. He is passionate about math, programming, and teaching both subjects to students of all ages and backgrounds. Since 2007, he had dreamed of writing a programming textbook. He now has ten years of programming experience (several languages) and a BS in computer science from the NYU Polytechnic School of Engineering. Armed with these assets, he penned Principles of Programming: Java Level 1. Imagine his voice patiently reading the words to you, in the conversational tone of his first book.
Related to Principles of Programming
Related ebooks
Python Programming for Beginners: A guide to Python computer language, computer programming, and learning Python fast! Rating: 5 out of 5 stars5/5Python Programming: Your Beginner’s Guide To Easily Learn Python in 7 Days Rating: 3 out of 5 stars3/5Java: Beginner's Guide to Programming Code with Java Rating: 0 out of 5 stars0 ratingsMy First In Java Rating: 0 out of 5 stars0 ratingsJavascript Concepts: 1St Edition Rating: 0 out of 5 stars0 ratingsProgramming in C | Step by Step: The Simple Beginner's Guide Rating: 0 out of 5 stars0 ratingsThe Javascript Adventure Rating: 0 out of 5 stars0 ratingsObjective-C Programming Nuts and bolts Rating: 0 out of 5 stars0 ratingsIntroduction to Python 2018 Edition Rating: 4 out of 5 stars4/5Selenium Webdriver: Book1 Rating: 2 out of 5 stars2/5A concise guide to PHP MySQL and Apache Rating: 4 out of 5 stars4/5How To Program A Mobile Game Rating: 4 out of 5 stars4/5Python Programming: Your Step By Step Guide To Easily Learn Python in 7 Days Rating: 3 out of 5 stars3/5How To Create An App Rating: 3 out of 5 stars3/5Flutter for Jobseekers: Learn Flutter and take your cross-platform app development skills to the next level (English Edition) Rating: 0 out of 5 stars0 ratingsCrafting HTML Email Rating: 0 out of 5 stars0 ratingsMastering Computer Programming Rating: 0 out of 5 stars0 ratingsSimultaneous multithreading A Complete Guide Rating: 0 out of 5 stars0 ratingsJavascript - 50 functions and tutorial Rating: 0 out of 5 stars0 ratingsHow to Become a Successful Programmer Without a Degree Rating: 0 out of 5 stars0 ratingsSwift Essentials - Second Edition Rating: 0 out of 5 stars0 ratingsA Guide To All Programming and Coding Languages Rating: 0 out of 5 stars0 ratingsProfessional JavaScript for Web Developers Rating: 0 out of 5 stars0 ratingsBuilding Android Games with Cocos2d-x Rating: 0 out of 5 stars0 ratingsMastering Android Game Development Rating: 0 out of 5 stars0 ratingsMastering HTML5 Forms Rating: 1 out of 5 stars1/5iOS 13 Programming for Beginners - Fourth Edition: Get started with building iOS apps with Swift 5 and Xcode 11, 4th Edition Rating: 0 out of 5 stars0 ratings
Programming For You
SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5C All-in-One Desk Reference For Dummies Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsLearn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5Coding with JavaScript For Dummies Rating: 0 out of 5 stars0 ratingsExcel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5C Programming For Beginners: The Simple Guide to Learning C Programming Language Fast! Rating: 5 out of 5 stars5/5HTML in 30 Pages Rating: 5 out of 5 stars5/5Microsoft Azure For Dummies Rating: 0 out of 5 stars0 ratingsBeginning Programming with C++ For Dummies Rating: 4 out of 5 stars4/5Gray Hat Hacking the Ethical Hacker's Rating: 5 out of 5 stars5/5Automate the Boring Stuff with Python, 2nd Edition: Practical Programming for Total Beginners Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsLinux: Learn in 24 Hours Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5
Reviews for Principles of Programming
0 ratings0 reviews
Book preview
Principles of Programming - Jonathan Frank
Copyright © 2016 by Jonathan Frank.
Library of Congress Control Number: 2015919764
ISBN: Hardcover 978-1-5144-3039-2
Softcover 978-1-5144-3038-5
eBook 978-1-5144-3037-8
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 by any information storage and retrieval system, without permission in writing from the copyright owner.
Any people depicted in stock imagery provided by Thinkstock are models, and such images are being used for illustrative purposes only.
Certain stock imagery © Thinkstock.
Rev. date: 12/22/2015
Xlibris
1-888-795-4274
www.Xlibris.com
725930
CONTENTS
Lesson 0: Setting Up Your Computer for Software Development
0-1: Installing the Necessary Software
Lesson 1: The First Program: ‘Hello World’
1-1: Getting Something on the Screen
Lesson 2: Anatomy of the First Program
2-1: The Whole Program
2-2: The Print Statement
2-3: The main Method
2-4: The HelloWorld Class
2-5: Packages
2-6: Comments
Lesson 3: Output: Printing Stuff on the Screen
3-1: Program: About Me
3-2: Anatomy of a Print Statement
3-3: Other Kinds of Print Statements
Lesson 4: Information Storage
4-1: Program: Know and Show
4-2: Anatomy of an Assignment Statement
4-3: More Kinds of Print Statements
4-4: Changing the Value of a Variable
Lesson 5: Calculation
5-1: Arithmetic in Java
5-2: Program: Count to Three
5-3: Formula Translation
Lesson 6: String Concatenation
6-1: Program: Silly Sentence
6-2: Consolidating Print Statements
Lesson 7: User Input
7-1: Allowing the User to Enter a Temperature
7-2: Program: My Signature
Lesson 8: Boolean Logic
8-1: Inside the Mind
of a Computer
8-2: Questions, Answers, and the Boolean Data Type
Lesson 9: Making Decisions with Boolean Logic
9-1: Deciding Between Two Choices: If and Else
9-2: Deciding Between More Than Two Choices: If, Else If, and Else
Lesson 10: Advanced Boolean Logic
10-1: The Logical NOT Operator
10-2: The Logical AND Operator
10-3: The Logical OR Operator
Lesson 11: Loops
11-1: Repeating Actions with While Loops
11-2: Game: Guess My Number
Appendix: Other Useful Information
A-1: What to Do If You Need Help
A-2: Naming Things in Java
A-3: Methods of the String Class
A-4: Methods of the Math Class
A-5: How to Get Multi-Word Input, Using the Scanner Class
Master Vocabulary List for Lessons 0-11 and the Appendix
Lesson 0
"Setting Up Your Computer
for Software Development"
0-1: Installing the Necessary Software
Modern computer systems do not usually come with the software (programs) necessary for software development (the creation of new programs). In order to develop software, you will need to install a few things on your computer.
The first thing that you will need to install is the Java Runtime Environment (JRE), which allows your computer to run programs that are written in Java. You’ll be learning how to use the Java programming language. A programming language is a special language that allows a person (a programmer) to tell a computer to do something, by telling it EXACTLY how to do that thing. A programmer writes a program’s source code, and runs a special program, called a compiler, which transforms the source code into something the computer can understand.
To install the JRE, follow these instructions:
• Go to http://www.java.com.
• Click the Free Java Download
button.
• On the next screen, click the Agree and Start Free Download
button.
• Your computer will download a program. Start that program, once it has been downloaded.
• Follow the prompts (things that tell you to do something) on the screen:
o Click the Install
button.
o If there is any offer
to install an unrelated (and BAD) piece of software, such as the Search App by Ask
, UNCHECK THE BOX next to Add the Search App by Ask
, and then click the Next
button.
o Wait.
o If the JRE installer detects out-of-date Java versions, click the Remind Me Later
button.
o Click the Close
button.
• Your web browser will re-open.
The JRE only allows you to run (start up and use) Java programs, though. The next thing that you will need to install is the Java Development Kit (JDK), which is a collection of tools that will allow you to develop programs in Java. However, to simplify the process of installing the necessary software on your computer, you can combine the installation of the JDK with the installation of an integrated development environment (IDE) called NetBeans. An IDE allows you to write your code, compile it, run your programs, and debug (fix mistakes in your code) them, all in one place.
To install the JDK and the NetBeans IDE, follow these instructions:
• Go to http://www.netbeans.org.
• Click the Download
button.
• Click the JDK with NetBeans IDE Java SE bundle
link. It’s in a paragraph of text, near the bottom of the page. You may need to scroll down.
• Check the Accept License Agreement
radio button.
• Click the red arrow/link next to your operating system.
o If your computer is from around 2010 or later, choose x64
.
o Else, choose x86
.
o If you don’t know, choose x86
.
• Your computer will download a program. Start that program, once it has been downloaded.
• Wait.
• Follow the prompts on the screen:
o Click the Next
button.
o Check the I accept the terms in the license agreement. Install JUnit.
radio button.
o Click the Next
button.
o Click the Next
button.
o Click the Next
button.
o Click the Install
button.
o Wait.
o If you get a dialog box on the screen, which asks you to close certain programs before continuing, click the Close Programs and Continue
button.
o Click the Finish
button.
If everything worked, then it’s time to begin the next lesson, in which you will write your first program in Java!
Lesson 1
The First Program: ‘Hello World’
1-1: Getting Something on the Screen
It’s time to start up