Java Core Concepts As mentioned in the previous text about  what Java is , Java is more than just the programming language itself. It...

Java Core Concepts

03:18 PASSOVE INCOME 0 Comments

Java Core Concepts

As mentioned in the previous text about what Java is, Java is more than just the programming language itself. It's a platform with many subtopics and concepts. Within the Java language itself though, there are a handful of core concepts that are central to learning Java. This text will take a closer look at these core concepts.

Variables

Computer programs, regardless of programming language, typically read data from somewhere (file, keyboard, mouse, network etc.), process the data, and write the data somewhere again (to screen, file, network etc.).
In Java, data is kept in variables. Your Java program first declares variables, then read data into them, execute operations on the variables, and then write the variables somewhere again. Variables are explained in more detail in the text on Java variables.
Each variable has a certain data type. The data type determines what kind of data the variable can contain, and what operations you can execute on it. For instance, a variable could be a number. Numbers can be added, subtracted, multiplied, divided etc. Or, a variable could be a string (text). String's can be divided into substrings, searched for characters, concatenated with other strings etc. Java has a set of built-in data types. These data types are described in more detail in the text on Java data types.

Operations

Operations in Java are the instructions you can use to process the data in the variables. Some operations work directly on the variables, while other control the program flow. The most important operations are:
All of these operations are explained in their own texts.

Classes + Objects

Classes group variables and operations together in coherent modules. A class can have fields, constructors and methods (plus more, but that is not important now). I will shortly describe fields, constructors and methods here, but they are explained in more details in their own texts too. Here is a diagram illustrating classes, fields, constructors and methods:
Objects are instances of classes. When you create an object, that object is of a certain class. The class is like a template (or blueprint) telling how objects of that class should look. When you create an object, you say "give me an object of this class".
If you think of a factory producing lots and lots of the same items, then the class would be the blueprint / manual of how the finished product should look, and the objects would be each of the finished products. If the factory produced cars, then the blueprint / design manual of the cars to produce corresponds to a Java class, and the physical cars produced corresponds to Java objects.
Here is a simple diagram illustrating the principle of objects being of a certain class. The class determines what fields and methods the objects of that class have.
A Java class can contain fields, constructors and methods.
A Java class can contain fields, constructors and methods.

Fields

A field is a variable that belongs to a class or object. It is a piece of data, in other words. For instance, a Car class could define the field brand which all Car objects would have. Then each Car object can have a different value for the brand field.
Fields are covered in more detail in the text on Java fields.

Constructors

Constructors are a special kind of method that is executed when an object is created of the given class. Constructors typically initialize the objects internal fields - if necessary.
Constructors are covered in more detail in the text on Java constructors.

Methods

Methods are groups of operations that carry out a certain function together. For instance, a method may add to numbers, and divide it by a third number. Or, a method could read and write data in a database etc.
Methods are typically used when you need to group operations together, that you need to be able execute from several different places. Or, if you just want your code to be easier to read.
Methods are covered in more details in the text on Java methods.

Interfaces

Interfaces is a central concept in Java. An interface describes what methods a certain object should have available on it. A class can implement an interface. When a class implements an interface, the class has to implement all the methods described in the interface. Interfaces are described more in my text aboutinterfaces.

Packages

Packages in Java is another central concept. A package is a directory containing Java classes and interfaces. Packages provides a handy way of grouping related classes and interfaces, thus making modularization of your Java code easier. Packages are described in more detail in my text about Java packages.

0 comments: