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
Learn Programming by Coding Like a Professional: Create Games, Apps, & Programs Rating: 0 out of 5 stars0 ratingsJava: Beginner's Guide to Programming Code with Java Rating: 0 out of 5 stars0 ratingsJavaScript: Advanced Guide to Programming Code with Javascript: JavaScript Computer Programming, #4 Rating: 0 out of 5 stars0 ratingsJAVA for Beginner's Crash Course: Java for Beginners Guide to Program Java, jQuery, & Java Programming Rating: 4 out of 5 stars4/5Writing Computer Code: Learn the Language of Computers! Rating: 5 out of 5 stars5/5Objective-C Programming Nuts and bolts Rating: 0 out of 5 stars0 ratingsJavascript - 50 functions and tutorial Rating: 0 out of 5 stars0 ratingsTeach Yourself Programming The Guide to Programming & Coding Like a Professional Rating: 0 out of 5 stars0 ratingsJavaScript: Beginner's Guide to Programming Code with JavaScript: JavaScript Computer Programming Rating: 0 out of 5 stars0 ratingsHello Swift!: iOS app programming for kids and other beginners Rating: 0 out of 5 stars0 ratingsComputer Programming Using C Rating: 0 out of 5 stars0 ratingsPython Handbook For Beginners. A Hands-On Crash Course For Kids, Newbies and Everybody Else Rating: 0 out of 5 stars0 ratingsA Day in Code- Python: Learn to Code in Python through an Illustrated Story (for Kids and Beginners) Rating: 5 out of 5 stars5/5C Programming Language Rating: 4 out of 5 stars4/5A Guide To All Programming and Coding Languages Rating: 0 out of 5 stars0 ratingsGet Programming: Learn to code with Python Rating: 0 out of 5 stars0 ratingsFlutter for Jobseekers: Learn Flutter and take your cross-platform app development skills to the next level (English Edition) Rating: 0 out of 5 stars0 ratingsC Programming For Beginners: The Complete Step-By-Step Guide To Mastering The C Programming Language Like A Pro Rating: 0 out of 5 stars0 ratingsPHP Package Mastery: 100 Essential Tools in One Hour - 2024 Edition Rating: 0 out of 5 stars0 ratingsPHP Ajax Cookbook Rating: 2 out of 5 stars2/5Java: Tips and Tricks to Programming Code with Java Rating: 0 out of 5 stars0 ratingsSpring Boot 3.0 Cookbook: Proven recipes for building modern and robust Java web applications with Spring Boot Rating: 0 out of 5 stars0 ratingsA Quick Reference to Data Structures and Computer Algorithms: An Insight on the Beauty of Blockchain Rating: 0 out of 5 stars0 ratingsJava: Tips and Tricks to Programming Code with Java: Java Computer Programming, #2 Rating: 0 out of 5 stars0 ratingsMastering HTML5 Forms Rating: 1 out of 5 stars1/5Microsoft .NET Framework 4.5 Quickstart Cookbook Rating: 0 out of 5 stars0 ratings
Programming For You
Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5DevOps: Introduction to DevOps and its impact on Business Ecosystem: Introduction to DevOps and its impact on Business Ecosystem Rating: 0 out of 5 stars0 ratingsPYTHON PROGRAMMING Rating: 4 out of 5 stars4/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Learn SAP Basis in 24 Hours Rating: 5 out of 5 stars5/5PRINCE2® 6th Edition - A Pocket Guide Rating: 0 out of 5 stars0 ratingsLearn NodeJS in 1 Day: Complete Node JS Guide with Examples Rating: 3 out of 5 stars3/5Java: Programming: Your Step by Step Guide to Easily Learn Java in 7 Days Rating: 4 out of 5 stars4/5Deep Learning For Dummies Rating: 0 out of 5 stars0 ratingsMastering Symfony Rating: 0 out of 5 stars0 ratingsiOS 17 App Development for Beginners: Get started with iOS app development using Swift 5.9, SwiftUI, and Xcode 15 (English Edition) Rating: 0 out of 5 stars0 ratingsScala Programming For Beginners: The Complete Step-By-Step Guide To Learning Scala For Functional Programming And Practical Use Rating: 0 out of 5 stars0 ratingsJavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5The Easiest Way to Learn Design Patterns Rating: 0 out of 5 stars0 ratingsClean Code in JavaScript: Develop reliable, maintainable, and robust JavaScript Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5100 Recipes for Programming Java Rating: 5 out of 5 stars5/5Learn PHP Programming in 7Days: Ultimate PHP Crash Course For Beginners Rating: 3 out of 5 stars3/5Mastering C# and .NET Framework Rating: 5 out of 5 stars5/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Node.js: Tools & Skills Rating: 0 out of 5 stars0 ratingsMastering Docker: From Basics to Expert Proficiency Rating: 0 out of 5 stars0 ratingsDevOps Interview Questions Rating: 4 out of 5 stars4/5Professional Python Rating: 0 out of 5 stars0 ratingsJavaScript: Tips and Tricks to Programming Code with Javascript: JavaScript Computer Programming, #2 Rating: 0 out of 5 stars0 ratings
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