≡ Menu

Programming 101 – The 5 Basic Concepts of any Programming Language

Programming 101 - the 5 fundamental elements of any programming languageFirst off, I’d like to say that I’m writing these preliminary posts in a way that I’ll assume you have very little knowledge in programming.  I want this content to provide anyone “walking in off the street” the knowledge to be able to write their first program with the Java programming language with as little pain as possible.

So, let’s get started with our first topic: The 5 basic concepts of any programming language.  You might say, “Why are we talking about any programming language?  I thought this was about Java”.  Well, I’ve found that it’s important to remember that a lot of programming languages are very similar, and knowing what’s common between all programming languages will help you transition into any other programming language if you need to!  For example, with the Java programming knowledge I had obtained, it took me less than a month to learn how to program in a language called Objective C (which is used for iPhone apps).  That’s powerful stuff!

Before we start learning: if you’re someone who also enjoys learning by watching videos, then I have the perfect deal for you. You can get access to over 50 hours of video tutorials (plus exercise files, assignments, quizzes and a private Facebook community of like minded programmers) for free for 30 days. You can click here to learn more about the Java courses.

So here are the 5 basic concepts of any programming language:

  1. Variables
  2. Control Structures
  3. Data Structures
  4. Syntax
  5. Tools

I recognize that these words probably look foreign to you, but don’t worry, I’ll do my very best at taking the mystery out of them.  Now, there’s a lot to say about each of these 5 concepts, so for today’s post I’ll only be talked about item #1, variables!

What is a variable?

Variables are the backbone of any program, and thus the backbone of any programming language. I like to start off by defining what we’re about to learn, so, Wiki defines a variable as follows:

In computer programming, a variable is a storage location and an associated symbolic name which contains some known or unknown quantity or information, a value.

Okay, well, that’s kind of cryptic.  To me, a variable is simply a way to store some sort of information for later use, and we can retrieve this information by referring to a “word” that will describe this information.

For example, let’s say you come to my website www.howtoprogramwithjava.com and the first thing I want to do, is ask you what your name is (so that I can greet you in a nice way the next time you visit my website).  I would put a little text box on the screen that asks you what your name is… that text box would represent a variable!  Let’s say I called that text box ‘yourName’, that would be the symbolic name (or “word”) for your variable (as described from our wiki definition above).

So now, when you type your name into the text box, that information would be stored in a variable called ‘yourName’.  I would then be able to come back and say “What value does the variable ‘yourName’ contain?”, and the program would tell me whatever it was your typed into that text box.

This concept is extremely powerful in programming and is used constantly.  It is what makes Facebook and Twitter work, it’s what makes paying your bills via your online bank work, it’s what allows you to place a bid on eBay.  Variables make the programming world go ’round.

Now, if we want to get more specific, when it comes to the Java programming language, variables have different types.  Brace yourself here, as I’m going to try to confuse you by explaining an important concept in three sentences. If I were to be storing your name in a variable, that type would be a String.  Or, let’s say I also wanted to store your age, that type would be stored as an Integer.  Or let’s say I wanted to store how much money you make in a year, that type would be stored as a Double.

What the heck are String, Integer and Double?

Excellent question!  In Java, the programming language wants to know what kind of information you are going to be storing in a variable.  This is because Java is a strongly typed language.  I could teach you about what the difference is between a strongly typed language and a weakly typed language, but that will likely bore you right now, so let’s just focus on what a type is in Java and why it’s important.

Typing in Java, allows the programming language to know with absolute certainty that the information being stored in a variable will be ‘a certain way’.  So like I said, if you’re storing your age, you would use the Integer type… well that’s because in Java, an Integer means you have a number that won’t have any decimal places in it.  It will be a whole number, like 5, or 20, or 60, or -60, or 4000, or -16000.  All of those numbers would be considered an Integer in Java.

So what would happen if you tried to store something that wasn’t an Integer, into an Integer variable, say for instance the value “$35.38”?  Well, quite simply, you would get an error in the program and you would have to fix it!  “$35.38” has a dollar sign ($) in it, as well as a decimal place with two digits of accuracy.  In Java, when you specify that a variable is of type Integer, you are simply not allowed to store anything except a whole number.

Specifying what kind of data that you are dealing with allows the programming language to use that data in interesting ways. Again, what I say “specifying what kind of data”, I’m just referring to the type of data.

Let’s dive into the power of assigning a type to your data.

What can you do with data types?

Let’s start with a simple example.

Your desire is to add two numbers together, let’s say the number 22 and the number 3. Java will behave differently depending on the type of the variable that’s storing this data.

Let me show you what I mean:

If you have defined your variables to be of type Integer, then adding 22 and 3 together will result in the Integer 25. Makes perfect sense right? Of course, this is simple Math.

But what happens if your variables are not Integers, but are Strings?

A String in Java is a different kind of data type and it behaves differently BECAUSE it is a different type of data.

When we refer to a String in Java (and in many other programming languages) we are treating the data like it’s just a plain old sentence in the English language. A String just represents words (or more specifically letters) all placed in a certain order. That’s all the English language (or any language) is, a series of characters/letters placed in a certain order to give meaning to what you’re writing down.

So now I ask you, what does it mean to add two sentences together? What does it mean to add two Strings together?

I’ll show you.

If you were to have two variables, each defined as Strings and they stored the data “22” and “3” (respectively), what would happen if we added them together?

We would get the String: “223”

This might be confusing at first, but it makes more sense when we use less “misleading” data.

Let’s assume that in our two String variables, we aren’t storing numbers, we’re storing words. So in variable 1 we store the String “Hello”, and in variable 2 we store the String “World”.

Now what happens in your mind if I tell you to add those two words together?

Hopefully your natural instinct is to say that the resulting String would be “Hello World”!

That’s all that’s happening with the Strings “22” and “3”… Java behaves differently because of the type of the variables.

To Java, the String “22” is the same type of data as the String “twenty-two”, they’re both characters arranged in a specific way.

Now I don’t want to go into too much detail about types, as this is better suited to programming basic concept #3 – Data Structures.  So that’s all I will touch on for now, but no worries, it will all make sense in time!

Want Free Access to my Best Java Courses?

Alright, so if you’re read this far down the article, then you’re clearly interested in learning how to code. You can currently get access to my 2 best courses on Java for free for 30 days (then it’s just $10/month afterwards, or $97/year).

When you sign up you’ll receive login information to start learning about Java. If you decide you don’t like the courses, you can cancel at any time. If you decide you love the courses then you don’t have to do anything and you can stay subscribed for as long as you like for just $10/month or $97/year.

It’s like Netflix for coders!

Go ahead an click the button below to get started!

So, to sum up, we talked about what a variable is and how you can store information in a variable and then retrieve that information at some later point in time.  The variable can have a name, and this name you give to the variable is usually named after the kind of content you’ll be storing in the variable, so if I’m storing your name in the variable, you’d name the variable ‘yourName’.  You wouldn’t HAVE to give it that name, you could name the variable “holyCrapImProgramming”, but that wouldn’t make a whole lot of sense considering you are trying to store a person’s name.  Makes sense right?  Finally, variables have types, and these types are used to help us organize what can and cannot be stored in the variable.  Hint: having a type will help to open up what kind of things we can do with the information inside the variable.  Example:  if you have two Integers (let’s say 50 and 32), you would be able to subtract one variable from the other (i.e 50 – 32 = 18), pretty straight forward right?  But, if you had two variables that stored names (i.e. “Trevor” and “Geoff”) it wouldn’t make sense to subtract one from the other (i.e.  “Trevor” – “Geoff”), because that just doesn’t mean anything!  So, types are also a powerful thing, and they help us to make sense of what we CAN do with our variables and what we CANNOT do!

So I hope this information has been helpful to you, and I hope you realize what the benefits of learning a programming language are! The allure to learning a programming language is quite high in today’s corporate world, as most companies are hiring programmers with the skills to create web applications. The programming profession is one that provides excellent pay and job stability, and in the end, isn’t that what we’re all looking for?

To dive even deeper into the subject, you can watch this video I’ve created on the topic of Variables:



Comments on this entry are closed.

  • hardikpatel July 13, 2012, 12:33 am

    helpfull site……….

    • Trevor Page July 13, 2012, 1:08 am

      Thanks Hardik, I’m glad you think so, this is a new site so keep checking in every week for new topics.

      • Fahad Munir October 10, 2012, 9:44 am


  • sonu July 14, 2012, 11:41 am

    excellent site……..

    • Javin August 26, 2012, 12:12 am

      I share same feeling, good stuff with clean layout. Thanks for your sharing your knowledge dude. Along with basics of programming, its also important to know basics of OOPS like Abstraction or Polymorphism; Which is I guess next step for any programmer.By the I have subscribed your blog now 🙂

      • Trevor Page August 26, 2012, 12:58 am

        Great stuff Javin,

        Nice to have another Java blogger in the neighbourhood 🙂

  • Mrigank ved July 18, 2012, 6:52 am

    Good explanation

  • sassirekha July 21, 2012, 6:21 am

    programs on concept of core java

  • jessiel cana July 21, 2012, 9:12 am

    nice explanation! keep it up1

  • Thathri July 22, 2012, 12:43 pm

    Thank You Master.

  • sapana July 26, 2012, 9:28 am

    it is easy to understand!!!

  • nive August 4, 2012, 12:26 pm

    i want some more information about java programming

    • Trevor Page August 6, 2012, 7:52 am

      Hi nive,

      I was just away on vacation and didn’t have time to write any new posts, but I’m going to sit down today and get one out for you guys, keep your eyes open for it, or sign up for my mailing list where i let you know when a new post is up.

      • ATAMA ALBERT March 13, 2013, 1:34 pm

        yes i am

  • kunj August 8, 2012, 5:02 pm

    very helpful site….
    Thank you.

  • manish August 9, 2012, 12:06 pm

    Hi, Today was my first class about this crap! I was sleeping there but its really helpful and good information for me. I am going to read all info. here.

    • Trevor Page August 10, 2012, 6:46 am

      Glad you were able to stumble upon my site, feel free to spread the word to your classmates if you think they’d benefit from it too 🙂

      Take care,


      • Bartholomew September 25, 2012, 9:30 am

        hello Page pls can you put me through in using java to send message.i have tried but my code is not sending message.ur help is welcome

        • Trevor Page September 25, 2012, 10:32 am

          I can absolutely help you out, but I will need a little more information. What do you mean when you say that you want to “send a message”. Are you trying to send an email? Are you trying to just output a message onto the console?

          Thanks for your comment 🙂


      • atama albert March 15, 2013, 1:32 pm

        i would wish that you sent me some your programes via my email

  • noobCoderSwag August 9, 2012, 1:23 pm

    Hi, I took a Java class last year and I’m about to take the 2nd level this year.
    Just wanted to let you know what a great of a site you have.
    I appreciate how you break things down using simple (human) language.
    I was the only one in my class who never had any experience with programming and felt so out of place and confused when the teacher would use computer science terms with us so loosely.
    This article is very valuable to people coming in with no knowledge of programming.
    Keep up the good work!

    And to all you newbies out there, don’t be afraid to take it slow.
    A solid understanding of fundamentals and much practice will take you far in the long run.

    • Trevor Page August 10, 2012, 6:48 am

      Thanks for your great comment… I’m here to help out, as I was a student who was completely lost as well! Feel free to shoot and questions my way if there’s anything you’re stuck on 🙂


  • mobiltelefon software aus dem Internet August 15, 2012, 2:33 am

    Great post.

  • Rayudu August 29, 2012, 2:21 am

    please send me what is the differnece between string and stringbuffer

  • Rayudu August 29, 2012, 2:22 am

    If u dont mine i want real time explnation on any project

    • Trevor Page August 29, 2012, 3:47 am

      Hey there,

      Thanks for the comment, bit i need you to be a little more specific. I don’t know what you want exactly.

  • hardi patel September 1, 2012, 1:54 am

    plz send me programs on concept of core java.

    • Trevor Page September 1, 2012, 8:18 am

      This entire blog contains programs with concepts of core Java, just read through my posts in order starting with this one 🙂

  • Abed September 6, 2012, 9:55 am

    i want to know more about java

    • Trevor Page September 7, 2012, 9:02 am

      Then by all means, keep going through the tutorials beyond this one 🙂 Let me know if you need any help understanding any of these concepts, or if you want me to cover something that I haven’t yet talked about, please do let me know.

  • acyl September 19, 2012, 8:12 am

    i am a newbie and is still taking java programming. We have to develop a game using java SE.. we are making a SPOT THE DIFFERENCE game.. just want to know more about the mouselistener and imageicon and the other tools we will be needing in developing this game.. and oh we only have about 3 weeks to finish it.. thanks in advance 😀

    • Trevor Page September 20, 2012, 9:05 am

      I assume you’re using Java AWT of Swing for the Graphical User Interface… is that correct?

  • Samyr Laine September 25, 2012, 9:20 am

    can i ask for codings in netbeans for binary calculator
    like adding of binary numbers, subtraction, multiplication and division.

    can someone knows that ?
    because we were having a project like that…

  • sahad September 26, 2012, 4:24 pm

    want to be a good programmer,how can i learn java perfectly?

    • Trevor Page September 26, 2012, 8:25 pm

      Hey Sahad,

      If you follow through all of my tutorials and download my podcast that would be a good start to understanding the core concepts of programming in Java. Make sure you download an IDE and install it to create your programs (that info is in part 5 of this series entitled “tools”).

      The most important thing is to stay focused and not to get too frustrated. If you do ever get stuck, just leave a comment here and I’ll be glad to help you out!

  • Arbiter September 27, 2012, 8:36 pm

    I need your help !… ive got a java test in school with nested if on monday… I am totally confused!
    i Actually dont know how to proggram with nested if,when it is used and stuff.


  • lyn September 28, 2012, 9:59 am

    hi im new here.. i hope this site could help me doing a java source code.
    i mean thanks for this site .

  • lyn September 28, 2012, 10:08 am

    could you pls help me doing a joption pane using a dialog box,,?its like doing “year entry level”
    and need to appears a freshmen,sophomore,junior,senior… its like that code? i am very anxious to find out..

    • Trevor Page September 28, 2012, 11:24 am

      Hi There,

      I don’t actually have much experience with Java UI, as I feel like it’s a bit of a wasted effort to learn, as modern Java applications these days are either Mobile Apps or Web Apps (which don’t use Java UI technologies such as Swing/AWT)

      I did write a post about Java UI where I reference some training materials here

  • mohammed October 5, 2012, 4:35 pm


  • barkat October 21, 2012, 7:38 am

    i want learn java&other language pleas help me

    • Trevor Page October 22, 2012, 7:19 am

      That’s what this blog is all about. This will teach you Java. My eBook is also a great resource for learning Java: http://javapdf.org.

  • JOSIP November 12, 2012, 12:53 pm

    zdravo potrebna mi je java runtime na mobitelu htc hd mini,zelim je skinuti kako bih mogao gledati filmove preko interneta,ali nikako da je skinem,pa mozete li mi pomoci ikako?

    • Trevor Page November 13, 2012, 11:59 am

      I don’t actually have any experience with installing the java runtime environment on a mobile device. The only mobile programming stuff I could point you to, is Android development resources. But as you didn’t post in English, I can only guess at what your exact problem is. So, if you do have an android operating system on your phone, and you’re looking to create an application to help you to watch movies on the internet, then I’m sure you could create an application to do so on your phone using an Android app.

      But again, I’m not positive on what it is you need.

  • jerry November 16, 2012, 2:21 am

    The first time I downloaded your podcast and listened to it, the first thing i did upon opening my ipod was to download all the remaining episodes and check your website as well. Keep it up Trevor! =)

    • Trevor Page November 16, 2012, 11:08 am

      Happy to be of service Jerry, enjoy your learning and feel free to ask any questions here if you get stuck 🙂

  • Elyot November 24, 2012, 6:31 am

    this is de best tutorial i’ve ever read. Good job 🙂

    • Trevor Page November 24, 2012, 9:44 am

      Thanks Elyot, I think a lot of the other readers here would agree with you, and there’s plenty more available here! I hope you learn tons!

  • mukesh December 9, 2012, 6:13 am

    very usefull website

  • arfa December 16, 2012, 7:34 am

    how can we run java program in program always occur error

    • Trevor Page December 16, 2012, 12:44 pm

      You’ll have to re-phrase your question and be more specific, I don’t understand what you’re asking.

  • parast January 4, 2013, 4:27 pm


    I have to write a program which draw contour plot(level curves) for every f(x,y) = z but i do not know how to determine x and y to draw the curves?

    Thank in advance

    • Trevor Page January 4, 2013, 7:56 pm

      Sorry, I really don’t understand what you need to accomplish, do you have more details than just that?

  • kazim ali korejo January 13, 2013, 3:48 pm

    hello I,m new. so plz tell me about scop of java?

    • Trevor Page January 13, 2013, 10:03 pm

      Can you elaborate a little about what you mean by the scope of Java? Do you mean, where is Java used? If so, then Java is used in web applications, mobile phones (android and blackberry) as well as desktop applications.

  • lucia January 13, 2013, 11:00 pm

    hi… this is my first time to see or visite,, it’s nice to read coz i leard something about this topic but what i want is example.

  • shital January 16, 2013, 4:54 am

    i want the program on how to make connetion between java and database like sql or ms access with what are setting made before actual code is wriiten. i want small snap short pictures of those setting . can you give me small project like simple hotel management system , with different window , coding and picks of setting .

    • Trevor Page January 16, 2013, 7:42 am

      I think what you’re asking for is the way to setup a database server on your computer, if that’s true then watch this 15 minute video I made about just that topic: http://youtu.be/DQUlyZAuJww

  • desta January 21, 2013, 2:56 pm


    • Trevor Page January 21, 2013, 6:53 pm


      I really can’t help you there unless you give me some more information. “Calculates the weekly class schedule” means nothing to me unfortuantely.

  • simple January 23, 2013, 1:27 am

    hello…. i need a help…
    1. I want to learn how to connect NETBEAN ant XAMPP …
    2. can u help me how to create web site….

  • mini January 30, 2013, 10:53 am

    m very hapi that u hav explain it in very
    easy way…n can u explain me y we use try ;
    Catch; and finally block in java…..plez help me

  • yohima February 3, 2013, 12:29 pm

    u hav good information please could you provide me with information about void and class methods

  • About Java February 11, 2013, 7:28 am

    im beginner to java programming language.. awesome tutorial.. thanks for sharing.. 🙂

  • Marilyn February 12, 2013, 10:48 am

    Trevor – I just learned about this site listening to your interview with Pat Flynn. I’m a former college professor (and really an “ex” programmer since I now mostly hire others to do it) who helps people commercialize technology. And mostly I just wanted to tell you that you are, indeed, a natural at teaching! Or maybe it’s just that I like using the same style – starting with those things that apply across disciplines. You are an inspiration on how to set up a website for teaching. Well done!

    • Trevor Page February 12, 2013, 10:54 am


      I’m completely humbled by your comment. It’s one thing for me to think that I’m a decent teacher, and it’s another to have other programming enthusiasts say that I’m a decent teacher… but it’s an entirely different thing (in my opinion) to have a former College professor tell me I’m a natural.

      My sincere thanks for taking the time to leave that comment, it means a lot to me!

      Take care Marilyn

  • khalid almalki February 23, 2013, 1:23 pm

    excellent site i’m really lucky man when i found this site everything is perfect

  • Mr.blue March 21, 2013, 3:24 am

    could you provide us some clear example programs about data abstraction,throw and catch .