Constructors

JavaA constructor is a special type of method that is executed when an object is created. The purpose of constructors is to assign values to the fields that are specific to that particular instance of the object. For instance, if you are creating a Car object, you may need to tell the program what brand the car is, what color it is, how fast it is going, and in what direction it is traveling. A constructor allows you to do these things easily when the object is created during program execution.

Saying that a constructor is a method is like saying that the Australian platypus is just another mammal. To understand the platypus, it is important to know how it is different from other mammals. To understand the constructor, it is similarly important to understand how it differs from a method. Any student of Java, especially one studying for certification, needs to know those differences; in this article, I will concretely spell them out. Continue reading

Advertisements

Classes & Objects

JavaClasses are designed to group variables and operations together in coherent modules. Classes have fields, constructors and methods among other attributes. Objects are nothing more than specific instances of a class. This is Object Oriented Programming in a nutshell.

The best way to think about classes and objects is to think about cars. The Car Class contains all possible cars within it. All cars share certain attributes such as having four wheels, an engine, a transmission, seat belts, a steering wheel, etc. When you create an object, it is a specific instance of a car. By default, this object takes on all of the attributes of the Car Class and it can also have its own attributes specific to that particular instance.  This is known as inheritance.

If you don’t understand all of it just yet, don’t worry – it will come to you. The point is simply that object oriented programming allows you to inherit certain attributes of a class without having to write that individual code every time you want to use it in your program. In other words, you don’t have to tell your program that a Car object has wheels, a steering wheel, an engine, a transmission, etc. because the program already knows these things because of the attributes defined within the Car Class. Continue reading

Operations

JavaSimilar to punching keys on a calculator, your Java programs rely on operators (+, -, *, /, ?, and a host of others) to work with the variables in your program. Operators can be used to assign value to variables, perform mathematical functions, and create new objects based on variables.

Operators are also used for conditional logic statements such as for loops, while loops, if statements, switch statements, and method calls. Continue reading

Variables

JavaAll computer programs, regardless of the programming language they are written in, read data from somewhere (a file, the keyboard, the mouse, the Internet, etc.), process the data, and then write the data somewhere else such as the computer monitor or a database file on the hard drive.

In Java, like most other programming languages, data is kept in variables. Yes variables – like X and Y and all those other letters you thought you would never use again in high school algebra. As you create Java programs, you have to declare variables, assign values to them, and execute operations using these variables.

Every variable in a Java program has a certain data type. The data type determines what type of data can be contained within that variable and what operations can be executed on the variable. A variable could be a number. Numbers are further broken down into categories based on their size. A variable can also be a string of text. Although you cannot perform mathematical equations on strings, you can use the “+” operator to concatenate two or more strings together. Continue reading

Introduction About Java

JavaWhen you first start learning Java, there are quite a few concepts that may seem foreign to you. One of the most important is the concept of Object Oriented Programming; one of many important subjects that are essential to successfully learning Java programming.

If you have no previous Java programming experience, Java for Absolute Beginners is a great place to get your feet wet while learning by example. In this tutorial, you will learn some of the core concepts inherent to the Java programming language. Without a solid foundation in these concepts, you’re unlikely to be successful with Java or most other programming languages for that matter.

The great thing about learning to program in Java is that there are excellent classes available and a large developer community willing to help should you run into issues along the way. If you get stuck on a particular statement, chances are that hundreds or even thousands of others have been stuck in the same spot before you and a quick Internet search should net you plenty of solutions for your problem.

Whether you have zero programming experience or are just new to Java (and have experience in another language), you will be well served to learn the concepts contained within this article because you will rely on them in practically every line of code you write for your Java applications.