You are on page 1of 10

INTRODUCTION TO JAVA

FOR ANDROID DEVELOPMENT


Lesson 1.02 Programming Basics

For New Programmers


If you're completely new to programming, the following presentation will help you get a handle on the
terminology, and basics of programming.
We'll talk about:
Misconceptions There are a number of misconceptions when it comes to programming. Let's
clear these up.
What is an application? While most of us know what an application is from a user's perspective,
let's define it from a programming perspective as well.
Code execution Let's outline what the code does in general, and how it runs.
Logic Our apps are able to make decisions. How do they achieve this?

Can Anyone Learn to Program?


Programming is something that anyone can learn. It isn't difficult to do so, but like everything else
worth learning, requires patience, dedication, and practice.
Imagine that you've just got the news that you'll be moving to a foreign country. One of the first things
you'll do is start to learn the language of that country so you can effectively communicate when you
get there. It may take you weeks to get the basics down, and if you stick with it, in several months
time you'll be able to hold your own, although you'll still make mistakes and may not be able to fully
understand everything. Once you get to this new country, it may take you six months to a year to be
more fluent and comfortable with the new language.
The same thing applies to learning a programming language. You must find the time to work on it,
and continue to practice in order to get better at it. However, while a foreign language requires you
to learn how to read, write, speak and pronounce correctly, learning to program requires you to only
be able to write it, and read it back with understanding. Overall, it is much easier to learn to program
than to learn a foreign language, if you ask me.

Programming Requires College


Many people are under the impression that in order to learn to program, one must attend a formal
computer science curriculum for a number of years. While there are numerous benefits to a college
education, everything you need to learn to write top notch applications is also available outside of
that medium.
Some benefits of learning to program on your own include:
Learn at your own pace. Repeat what you didn't get, until you understand it.
Real-life experience. Text book examples are rarely useful examples of how you would use an
application to solve a problem. By working on your own, you're able to apply your programming
knowledge to your needs and your real-life observations.
Out of the box thinkers. Colleges tend to force students towards using specific guidelines and rules
when it comes to programming. While this isn't a bad thing per se, it does limit your possible set of
solutions for a given problem.

Programming Requires Math


You do not need to be a mathematician in order to write great applications. Math is used in
programming, but not to the extent you might think. Math becomes more important when you start
to work on games and 3D/2D graphics, but for the majority of the work that you'll be doing, nothing
beyond basic mathematic skills is required.

Experience
Experience is important to being able to write applications. I've said this before, and I'll say it again
walk before you can run. Don't start out working on an application that is beyond your current
abilities. Instead, work towards it. Solve smaller problems, and gain the experience you need.
Eventually, that killer application inside your head will become a reality.

Applications
We certainly know what an application is from a user's perspective. We use them every day to check
our email, to write documents, to create spreadsheets, to design graphics, and many, many other
tasks.
We can define an application as something that runs on a computer's operating system, and performs
one or more related tasks. I use the term "computer" loosely here, as that can represent just about
anything with a processor and an operating system. I also want to point out that many applications
do not directly interact with the user, yet still meet this definition.
From a programming perspective, we can define an application as a set of instructions for the
computer that help solve a problem. The problem may be as general as "I need to write a letter", or
as precise as "calculate PI to the 120th decimal".

Writing Applications
Writing an application is a lot like putting together a jig-saw puzzle. There are many pieces, all of
which must fit together properly, and it's not done until all of those pieces are in place.
Unlike a jig-saw puzzle, however, the programming pieces are "re-usable", and fit multiple times into
the same jig-saw puzzle. We call those re-usable pieces "classes", or "objects", and they shape the
basis of "Object Oriented Programming".
You work on creating the individual pieces first, then combine them together to make your
application.

Code Execution
Your code executes linearly, from top to bottom, left to right. For the most part, each line of code
represents a single statement, which performs a single action. You can combine multiple statements
into blocks of code, and identify those blocks by a name. This is known as a "function" or a "method".
Code is not dynamic and will perform the same set of steps each time it is executed. Code is able to
branch out to other code sections of your application, but always returns back to where it branched
off from. The code you write must handle all possible branching scenarios.

Method
A
Main
Code
Method
C

Method
B

Logic
Your application can make decisions through evaluation of conditions. Those conditions must always
resolve to being either true or false.
Any logic that you are going to implement in your application, must be broken down into simple
statements, and if the application has to make a decision as to which piece of code to run, it must do
so based on a true / false condition.
Example Programming a stop light (pseudo code)
1 wait 15 seconds
2 if light = red then light = green
3 if light = yellow then light = red
4 if light = green then light = yellow
5 go back to step 1
All computer code must be broken down into these types of simple statements, regardless of what
programming language you're planning to use to write your application in.

You might also like