Welcome back to our fourth lesson in our five part series on the 5 basic concepts of any programming language.  Today’s concept is syntax.

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

 
What is syntax?  As always, let’s hop over to wiki for a quick definition:

In computer science, the syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be correctly structured programs in that language.

Alright, so I would say that’s almost English, but what do they mean by “combinations of symbols that are correctly structured”?  Well, I would choose a different word than symbols.  I would define syntax to be a particular layout of words and symbols.  An example of this in the case of Java would be round brackets (), curly brackets {}, and variables, among other things.  Think of it like this, when you look at an email address (i.e. john.smith@company.com), you can immediately identify the fact that it’s an email address right?  So why is that?  Why does your brain make the connection that it’s an email address, and not, say, a website address?  Well, it’s because an email address has a particular syntax.  You need some combination of letters and numbers, potentially with underscores (_) or periods (.) in between, followed by an at (@) symbol, followed by a website domain (company.com)  That is a defined combination of letters and symbols that are considered correct structure in the “language” of the internet and email addresses.  So, syntax in a programming language is much the same, there are a set of rules that are in place, which when you follow them, allows your programming language to understand you and allow you to create some piece of functioning software.  But, if you don’t abide by the rules of a programming languages’ syntax, you’ll get errors 🙁

How about an example of syntax in Java?  Well you’ve seen it already back when we talked about variables and control structures.  To define a variable in Java, you need to do this:

String helloVariable = "Hello Everyone!";

There are four parts to the syntax of creating a variable in Java.  The first is the word String, this is the variable’s type.  Remember when we talked about variable types in the first part of this series?  I mentioned String, Integer and Double, three different variable types that allow you to store three different kinds of data.  A String in this case, allows you to store regular letters and special characters.  The second part to this variable creation syntax is the variable name, in this case I arbitrarily chose helloVariable.  I could have just as easily chosen holyCowThisIsAVariableName.  Variable names can be made up of letters and numbers, but the only special characters they can contain are underscores (_).  They also usually start with a lower case letter, they don’t have to, but that’s kind of an accepted and suggested convention (at least in the Java world).  The third part of the syntax for creating a variable is the value that the variable will hold.  In this case, we have a String variable, so we have the value "Hello Everyone!".  In java, Strings are defined by wrapping regular letters/numbers/special characters in quotes (” “).  Again, that’s just the syntax that Java uses.  The last part of this syntax, is the part that marks this particular code segment as being complete.  In Java, we use the semi-colon (;) to mark a part of our code as complete.  You will see that almost every line of code in Java will end with a semi-colon (;).  There are certain exceptions to this, for example control structures aren’t marked with semi-colons, as they use curly braces to make their beginning and end.  Think of it like putting a period at the end of every sentence.  If we didn’t put a period, we would just have one long unstructured run on sentence, and that wouldn’t help us to understand anything that’s being said.

So, as I mentioned before, the syntax of any programming language will likely be your biggest hurdle as a new developer, but as you see more and more examples of code and are introduced to more and more syntax in the language, you will become comfortable.  There is good news though, as people have realized that dealing with syntax can be tough, so certain companies (or groups of enthusiasts, a.k.a nerds) have created tools to help us with the syntax of programming languages.  These tools are called IDEs, or, Integrated Development Environments, which you can download onto your computer and use to create programs.  These IDEs have built in syntax checkers (much like the grammar checker in MS Word) that will let you know if your syntax is incorrect, and will even give you hints with what it thinks you meant to put!  So don’t you worry, I’ll cover those tools in the next section of this 5 part series.

The Best 7 Java Programming Resources

Alright, so if you’re read this far down the article, then you’re clearly interested in learning how to code. We actually have a free guide that outlines the best 7 resources for Java programmers.

When you sign up you’ll receive the guide immediately and you’ll also receive a few emails a week that will help you speed up your Java learning process so you can get up and running as fast as possible.

Go ahead an click the button below to get started!

CAREFUL! Don’t Push This Button If You’re Not Ready To FINALLY Learn How to Code

So, let’s sum up.  In today’s post, we have learned that syntax just means that there’s a “correct” way to write down your code, and that this allows the programming language understand what it is that you’re trying to tell it to do.  Unfortunately for us, computer’s can’t read our minds (yet!) and know what it is that we want them to do, so some very smart people have created this “computer language” that, when understood by programmers, allows us to tell the computer what actions we would like it to carry out… whether that action be to send a bill payment to our credit card company, or to play a game of poker online with a virtual table full of strangers.  Syntax is our systematic way to talk to a computer and convey our wishes.

I hope I have taken a little bit of mystery out of the term syntax, and I look forward to teaching you about our final subject… tools!  A developer’s best friend 🙂

Plenty of Ways to Learn

  • COMMUNITY – Learning with a community is the best way to ensure accountability and support when you need help. Coders’ Campus is a brand new community that is dedicated to new programmers like you!
  • BLOGS – If you feel like you enjoy the way this information is laid out in blog format, then I invite you to click on the “next” button below.
  • BOOKS – If you feel like you are better at learning from a book, then I invite you to check out my ebook via http://javapdf.org. This eBook is organized, and packed full of easy to follow tutorials and videos.
  • PODCASTS – Finally, if you prefer to learn by just listening, then there’s also a podcast available on iTunes via How to Program with Java Podcast.

Free Java Beginners Course

Start learning how to code today with our free beginners course. Learn more.

Thank you for your message. It has been sent.
There was an error trying to send your message. Please try again later.