Table of Contents
Java is a good programming language for beginners
Java is fairly easy for beginners to get started with. And we believe this is in part due to it’s fairly straight forward, clear-cut and easy syntax, good documentation and clear error presentation.
And since it’s one of the oldest high-level programming languages we have, there are plenty of good material to learn from!
With this website we aim to provide a resource that makes it easy to get started programming with Java and provide test projects, valuable links and resources, video tutorials, code examples, a help forum and much more. All available in one and the same place!
Our goal is to provide a complete tutorial that covers everything a beginner could be interested in learning when it comes to getting started with Java programming.
In earlier articles we touched on what .java files are, how packages in Java are to be used as well as what Java classes are. We also briefly discussed the Main-method in Java.
So for this article we will take a more in-depth look at these areas as well as focus on looking at what makes Java different more specifically compared to other programming languages in more detail, as well as what you can do with Java.
We will also be looking at good coding praxises for Java as well as go into detail of how debugging is done and introduce you to so called “pseudocoding” to help visualize how your code will work and give some words of wisdom when it comes to how to learn Java most efficiently when starting out.
What makes Java different from other programming languages?
Here we will point out a a few differences that we’ve noticed from trying various programming languages – if you feel there is more worth mentioning, don’t hesitate to get in touch :)
Strictly (strong) typed vs. Loosely (weak) typed programming language
Java is a strictly typed programming language, where you have to code things in a very restricted way for them to work – compared to loosely-typed programming languages where 50 different ways of typing might be “acceptable” to accomplish the same thing.
Strictly (strong) typed programming language
Strictly (strong) typed programming languages makes it easier (in my opinion) to write the code, because there are only so many ways that will work without throwing off errors. Also the strict typing of the language helps to make the code clearer and easier to understand for others that might be looking at your code. As well as for yourself – if you come back to a program developed in Java, years after you coded it and might’ve forgotten details about it.
Strictly typed languages can also be helpful when debugging and trying to find and correcting errors, since there are only so many ways the code is accepted to get it to work.
Loosely (weak) typed programming language
Loosely typed programming languages makes it easy to create very messy code because there are so many ways one could get “acceptable” code.
Loosely typed programming languages have a tendency to allow omitting (leaving out) parts of the code that makes it clearer to read and understand for both code interpreters (compilers) as well as humans.
JavaScript is an example of a loosely typed programming language.
Automatic Garbage collection in Java
Java has automatic Garbage collection, which was mentioned in our Introduction to Programming article, compared to C++ for example where instead you have to do manual Garbage collection.
Automatic garbage collection saves time at the cost of losing a bit of control when it comes to what performance is available at any given moment in the program.
But it’s great for beginners just starting out learning programming because it’s one less thing to worry about, and allows more focus to fall on the actual logic of getting your programs to work!
One program to work with all operating systems in Java thanks to JVM
Java runs all of it’s programs inside of the JVM (Java Virtual Machine), which was also discussed shortly in our Introduction to Programming article earlier.
With JVM you simply develop one single program that can work on multiple platforms/operating systems.
Whilst in other languages that don’t execute their code inside of a virtual environment you might end up having to do customizations for each and every operating system just to have their program be compatible – because of the differences between all of the various operating systems.
To paint a clearer picture for this conundrum, imagine developing Android applications, and you wish to use a specific feature that was released in version 5.X. That means you probably have to do customizations for the lower versions to make your Android application be compatible with these versions as well – if that is something you consider worth your while that is.
This means that the programs you develop in Java have a very wide area of application, you can build Java applications for the Web, Embedded systems, Android, Cars, and more.
It’s pretty nice to be able to develop one solid program that will work on multiple systems right off the bat. Saves a lot of time too – imagine having to develop multiple versions of your program just to suit all the different operating systems and platforms the program need to run on. Been there, done that, it’s a pain to say the least.
Examples of what can be done with Java programming
Since Java programs are run in a virtual environment, making them compatible with most- if not all operating systems/platforms there are virtually endless possibilities of what can be done with Java programming.
Develop Android applications with Java
One of the most popular Java applications of late I imagine, is the development of Android applications. Since Android itself was developed using Java it only makes sense that the applications for the operating system is also coded using Java. This of course also means that you can develop operating systems using Java :)
If you wish to learn more about Android application development, see our Appendix where you can find the material you need to get started :) Although we recommend you to first read through the articles leading up to the Appendix to get a good understanding of Java before delving deeper into Android application development!
Developing for embedded systems with Java
Before smartphones though, a lot of embedded systems were developed using Java, so don’t be surprised if you find bank systems, ATM machines, car interfaces, medical equipment, interactive billboards and much more – that is developed using Java programming language.
.java Files and Java classes explained
A .java file is also known as a “class file” and contains the code that will make up your program.
A class in programming is a way of structuring data, a concept that allows for a structured development practice, a blueprint if you will.
Classes allows you to organize your code in logical objects and relationships that make a program clearer and also makes it easier for you down the road when it comes to extending (scale) your program or doing code maintenance (refactoring).
You could think of a class like a schematic where you can have variables that keep track of various attributes – and methods that contain functionality that can be accomplished using a certain class.
The concept of classes can be thought of as objects and relationships. Think of a car for example – a car can have:
- a color
- a topSpeed
- “x” amount of seats
- it can be of a certain type (cabriolet for example)
- and it can be of a certain brand
There you have a couple of attributes that could be represented using variables in a class (variables that belong to a class are usually called “member variables” in Java).
Then the car could:
- accelerate
- break
- turn
- goReverse
These are excellent examples of methods for the perverbial Car class that represents a Cars functionality.
The concept of coding with classes is known as Object oriented programming (OOP) and is supported by a lot of different programming languages out there.
Classes can also be structured hierarchically such as a main class could be a general schematic for all Cars, while subclasses exist for different Types of Cars – say Cabriolet might differ in both attributes and functionality from a default car which could be best described in a subclass that inherits all attributes and functionality from its parent class and then can extend or complement these attributes and functionality.
But Object oriented programming is a more advanced subject of programming and more information about this if you are curious to learn more about it can be found in our later articles (part XI).
For a demonstration of object oriented programming, look at our coded demo class of Car below:
A rule in Java is to always name ClassNames with a capital letter in the beginning to make it easier to distinguish classes from functions (methods) and variables in programs when called upon and used
public class Car { private String color; private int topSpeed; private int amountOfSeats; private String carType; //Class constructor - this "method" is used to create objects of this class every time a program creates an instance of this class that can be used in that program public Car(String carColor, int maxSpeed, int seats, String type) { //Setting class attributes values when an "object" of the class is created in a program via the class constructor this.color = carColor; this.topSpeed = maxSpeed; this.amountOfSeats = seats; this.carType = type; } //Class functionality public void accelerate() { } public void break() { } public void goReverse() { } public void turn(String direction) { if(direction == "right") { //turn right }else if(direction == "left") { //turn left } } }
The Main-method in Java explained
Every runnable Java program needs to have a so called “Main-method”. The main-method looks like this in Java:
public static void main(String[] args) {
// Place your code here :)
}
This is the method called when you run a Java program. So anything that pertains to your program running should be placed inside of this method.
12 Good Java Coding Praxises/Guidelines
#1 Managing expectations and unpredictable user input to ensure working program logic as intended
A good praxis is to always check what value you have when in your program – especially if you are using user-generated values that you get as user input. In these cases you might need to validate that the data the user inputted actually is the data you expected to get from the user!
As an example imagine you have developed a banking application and ask for a sum money (a number) to be deposited from the user, and they instead enter a text – if you don’t have safeguards in place to deal with these issues it can – and often will – result in a crash of your program(!).
To deal with these types of scenarios you could (and should) make sure to check the data the user inputted after your program receives the data.
Java has multiple good ways of verifying that the data and values actually are what you expect them to be, and if they are not – reset the process of getting user input while informing the user what went wrong so they don’t get confused and the program flow can continue as if nothing happened.
#2 Make use of indentation for more human-readable and better structured code
Indentation is important in programming, not only does it help indicate what code belongs where in a program, but it also improves the human-readability of the code which makes it easier to follow along when coding – both for you who write the code but also for those who might be interested in your code.
Sharing is caring.
– Learning from others is a natural part of the programmers journey.
For an example of indentation in action vs. not, see below:
// Indentation example: for(int i = 0; i < 5; i++) { if(i == 1) { // Do something }else if(i > 1) { // Do something else }else { // And something else again } } // Without indentation example: for(int i = 0; i < 5; i++) { if(i == 1) { // Do something }else if(i > 1) { // Do something else }else { // And something else again } }
Can you see the difference? Without indentation it is way harder to read and understand what code belongs to what statement, its also in general way more messy and uncomprehensible for us humans.
Indentation also makes it easier to track the brackets that belong to which statement, which can be very useful when debugging since a lot of errors can stem from having missed a bracket somewhere, easier then to detect if they make up a predictable and symmetrical pattern with the help of indentation.
Auto-formatting hotkey in IDE such as Eclipse
Some Integrated Development Environments (IDE’s) such as Eclipse usually have built-in features and hotkeys that help you to auto-format the code (CTRL + SHIFT + F – alternatively click Format in main menu and then Source) to have “proper” indentation if you might have forgotten it at some places while coding (good praxis is to NOT forget to indent – saves time in the long run).
One thing to keep in mind though, is that with everything in life – repetitively doing a good habit – such as doing indentation manually when programming, will help keep the habit alive, whilst using the hotkey, might make the habit disappear and you forget (if you’re just starting out with programming this is more likely).
Sure it saves time, but its also not that hard to just remember doing it while writing the actual code in the first place :)
What is – and how to create indentation when programming
Indentation when programming often consist of [TAB]’s – some people prefer spaces, but usually its faster to simply use the TAB-key on your keyboard. 1 TAB in some editor can via settings be configured for how many spaces it should consist of, I believe default is around 3-4 spaces in some of the popular code editors.
#3 Proper Java naming conventions explained
There are a few things to consider when choosing names for your variables and functions/methods in Java.
Descriptive variable names in Java
When you choose a variable name, make sure its “descriptive” meaning its self-documented so that anyone who is not familiar with your code since before, and starts to get familiar with it, will instantly have a good idea what each and every variable as well as function name does and represents!
A practical example of this would be a variable to hold the cost of groceries in a store:
double groceriesCost = 0;
It’s pretty clear above variable is intended to store the cost for our groceries, right?
This is what I mean by self-documented – or self-explanatory if you will.
The variable name is descriptive of its purpose and therefore both easy to understand for an outsider as well as help with your own understanding of what is happening at each and every turn in your program.
camelCase and PascalCase explained in detail
So when it comes to naming conventions in Java, two methods are popular: camelCase and PascalCase.
camelCase explained
camelCase as you probably have figured out by now is the naming convention where first letter always will be lower-case, then for every following word that is part of the variable and/or function name first letter of that new word should be capitalized.
As a practical example:
// Variable name with camelCasing int thisIsMyVariable = 0; // Function name with camelCasing runProgram();
See how each new word following the first intial word have a capital first letter? This is camelCasing.
camelCasing is used in Java for functions/method names as well as variable names (with the exception of constant Java variables).
PascalCase explained
So when it comes to PascalCase, as you probably can tell – the difference compared to camelCasing is that with so called “PascalCase” the intial first letter IS capitalized.
PascalCase is used in Java for Class names and interface names.
As a practical example:
class ImageCompressor {}
ALL UPPERCASE constants in Java explained
In Java there is a variable type called “constants” – these variables are created only when you are sure a variable will never be changed in your program.
You can think of constants in Java as in mathematics compared to mathematical algebraic variables. A constant in mathematics is a fixed number/value that you have and know, whilst algebraic variables are usually represented by letters and often unknown until calculated. It’s the exact same in Java!
Variables in general can hold values that can change during your program whilst constant variables hold values that cannot and will not change during your program.
To differentiate constant variables in Java from all other variables, a common naming convention has become to name constant variables with ALL-UPPERCASE letters separated with Underscores (_).
An additional added bonus for constants in Java is that they can help increase performance of your program by caching the stored values, more about this in later sections :)
A practical example of a Java constant can be seen below:
int THIS_IS_MY_NUMBER_CONSTANT = 9;
#4 Document your code in Java
Documenting code is very important, both for you and your future self, as well as to others who might share an interest in the code you write.
For simpler “note to self” that help the understanding of the code, one-line comments can suffice:
// This is a one-line comment, supposed to be short and concise
If you feel you need a multi-line comment you can use the following Javas syntax to create those:
/*
This
is
a
multi-line
comment
*/
But when documenting in a more “official” capacity, such as reusable functions/methods Java, you should use Javas Documentation comment syntax:
/**
* So this is a documentation comment, usually with description of the function at the top
* @param myFirstNumber - A first number to use for addition
* @param mySecondNumber - A second number to use for addition
* @return sum - The sum of our addition
*/
public int function sumMyNumbers(int myFirstNumber, int mySecondNumber) {
int sum = 0;
sum = myFirstNumber + mySecondNumber;
return sum;
}
These Java documentation comments as you can tell from above example can also have special formatting that later can be read by tools such as JavaDoc to get an easy overview over classes and programs without having to analyze the entire code in detail.
In the above example you will see that the first line of our Java documentation comment describes the purpose of the function/method whilst the following rows make use of @param which is a variable that can later be read by JavaDoc tool to tell a user more about input parameters for functions/methods, and @return which JavaDoc tool can use to tell users the return to be expected from the function/method.
Notice also how the Java documentation comment starts off with 2 stars right after the slash (/) instead of 1x star such as the multi-line comment.
Our function/method in above example is an addition function/method that will return the sum of the addition of two integer number values.
Every function should have a comment that explains its purpose and what it does.
#5 “Magic numbers” explained and why you should avoid them when coding
The concept “Magic numbers” refer to when actual numbers and values are used WITHOUT using variables to explain what the numbers and values represent. This makes it not only hard to sometimes (especially for outsiders) to understand the code, but also makes it more difficult to maintain the program code in the long run.
Imagine you are coding a program to loop through a list of values where you know from the beginning that the list always will have 15 values that need to be looped through.
If you’re coding “fast and loose” you might code it as follows:
for(int i = 0; i < 15; i++) {
// Do something with each value we loop through
}
Notice how we coded 15 as a pure numerical value in the middle of our loop-condition in the code above.
This is what a “Magic number” is. There are multiple reasons why this might be considered a BAD praxis – one of them are that since this is a known value that will be used throughout the program – odds are you will need to use 15 multiple times throughout your code on multiple different places.
Why is this bad then? Well, if you have the numeric value 15 multiple times throughout your code, and it turns out at some point that your program needs to be changed and you suddenly need this value to be 20 instead of 15, then you suddenly have to change EVERYWHERE where you used the value 15 for this purpose.
But not only does it make for code that is difficult to maintain, but if you have been away from your code for a long time, or you ask an outsider to take a look at your code – chances are the numerical values in the middle of the code will make it more difficult for them to understand what exactly that particular number refers to.
So what can be done to avoid “Magic numbers” then?
Well, if you know its a “constant” value that won’t change, and might need to be referred to on multiple occasions throughout your code, you could create a Java constant variable to hold the value, which also can have a descriptive name to help with understanding and also contribute to making the code easier to maintain and clearer to understand in general!
int LIST_VALUES = 15;
See below example of how this compares to above code example with clearer and more descriptive code:
for(int i = 0; i < LIST_VALUES; i++) { // Do something with each value we loop through }
When it comes to amount of values contained within a list, lits in Java usually contain a method or variable that can be referenced to get the length of the list, which also can be used instead of the numerical value 15, or the Java constant LIST_VALUES
.
#6 Avoid using break and continue statements at all cost in Java – makes for bad code
Switch-statements might be the exception to the rule where breaks are concerned, but except for this, try to avoid using both continue and break when coding.
Usually there are smarter and better ways available to write code that does exactly the same as you intended to accomplish with break and continue.
You can read more about why and when using break and continue is bad in Java here.
#7 Guideline for optimal method size/length in Java
A common recommendation is to try and keep stand-alone functions/methods restricted to a maximum of 30 lines of code.
This guideline is simply to help “break up” more complex functions/methods into multiple more easily manageable smaller functions/methods – instead of one huge barely comprehensible function/method.
#8 Avoid defining multiple variables on the same line in Java
This is because multiple variables defined on the same line makes it harder to analyze the code and get a general overview of everything.
#9 Use braces {} for code blocks in Java – makes for better readability
I recommend using braces when coding in Java, this is mainly because it makes the code more easily readable, but it also helps to avoid confusion which can arise sometimes when braces have been skipped and indentation might not be 100% proper.
I try to make it a habit to avoid skipping braces since then I don’t have to worry about maybe confusing myself and spending countless hours trying to locate the simplest of errors.
Lining up braces {} in various ways in Java
This usually comes down to personal preference of what you think looks easier to understand and interpret when looking at your code. I will demonstrate below two different styles of lining up braces in Java.
// Option 1:
if(true) {
// Do something
}
// Option 2:
if(true)
{
//Do something
}
Notice how in the first option the initial bracket comes immediately after the if-statement condition, whilst in option #2 it starts at the next line.
I personally used to code using option 2 when starting out quite a bit – especially for for-loops and if-statements, although I used option #1 for functions/methods and classes.
Lately however I tend to use option #1 more, if you look in the above example you will also notice that option #1 saves 1x Line of code, compared to option #2. Now imagine a larger coding project, those 1-liners might add up to a significant amount of extra lines of code, which might in turn increase the file size and thereby perhaps also affect system performance when running your program. Food for thought :)
As a contrast to this however, using Option #2 it might be easier to debug checking if all brackets are where they are supposed to be.
#10 Java files should also have JavaDoc comments documenting purpose, author, version
A good praxis could be to always use Java documentation comments in the beginning of class (java) files explaining the purpose of a class (java) file, as well as the author/coder and the version of the file (perhaps even document date of creation and last edit if you’re feeling ambitious).
#11 Don’t underestimate whitespace when it comes to readability – But don’t overdo it!
What I’m trying to say here is to not be cheap with the use of whitespace at the cost of readability.
This doesn’t mean you should have tons of purposeless whitespaces and linebreaks in your code, but instead maybe separate different statements with linebreaks inbetween to make it easier and quicker to get an overview of the code.
Same goes for same-line code, don’t be cheap with whitespace when declaring variables, assigning values to variables, adding input parameters to functions, creating functions, conditional statements, etc.
See a few examples below:
// A good example of variable declaration:
int aVariable = 10;
// A bad example of variable declaration:
int aVariable=10;
// A good example of variable assignment:
aVariable = 5 + 10 + 15;
// A bad example of variable assignment:
aVariable=5+10+15;
// A good example of a different variable declaration & initalization:
String aString = "this is text";
// A bad example of a different variable declaration & initalization:
String aString="this is text";
// A good example of string concatenation:
aString = "this is text" + " another part of the text";
// A bad example of string concatenation:
aString="this is text"+" another part of the text";
// A good example of if-statement:
if(aVariable == 10) {
//Do something
}
// A bad example of if-statement:
if(aVariable==10){
//Do something
}
// A good example of for-loop:
for(int i = 0; i < aVariable; i++) {
//Do something
}
// A bad example of for-loop:
for(int i=0;i<aVariable;i++) {
//Do something
}
#12 Where to declare our program variables in Java?
There seem to be a few differing opinions about this, some claim it would be preferable to declare variables just before you intend to use them in your program, others prefer to globally declare all variables your program is going to use at the top of the program code files (in the beginning).
Personally I have noticed that for the purposes that I usually coded for – global variables could be very handy – especially if you knew which they were – even if you don’t know at first, you might notice one after the other while coding your program – thats how it usually was for me when coding in Java. That way when I discovered a variable that I needed to access throughout the program on multiple occasions, I chose to declare it as a global variable easily overviewed in the start of the program – that way I could easily keep track of them.
It did however happen that I sometimes also created what I like to call “temporary” variables, which basically refer to variables created as the need arose during coding in the place where the need revealed itself. Such variables could for example be the for-loop iteration variable i in for(int i = 0; i < length; i++)
.
Read more if you’re interested in the ever-ongoing discussion about global or no-global variables here.
A few last words about good coding praxises before moving on to the next chapter of debugging in Java is that coding style guides that can be found online will vary between different organizations and personal preferences. These guidelines were inspired from the book Big Java Late Object with a personal touch from how I have come to code with time.
Debugging in Java
There are multiple methods to debugging Java code, some of the simpler ones, we will be explaining in this section below.
Using System.out to print out every variable – to see what it holds when during program execution
There are 2 ways of printing out debug information when programming in Java that can be useful to know about.
Print out ALL debug information at once in Java
One way is that you create a “debug” String/text variable to hold all your debug data, and then you simply “concatenate”/add to this variable as you go through your program – this can be good to activate/deactivate all debugging efforts at once with a simple on/off switch (IF statement). But it can also be good if you want to format your debugging information in a specific way.
Print out debug information on a needs-only-basis in Java
The other and probably most common way is to console print out everything you want to know, where you want to know it in the code, and when the print out is no longer needed, the printout can be either removed or commented out. This is usually the way I do it.
Say for example I have a variable I wish to know the value of at a certain point in my code, then I simply put a printout – in Java this is done with for example System.out.println();
method – after I expect the variable to have a certain value, to see if it does, then I can see in the console if my assumption was faulty or correct! And from there you can then move on to the next thing in your debugging efforts.
Step through the code via Eclipse Debugger
Eclipse similarily to other IDE’s and development tools often have built-in debugging kits which allow you to insert “breakpoints” on certain lines of code that allows you to then step through your code one breaking point at a time. This can be helpful if there is a lot of stuff happening very fast which usually is the case in programming since a computers processor and RAM tend to work quite fast most times.
The first thing you want to do when you’re about to start debugging using Eclipse built-in debugging tool is to “switch view”, see below:
In the picture you can find the view switch buttons in the interface to the top right, where Java coding view is to the left, and debugging view is to the right.
If you’re trying to start the debugger without first having switched views you will probably get a prompt looking like this:
In this debug prompt you can read that you will gain access to debug stack, variables and breakpoint management.
- Debug stack will you show information pertinent to each and every function being called up the the point you defined with breakpoints.
- Variables will help you track the values each variable holds at any given point in time when stepping through your breakpoints defined in your code.
- Breakpoint management allows you to add and remove breakpoints to further investigate your source code.
You define your breakpoints where you can see 2) in the picture above, and then they will appear as dots next to the row where you defined a breakpoint.
The prompt can be chosen to not appear in the future while switching between coding and debugging mode, to smooth the transition for future development.
At 3) you can see where in Eclipse you will find the Running of the debugger.
As you can see in the picture above, once you have accepted to switch view and initiated the debugger, you will find the variable values at each breakpoint at 1) in the top right corner of the debugger, 2) Shows where the debugger stopped and highlights the row to make it even clearer as you step through your source codes defined breakpoints with the Eclipse debugger.
At 3) You will find the following function buttons from the left to the right:
- Resume debugging
- Suspend debugging
- Terminate debugging
- Disconnect
- Step into (function calls etc.)
- Step over (skip function calls etc.)
- Step Return (Haven’t tested this yet but guessing it means return to where you were before stepping into function call)
- Drop to Frame (have never personally used)
- Use Step Filters (have never personally used)
Where the most common that I myself ever used was the 1-3 and 5-7 to stepping through the breakpoints defined in the source code.
And as you can see in above picture, when stepping through your breakpoints in Eclipse that will cause changes to occur in variables.
Eclipse will automatically highlight the varible affected so its easy to identify while at the same time highlighting the row in the code responsible for the change.
Very handy features that makes it a bit easier to keep track of everything :)
“Finger-tracing” and talking out loud to oneself (no joke)
The concept of finger-tracing is following function calls and variable journeys throughout your code so that you know that everything goes where you intended it to. A simple concept that can be oh so powerful.
Sometimes it can actually help to hear yourself talk because it opens up a new perspective, to have to hear something and let the brain interpret what it just heard makes you think about things differently sometimes. For coding this can be a valueable skill when you feel like you’re stuck and aren’t getting anywhere.
A famous concept among coders are to “stare themselves blind at their code” – which will happen to each and every one of us at some point – when it does, it’s good to have options for how to get on with it.
- Ask a colleague to take a look
- Talk out loud to yourself
- Track every single variable through your program to see that it does exactly what you intend for it to do where and when you use it in your code
- Check that your conditional statements are actually working
- Or that your loops behave the way you intended for them to
For one of my own personal horror stories I carry with me in my development efforts everyday: I have once been stuck at a programming problem for 2-3 weeks when I was developing a Snake game (with a few twists of my own) in JavaScript for a University course… Turned out that it was a malplaced dot (.) in the wrong place that caused my sleepless nights, staring myself blind at my code for days without end and the headaches that came of it. Unlucky for me, JavaScript did not report this error or give any clues as the where to find it. You can imagine my struggle when the game was a couple of thousand lines of code… and every detail needed to be sifted through.. And these things can happen to anyone(!) Especially if you code without a fancy IDE that is good at pointing out errors – I myself usually code web development in Notepad++ because I never really found an IDE for web dev that I liked enough to code in full time.
Writing Pseudocode to understand programming logic
So then, what is Pseudocoding? Well, pseudocoding is the concept of describing how to “code” with regular words one could say. What I mean by this is that you write the code as you would talk about it to make someone whos not into programming understand it.
So for example say we have a variable that should contain the total cost of something, then pseudocoding could be used to describe how this should work, like this:
sum of all costs = cost of apple + cost of milk + cost of butter
You could also write the following to get salary raise by 15% – to understand how the “problem” of getting 15% increase should be solved in programming:
Starting salary multiplied by 1.15
To write like this makes it easier to understand in programming what needs to be done logic-wise to solve problems.
What should be made into variables to make the calculations work, to make the logic work.
There are no strict guidelines to follow, even if some books may give tips on how to describe different things in programming using a certain “pseudocode syntax”.
Big Java Late Object describes a few examples on p. 18, where they have defined how to describe variables, arithmetic operations, conditional statements, loops, indentation to indicate relationship of code and how to define results for statements. But I have found that I don’t use these guidelines as strictly after having gotten used to programming more.
One could use it in whichever way makes it easier for yourself to get a proper understanding of the problem your facing and how to solve it – afterall thats whats important in the end.
Perhaps my variation described below that kind of just “became” is not actually “proper pseudocoding”, but I think its worth mentioning it nonetheless since it also can help solve programming problems – especially once you’re more into programming than when first starting out.
Pseudocoding variation – Mix between programming terminology and pseudocoding
Personally I can sometimes discuss programming problems with my colleagues at work and talk to them in a very conceptual way with a mix of programming lingo as well as pseudocoding – so its like pseudocoding but with programming terminology, and that also works pretty decently :)
An example could be like this:
Since our list is an array we need to loop through it to then identify when the index of the loop-iteration is 5, and then print the value to see what the 6th (index starts counting with 0) slot of our array holds.
Maybe its just how you talk about code once you get used to it :P
Words of Wisdom to effectively learn and understand Java quickly in the beginning
Do Not – I repeat – Do Not Copy-Paste!
Write everything by hand to get a proper “feel” for the language and at the same time develop and get a better memory of the building blocks that makes up the coding language – the components it uses if you will.
Using more of our senses when it comes to remembering things can really help – much like how some people prefer to jank door-handles to the bathroom to know it’s locked for sure in a public space. Same goes for any type of learning.
I have found (for myself personally) that actually using pen and paper empowers my memory of things I’ve read for example. The act of jotting down notes about it on a piece of paper actually helps bolster my memory, and I’m sure it might similarily help others as well. Writing on a keyboard for a computer can also have a similar effect. Hence the no copy-paste!
When you copy-paste other peoples code when just starting out, you are actively being lazy and might end up punished for it in ways of having bad understanding of fundamental building blocks necessary to have a good understanding to later become fluent in your chosen language, or simply a lack of understanding how the different puzzle pieces interact together which is crucial understanding to have when you have to use your creativity to solve a- before unheard of- problem for example.
This rule is especially important when you’re starting out, it becomes less relevant later on when you already have a good understanding of the programming language, still though – it doesn’t hurt to keep typing by hand, can only help further with memory as well as typing speed (the faster you type and don’t “stumble” on keys when programming, the more efficiently you will develop programs).
Luckily this is most crucial for your very first programming language, since a lot of programming languages share lots of similarities in both logic and syntax, much like spanish, italian and french languages share some similarities as well – and this helps if you have already mastered one language and are looking to expand your horizon and learn another one.