Now that you know how to separate your code in methods, the next step is to learn about classes. Classes will not only let you organize your code in a better way, but it will also let you start diving into what is known as Object Oriented Programming, one of the most popular and powerful ways of coding today.
A class is a programming construct that enables you to define your own custom types. In a class you define a behavior (methods) and characteristics (member variables) that are shared across all instances of a class. You will use your class as a template to create objects. When you do this it is said that your new object is an instance of that class, or if you want to see it this way, your new object is a “copy” of your class.
Until now, all our code examples have been in the same Method. This is not the way it should be. In bigger projects you should create and use multiple methods. This is the topic of today’s post.
If you recall all our examples from previous posts, you see that we wrote all our code under a line of code that looks something like this
public static void main(String args)
This is the main method and is the method that is called when your program runs.
Now, we wrote all our code in the main method, but that is a bad practice. You can create your own methods to split functionality in your program. Normally, you would want a method to do a specific task.
This Post is part of the Variables & Operators block. I am going to introduce to you the wonderful Arrays.
An array is simply a container of multiple values of the same type. Along with the specific data type it also has a specific length or capacity.
You can use it, for example, to store 10 integer numbers on it. If you try to add a different data type, say a double, you will get an error. And also if you try to add 11 numbers, you get an error.
So… an array is a container with fixed lenght or capacity that can only contain one specific data type.
You can have access to each element in the array. For this you need to access it via its index. The index is the position the element has in the array.
Life is simple. You go on living in what looks like a straight line, without making decisions and without repeating any activity. It seems the perfect world…. until you realize it isn’t!
As in real life, writing code involves making decisions. Depending on some values, or the answer to some question or calculation or even the user input, the code will do something different. This is when it has to make decisions…. and to make decisions you use control (or conditional) statements.
There will be times when you need to repeat the same task many times, and you won’t know exactly the total number of times you need to repeat them. Instead of writing the same code over and over again, you can use control statements to repeat the same instructions until the processing is done.
Things will begin to get interesting….
So now you know how to install Java and Eclipse, how to create a simple project, a class and print the Hello World message, and also you know that Java has certain data types that can be used to create variables to store data.
But… what can be done with the data in the variables?
It is time to introduce to you the operators. With them you can do “operations” to your variables.
“In the beginning, God created… the integers, floating point numbers and the characters and strings…”
In this post you will learn data types supported in Java – that you can and will use in your code – and the ways to initialize them, valid values, etc. This is important because you will be handling different types of data – integers, floating point numbers, characters – always in your code.
First of all.. what is a variable? A variable is space in memory that is reserved for you to store data of a specific type. You can change this value, manipulate it or do whatever you want with it.
OK, I said that we will see again in a week, but I am too excited with the blog so I decided to write the next entry as soon as possible.
In this post I will show you the tools you need and how to get, install and run them to be able to program in Java.
You need two basic things: install Java on your computer and install an IDE.
Some time ago I came across Simple Programmer. This is a great blog from John Sonmez about software development: Making things simple. I subscribed to the site and one day I got an email from John with a Free Start Your Blog course. This course is the reason I am starting this blog today.
This course gives you the basics on how to start your own blog, and most importantly, how to keep up with it. I have tried in the past to start my blog, but I only got one entry and never got back to it. Now with the tools John provided me in this course I’m sure the story will be different.
In this first series of posts from Warrior Minds I will write about Software Development basics. You will learn the basic building blocks of software development so you have all the tools you need to start developing. This series of posts will use Java as programming language and Eclipse as IDE, but these basic building blocks will apply, mostly, to all Object Oriented Programming languages. Once we get finished with the Basics series, I will continue with more advanced series like mobile and web development.