ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Learn Computer Programming - Beginner Tutorial

Updated on November 13, 2014

Why did I choose computer programming?

Computer programming has been one of my passions since I was 11 years old. I'll never forget how excited I was when my parents bought me my first ColecoVision computer! At that time, computers were primarily tape driven. Flipping through the operator's manual, I discovered that my machine was fully programmable! Writing my first program and seeing it in action was a euphoric moment for me! That's all it took to get me hooked!

Why did I write this Hub?

The goal of this Hub is to encapsulate my knowledge, consisting of over 11 years of experience, into an article that propels the reader into the Information Age.

One of the challenges I've experienced is finding a single text that covers how mathematics and computer programming are interrelated. Often these are viewed as disparate topics. My objective is to provide you with a holistic learning opportunity that brings these two worlds together and provide you with a solid foundation into the world of programming.

"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." – Socrates

Why should I get into computer programming?

The landscape that we once knew is rapidly changing. We've seen a paradigm shift that has propelled us from the Industrial Age into the Information Age. Our society has become so dependent on technology that it's hard to imagine our world without it.

An exciting innovation that has taken the development world by storm is the advent of software distribution marketplaces. Developers can now upload and sell their applications to the masses. Imagine that you designed a top-notch phone application that becomes popular and decide to sell it for $0.99 cents a download. Note: Keep in mind that the marketplace vendor will charge 20%-30% off the top. So roughly $0.30 per sale will go back to the vendor. If the application gets 100,000 downloads, you would bank $70,000 (not including taxes). Electronic distribution has incredible potential as there is nothing to ship! It's like selling air!

Software Requirements

This Hub does not require any software to be installed. In fact, all of your programming will be done online using JavaScript! Once all of the math concepts have been mastered, you'll be on an excellent path to becoming a great programmer!

Math Essentials

Some basic math and Algebra will go a long way in your programming career. Many of the concepts in math will translate directly over to computer programming. I see math as a collection of tools that can be used to solve a problem. In my opinion, learning how to apply math to a real world problem is more important than the mechanical steps needed to solve.

Important: At this point in the tutorial, don't worry if some of the math concepts seem foreign. For now, I just want you to become familiar with them. Later in the tutorial, you'll see how these concepts come together.

Math - Variables

A variable is simply a container. Think of it as like an empty box that can hold something.

In Algebra, you may recall a simple statement such as:

x = 10

In this example, the number 10 is assigned to the variable x. So variable x now equals 10.

Let's look at another problem.

10 + x = 14

In this simple problem, we can easily infer that x must be equal to 4 to balance the equation.

Math - Variables - Quiz

view quiz statistics

Math - Comparison Symbols

In Math, we can use symbols to compare numbers and variables. These symbols are:

< (Less Than)
(Less Than Or Equal To)
> (Greater Than)
(Greater Than or Equal To)
= (Equals)
(Not Equal)

Math - Comparison Symbols - Quiz

view quiz statistics

Math - Order of Operations

In math, the way in which terms are ordered can dramatically the impact resulting calculation. For example:

2 + 3 × 5

Intuitively, it's easy to assume that the first set of terms (2+3) would be calculated first. This is wrong however, as it would yield 25 which is incorrect. The correct answer is 17. Why? You may recall the mnemonic PEMDAS. This is the order in which terms should be evaluated.

P = Parentheses
E = Exponents
M = Multiplication
D = Division
A = Addition
S = Subtraction

Don't let the mnemonic fool you however, the M and D does not explicitly mean that multiplication happens before division. The same applies to A,S.

How can we ensure that the calculation for 2+3 happens first? We do this by using parentheses. For example:

(2 + 3) x 5 = 25

For more information, check out this tutorial: Operations in the correct order

Order of Operations - Quiz

Let's go ahead and do a practice quiz:

Problem:
2 + (3 × 5)
Answer:
17 - The terms in parenthesis are calculated first.


Problem:
2 + 3(5)
Answer:
17 - The multiplication terms are calculated first.

Problem:
2 + 15 ÷ 5
Answer: 5 - The division terms are calculated first.

Problem
5 - 2 + 22 + 15 ÷ 5
Answer:

  1. Exponents always come first so let's simplify 22
    5 - 2 + 4 + 15 ÷ 5
  2. Division comes before addition/subtraction so let's simplify further
    5 - 2 + 4 + 3
  3. Now read from left to right
    3 + 4 + 3
  4. The final calculation is
    10


Problem
5 x 5 ÷ 5
Answer: 5 - When adjacent multiplication/division terms are present, solve from left to right.

Problem
24 ÷ 6 x 5
Answer: 20 - The same rule applies, when adjacent division/multiplication terms are present, solve from left to right.

Problem
5 - 2 + 5
Answer:
8 - When adjacent subtraction/addition terms are present, solve from left to right.


Problem
4 + 3 - 4 = 3
Answer: 3 - The same rules apply, when adjacent addition/subtraction terms are present, solve from left to right

Working with Positive and Negative Numbers

Working with positive and negative numbers is an essential skill you will utilize throughout your programming career.

My wife and I were joking around one morning as I posed the question, "Do you love to hate me or love to love me." Right then, it dawned on me that this was the perfect example for illustrating the Algebra rules surrounding positive and negative numbers. Think of the positive as "love" and the negative "hate". Let's look at each of these statements and determine if it's positive or negative (Note: the positive and negative signs are added for reference):

1) I love (+) to hate (-) you.
Answer: negative statement

2) I hate (-) to love (+) you.
Answer: negative statement

3) I love (+) to love (+) you.
Answer: positive statement

4) I hate (-) to hate (-) you.
Answer: positive statement

Now let's apply what we have just learned. To get started, read through the following tutorials to get a basic understanding of how to add, subtract, multiple, and divide positive and negative numbers:

AND vs. OR Operators

A condition is a statement that yields either a true or false answer. As an example, imagine that you are a customer attempting to sign into an internet web site that requires security credentials to be entered. In order to be authenticated, certain conditions must be met. Let's have variables A, B and C represent each of the following conditions:

Let variable A = Customer entered correct password (True/False)
Let variable B = Customer entered correct security question # 1 (True/False)
Let variable C = Customer entered correct security question # 2 (True/False)

The "And" Operator

Joining these three conditions using the "AND" operator will require that A and B and C be correct. Of course, this will make logging in more difficult. In plain English, we would say, "If both the password (A) is correct and security question # 1 is correct (B) and security question #2 (C) is correct, then allow the user to login.

The mathematical notation would look like this:
a ^ b ^ c
The caret (^) symbol is used to represent AND which is a conjunction.

The "Or" Operator

Note: For security purposes, condition A should always be true.

Now let's us imagine that we are the system administrator who sets up the security rules for the website. What if we wanted to require that only one security question be correct? This is where we would use the "OR" operator. To join these conditions we would require that A be always true and either B or C be true. In English, we would say, "If the password (A) is correct and either security question # 1 (B) or security question #2 is correct, then allow the user to sign in.

The mathematical notation for this scenario would be:
a ^ (b v c)
The (v) symbol is used to represent OR which is a disjunction.

And vs. Or Operators - Quiz

Use these variables to answer the following questions:

Let a = True
Let b = False
Let c = True

Answer True/False

Problem
(a v b)
Answer: True. Only one of the two variables has to be true.

Problem
(a v b v c)
Answer: True. Only one of the three variables have to be true.

Problem
(a ^ b)
Answer: False. Both variables would have to be either true or false.

Problem
(a ^ b ^ c)
Answer: False. All 3 variables would have to be either true or false.

Problem
(a ^ c)
Answer: True. Both variables are both true.


Exploring the Truth Table

Now that we understand the math notation, we can now summary the possible outcomes using a truth table.

a
b
a ^ b
a v b
True
True
True
True
True
False
False
True
False
True
False
True
False
False
False
False

Negation

An easy way to think of negation is to think in terms of opposite value. In plain English, it's like saying the word NOT.

The mathematical notation uses the tilde (~) symbol in front the variable to represent NOT. This truth table demonstrates negation.

a
~a
True
False
False
True

Sets

A set is simply a collection of things. So to visualize, we can think of a collection as a big box that can contain many values.

In the mathematical world of Set Theory, the syntax for a set looks as follows:

a = {1, 2, 3, 4, 5}

From this example we can see that variable A holds a list of numbers.

Math - Intersects

With intersects, only numbers existing in both sets become part of the merge. Here are some examples:

Example 1:

A = {1,2,3,4,5}

B = {1,3,7,8,9,10}

A ∩ B = {1,3}

In plain English, it is like saying, "Show me all items that exist in both A and B.

Example 2:

A = {1,2,3,4,5}

B = {7,8,9,10}

A ∩ B = ∅

Math - Unions

How do we combine two or more sets together? Easy, we union them. The math symbol for a union is υ . In programming, you will be working with all kinds of different sets. It's often necessary to bring two sets together.

Let's look at an example:

A = {1,2,3,4,5}
B = {5,6,7,8,9,10}
A υ B = {1,2,3,4,5,6,7,8,9,10}

In plain English, we would say join everything that exists in either A or B.

It's important to note that although both sets include a 5, only one 5 is recorded in the final set.


For more information on Sets and Venn Diagrams, I highly recommend going through the following mathisfun.com tutorial at: http://www.mathsisfun.com/sets/venn-diagrams.html

Math - Functions

What is a function? A great analogy I often hear is a function being like a vending machine. With a vending machine, a token goes in and the merchandise comes out. Similarly with a function, a variable (with an assigned a value) goes into the function and a resulting calculation comes out.

The math notation for a function is "f(x)" where "f" is the function name and within parenthesis is the variable:

f(x) = 2 + x + 5


One of the best ways to understand this concept is to see an examples:

Example A

Pass zero into the function

Step 1 - Replace variable a with 0
f(0) = 2(0) + 5

Step 2 - Simplify
f(0) = 0 + 5

Answer: f(0) = 5

Example B

Pass -5 into the function

Step 1
f(-5) = 2(-5) + 5

Step 2
f(-5) = -10 + 5

Answer: f(-5) = -5

Example C

Pass 10 into the function

Step 1
f(10) = 2(10) + 5

Step 2
f(10) = 20 + 5

Answer
f(10) = 25



Let's Start Programming!

In order to write a program, we will first need a programming language. An excellent language for beginners to dive into is called JavaScript. This is a simple, yet powerful, programming language that is extensively used by web developers to build rich interactive websites. Web browsers have their own built-in JavaScript interpreter. Think of this interpreter as a translator that can read our code and translate it into something meaningful that the user can work with.

One of the best tutorials on the web for learning this language is hosted for free by W3Schools. To get started, visit:

http://www.w3schools.com/js/default.asp

As you go through this tutorial you'll begin to understand how the math concepts we learned directly relate to programming. You now have a tremendous mathematical foundation that can be used to kick start your programming career and put you on the right path!

Note: If your not familiar with the HTML in this tutorial, I highly recommend going through this tutorial first:

http://www.w3schools.com/html/html_basic.asp

Also check out the tutorials on Code.org:

http://code.org/learn

What is your favorite programming language?

See results

© 2014 Isaac Ortiz

Comments

    0 of 8192 characters used
    Post Comment

    • Isaac Ortiz profile imageAUTHOR

      Isaac Ortiz 

      3 years ago from Olympia, Washington

      Anytime. Thank you also for visiting my Hub and sharing your feedback. I wish you all of the best in your programming endeavors!

    • Taranwanderer profile image

      Taranwanderer 

      3 years ago

      Excellent resource, Isaac - I'll certainly take a look at it! Thanks a bunch for taking the time

    • Isaac Ortiz profile imageAUTHOR

      Isaac Ortiz 

      3 years ago from Olympia, Washington

      I think JavaScript is a great language to start with. Apps written with HTML5/CSS/JavaScript are starting to take the world but storm. What's great is they are cross-platform and work on many different devices. Don't hesitate to start writing a program today in Java. Diving in is a great way to learn. Here is another great site that I know you'll enjoy: http://code.org/learn

    • Taranwanderer profile image

      Taranwanderer 

      3 years ago

      Wow - this is a heckuva pick-me-up lol. Thanks for responding, Isaac Ortiz. I think I will buy a few second-hand textbooks on college mathematics, and go through them side-by-side with html and css to start. Hopefully, within a year or two tops I can move on to Java and the rest. I'll definitely take a look at W3schools and try to spend an hour a day starting very soon. Thanks for responding.

    • Isaac Ortiz profile imageAUTHOR

      Isaac Ortiz 

      3 years ago from Olympia, Washington

      Taranwanderer, don't give up! With everything, it just takes practice. Go through some of the tutorials on W3schools, and you'll be surprised how far you go. Never let the math intimidate you. You actually can get started programming without any formal training in Algebra (just basic math)., however, knowing the math will give you a solid foundation and a great head start. Let me know if there are any math topics you would like me to elaborate on. Thanks for visiting my tutorial.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://hubpages.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)