Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Discover millions of ebooks, audiobooks, and so much more with a free trial

From $11.99/month after trial. Cancel anytime.

Essential Java for AP CompSci: From Programming to Computer Science
Essential Java for AP CompSci: From Programming to Computer Science
Essential Java for AP CompSci: From Programming to Computer Science
Ebook403 pages2 hours

Essential Java for AP CompSci: From Programming to Computer Science

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Gain the essential skills for computer science using one of today's most popular programming languages, Java. This book will prepare you for AP CompSci Complete, but you don’t need to be sitting that class to benefit. Computer science has become a basic life skill that everyone is going to need to learn. Whether you are going into a career or side hustle in business, technology, creativity, architecture, or almost any other field, you will find coding and computer science play a role. 

So when we learn programming we are going to focus on three things: what is the process; what is the syntax; and what is the flow. The process is represented as a flowchart. We will learn how to make these to help you plan out what you are going to do before you write a line of code. At first, the flowcharts will be pretty simple, but then they will get more complex. The syntax is the code: this is what you write that translates the process you create in a flowchart to the instructions that the computer can understand. Finally, there is the flow. This is where you trace through the code and see how the data and information it stores along the way changes. You can see how the operation of the program cascades from line to line. You will be building charts that will capture the programming flow so you can better understand how the computer processes code to make your next program easier to conceive and code.

Along the way to aid in the learning of the essential Java skills, there will be three kinds of project types throughout this book: business software projects for applications where you work for a company and need to complete an internal project for a team such as the sales, marketing, or data science teams; social good projects where you are working for non-profits or for agencies that are trying to research and provide solutions to economic, environmental, medical, or humanitarian projects; and game development projects for games basedon player input, random chance, or other mechanics for the use of entertainment.

What is unique about computer science is how it has become a skill, and not just a career. While there are jobs and titles of “computer scientist”, the skill of computer science, and specifically programming, are almost everywhere. After reading and using this book, you'll have the essential skills to think like a computer scientist, even if you are not. As a result you’ll be of greater value to your clients, your company, and yourself.  

What You Will Learn

    Discover the primary building blocks of programming using the Java programming language
  • See terminology and best practices of software development
  • Work with object-oriented programming concepts
  • Use common-language definitions and examples to help drive understanding and comprehension of computer science fundamentals

Who This Book Is For

Those who want to learn programming and want to think like a computer scientist. Ideal for anyone taking AP CompSci Complete.

LanguageEnglish
PublisherApress
Release dateJul 30, 2021
ISBN9781484261835
Essential Java for AP CompSci: From Programming to Computer Science

Related to Essential Java for AP CompSci

Related ebooks

Computers For You

View More

Related articles

Reviews for Essential Java for AP CompSci

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Essential Java for AP CompSci - Doug Winnie

    © Doug Winnie 2021

    D. WinnieEssential Java for AP CompScihttps://doi.org/10.1007/978-1-4842-6183-5_1

    1. Introduction

    Doug Winnie¹  

    (1)

    Mission Hills, KS, USA

    Computer science has become a basic life skill that everyone is going to need to learn. Whether you are going into a career or side hustle in business, technology, creativity, architecture, or almost any other field, you will find programming, coding, and computer science play a role.

    In fact, if you look at the top skills on LinkedIn for the United States, in the last year all ten of the top were programming, computer science, or code related. These include cloud and distributed computing, statistical analysis, data mining, mobile development, storage systems management, user interface design, network and information security, middleware and integration software, web architecture and development frameworks, algorithm design, and Java development.¹

    What is unique about computer science is how it has become a skill, and not just a career. While there are jobs and titles of Computer Scientist, the skill of computer science, and specifically coding and programming, is almost everywhere.

    In marketing, you need to analyze and sift through tons of user data and metrics on how people use your products, website, apps, or services. In medicine, doctors and researchers need to gather and analyze data gathered from clinical studies or to find new breakthroughs. In agriculture and farming, thousands of IoT devices need to be deployed and managed to gather data on soil conditions, humidity, and crop health. In architecture and construction, mapping out and analyzing how people use elevators, building infrastructure, or public spaces can help design better buildings for people to work and live in. Even when building a side business, or hustle, entrepreneurs may need to perform research, build a website, program a mobile app or game, or perform tons of different activities involving code, logic, automation, and programming.

    When people create projects based on code, they organize their work into multiple chunks or segments of development. They call these sprints. So, we will learn Java in the same way, using multiple sprints that will teach a single topic to help us keep pace with things along the way. Part of what makes learning coding difficult is it can be difficult to find real-world examples to draw parallels from. If you are planning on taking the AP Exam in Computer Science, many of the questions will not have any real-world context and will require you to understand and follow code without that as a reference.

    For you, this can make it confusing, but just remember: there are two sides to programming—what is being done and how it happens.

    The what is pretty easy, and this gives the code context, like parsing transit data, rolling a virtual die, or adding sales data for a quarter together.

    How it happens is a completely different story however. This is where you need to break things down into individual steps and start to think like a computer. A computer is going to think only about one single step at a time. It has no concept of what comes next or what came before it. It only is concerned with the present. So, if it can’t find something—you get an error. If it tries to do something that doesn’t exist—you get an error. If you try doing something out of order—you guessed it, you get an error.

    In fact, the computer is pretty dumb. I mean, like really dumb. What makes it smart is how we are able to string multiple actions together to make something work. And with growing advances in artificial intelligence, the computer itself can start making adjustments. And then Skynet activates, and we all know what happens after that.

    So when we learn programming, we are going to focus on three things:

    What is the process

    What is the syntax

    What is the flow

    The process is represented as a flowchart. We will learn how to make these to help you plan out what you are going to do before you write a line of code. At first, the flowcharts will be pretty simple, but then they will get more complex. And yep, you will get pretty annoyed with flowcharts before the year is over, but trust me…they help.

    The syntax is the code; this is what you write that translates the process you create in a flowchart to the instructions that the computer can understand.

    Finally, there is the flow. This is where you trace through the code and see how the data and information it stores along the way changes, and you can see how the operation of the program cascades from line to line. You will be building charts that will capture the programming flow so you can better understand how the computer processes code to make your next program easier to conceive and code.

    What You Need

    You will need a Windows or macOS computer to complete the projects in this book. You will need to install and configure the Java JDK (Java Development Kit) and IntelliJ from JetBrains (our IDE or code editor for the class). If you are on macOS, it is suggested that you uninstall the built-in Java JRE (Java Runtime Environment) and use the one included in the Oracle Java JDK. This will avoid warnings that appear when you build your projects.

    Footnotes

    1

    The Top 10 Skills You Will Be Hiring For in 2017, https://business.linkedin.com/talent-solutions/blog/trends-and-research/2016/linkedin-new-report-reveals-the-latest-job-seeking-trends

    © Doug Winnie 2021

    D. WinnieEssential Java for AP CompScihttps://doi.org/10.1007/978-1-4842-6183-5_2

    2. Setting Up the Java JDK and IntelliJ

    Doug Winnie¹  

    (1)

    Mission Hills, KS, USA

    To get started with our exercises, we need to set up our computers to work with Java code and run it. This is called creating a development environment.

    As you learn more about coding and programming, you will encounter many different tools to help you do your job. There are so many in fact, that you might find that one fits better than another. While they all essentially do the same thing, there are features and options in different tools that mesh better with different types of coders.

    Coding Tools and IDEs

    Coding tools, and their more sophisticated brothers, the integrated development environment, or IDE, can sometimes spark passionate debate on which one is considered the best, but ultimately it comes down to you, the coder, to decide what is best for you.

    To help make this course and the tools we use easy to understand and the same across Windows and macOS, the tool we will use is IntelliJ IDEA . IDEA is a free coding tool from JetBrains that is easy to use, not very complicated, and it is the same across platforms.

    There are others that you can use for this course as well. Some examples are Eclipse or NetBeans. These tools provide the same features, but I wouldn’t recommend using them to help us all be consistent with our tools when working together.

    The other key tool you will need is the Java Development Kit or JDK. In order for the IDE to work, it needs to have the Java compiler to create your Java bytecode and then use the Java Runtime Environment or JRE to run your program in a virtual machine, called the JVM.

    The version that you will use is the Java SE or Standard Edition that you can download for free from Oracle. Regardless if you use IDEA, or another IDE, you will need to install the JDK in order to compile and build your programs.

    Installation and Setup

    If you want to follow along with the same tools that I’ll be using, you will need to install the JDK and IntelliJ IDEA.

    To install the tools I’m using, you will need a PC with Windows 7, 8, 8.1, or 10 already installed.

    For a macOS computer, you will need Yosemite, High Sierra, or Mojave. It is recommended that you uninstall the version that Apple installs by default (called OpenJDK). Refer to instructions online for how to do this.

    Install the JDK

    First, we need to install the JDK.

    With your browser, go to the Oracle website:

    www.oracle.com/technetwork/java/javase/downloads/index.html

    From here, click the Java JDK download button.

    Then accept the license agreement, and then select Windows which must be installed on a 64-bit computer and operating system or for macOS.

    Your browser will prompt you to save the installer to your computer. Save and run the installer using the defaults for the configuration.

    Remember the location of where the JDK is installed; you will need this later on to connect IntelliJ IDEA to the JDK.

    Install IntelliJ

    Now we need to install IntelliJ IDEA.

    With your browser, go to the JetBrains website:

    www.jetbrains.com

    Under Tools, look for the column IDEs, and select IntelliJ IDEA. We will use the Community Edition, which is free.

    Your browser will prompt you to save the installer to your computer. Click Save to continue and download.

    Run the installer and accept the defaults for all the settings.

    That’s it! IntelliJ IDEA and the Java Development Kit are successfully installed!

    © Doug Winnie 2021

    D. WinnieEssential Java for AP CompScihttps://doi.org/10.1007/978-1-4842-6183-5_3

    3. Setting Up GitHub

    Doug Winnie¹  

    (1)

    Mission Hills, KS, USA

    When you code, you need to have a location to store it and share that code with others to work with it and review it. Tools called code repositories are ideal ways to do this, and there are several different types that are available for developers to use; one of the most popular is GitHub, and we will explore it here. GitHub, in the context of this book, is a tool that you can use on your own. I’m introducing it here, because as you get more familiar with programming, you’ll find it to be an indispensable tool.

    ../images/499634_1_En_3_Chapter/499634_1_En_3_Fig1_HTML.png

    Figure 3-1

    Repository lifecycle

    GitHub

    The one that we will use is called GitHub. GitHub is a free public code platform that developers use to build, archive, and manage coding projects for individual or group collaboration. It is built on the Git technology that is ordinarily used for private, internal projects, but GitHub builds their public platform on Git to make it available to anyone.

    To create a GitHub account is simple. Go to www.github.com/ and create an account there. For our use in class, please create your account as your Serra email address so I can easily identify your account.

    When you create your account, be sure to go to GitHub Desktop to download the desktop client for Windows or macOS. You can download the installer here: https://desktop.github.com/.

    Install the client and sign in to your account. You can then create a repository to keep track of the changes you make in your classwork projects. You can create a single project to capture all of your homework assignments, or you can create an individual repository for each project. Whichever you choose is up to you.

    How GitHub Works

    GitHub and Git create a special directory that it uses to keep track of all changes that you make to the files inside of it. When you make a change to a file, it tracks what the change was and notes that.

    This is different than a backup. A backup creates a copy of everything that is in a folder. A change in Git and GitHub only records what changed, which can save a lot of space and is much faster to process.

    There are many advanced workflows and automations that you can tie into Git and GitHub, but we will only be using the platform to store and share projects and homework assignments.

    There are ways to tie in GitHub directly into the IntelliJ IDEA IDE, but for simplicity, we can use the GitHub Desktop client to make, track, commit, and sync changes to our GitHub account.

    Lifecycle of a Repository

    A repository, or repo, starts with the master branch, sometimes known as a trunk. For individual developers, or small teams, projects might only use a master branch and never create alternate versions of it.

    As the program evolves and new changes are made, they are saved to the repository by making a commit. A commit contains the changes to the code and a brief comment and description made by the developer on what changed for future reference. Over time, there will be dozens or hundreds of commits on a repository.

    At some point, a repository will need to split in some way. Either there needs to be simultaneous work and they don’t want to have code conflict with others, or a project needs to maintain an existing version and they want to do something else with it. In that case, a branch is created from the main trunk, and development can happen in parallel with the original code.

    At some point, a branch will need to rejoin the main development, and this is done by merging that branch back into the master trunk.

    For open source repositories, it is common for a developer to find a helpful framework and want to add it to their own development environment. To do that, they would fork the repository, creating a copy in their own environment to work with and potentially make changes.

    When a developer makes changes or improvements to a forked repository, they might want to contribute those changes back to the main repository they forked from. To do that, they submit a pull request back to the original repository. As part of this pull request, the developer outlines the changes that were made, and the person who receives the requests can compare the proposed changes to the repo by performing a diff that shows the changes side by side from one another.

    Repositories can vary in complexity from something very simple with a single or a handful of developers to a large open source project with tens of thousands of developers. Code repos are the core of how software developers work together on projects of any size.

    © Doug Winnie 2021

    D. WinnieEssential Java for AP CompScihttps://doi.org/10.1007/978-1-4842-6183-5_4

    4. Programming Languages

    Doug Winnie¹  

    (1)

    Mission Hills, KS, USA

    Programming languages started as an abstract concept and then adapted and changed over time. From the origins of machine language, switch input, extending into the early days of simple line-by-line coding like COBOL or BASIC to object-oriented languages like Java and C#, to quantum computer languages like Q#, the evolution of programming languages has developed over the course of many decades.

    Origin of Programming

    In the early 1840s, Charles Babbage proposed a machine called the Analytical Engine. It was only a proposal—no actual machine was built, but one inventive woman by the name of Ada Lovelace decided to write an article that provided detailed instructions on how to represent Bernoulli [ber-noo-li] numbers, a recursive equation based on number theory, on the Analytical Engine. This article is considered to be the very first computer program.

    Since then the devices that can be programmed went from theoretical to physical, manual to automatic, analog to digital. With each evolutionary step, the way we program computers needed to evolve as well.

    With the birth of mainframe computers, data processing required instructions to be sent to the machine to process and interpret the instructions from the programmer. This was then applied to data to organize and analyze the data. Instructions were entered through a keyboard, but without the benefit of a monitor, so everything was done through printouts on paper or storing data in the form of punched holes on cards that were stored in stacks. If you look carefully at text encodings and at some programming languages, you’ll see things like carriage return or print that are carryovers from those printer days from decades ago.

    As computers got smaller and more powerful, more languages were created. Languages also were created to serve specific types of projects and industries like mathematics and science, data storage, and graphics.

    Today, we work with programming languages that can serve many different purposes. In fact, a programmer often needs to use multiple programming languages to get a project completed. As languages have evolved, they have become specialized to complete specific tasks. As a programmer, you will use the best languages for specific tasks and combine them together to create your project.

    The programming languages you learn today will continue to evolve and change in the future. With future waves of new technology, new languages will be developed to allow programmers to drive even more innovation.

    Forms of Programming

    As programming has evolved over the decades, the types of programming you can do have changed as well. Depending on what you want to do, there are different types or forms of programming languages that work in different ways. As a programmer, some forms of programming give you direct access to the computer processor, while others abstract the hardware into more human language that needs to be translated or converted into the native language of

    Enjoying the preview?
    Page 1 of 1