Tutorial Java – Contents

This Java tutorial covers all important Java 6 and 7 topics and allows a new programmer to learn the concepts, the know-how and the syntax elements of Java programming language. Also the tutorial highlights important topics for the SCJP certification exam.

1. Tutorial Java 6 – #1 Prerequisites

This series of tutorials, beginning with this topic, synthesizes elements of Java 1.6  that allows learning of Object-Oriented Programming (OOP) in Java 1.6.

2. Tutorial Java 6 – #2 Basic concepts

In this post we will see what are the basic rules, the components and the structure of Java programs.

2.1 Tutorial Java 6 – #2.1 How to write or generate JavaDoc commentsIn this post are described the rules needed to write or generate JavaDoc comments.

2.2 Tutorial Java 6 – #2.2 How to generate JavaDoc in Eclipse or NetBeansIn this post are presented de steps required to generate JavaDoc documentation for a Java project developed using an IDE like NetBeans or Eclipse.

3. Tutorial Java 6 – #3 How to define primitive data types variables

Java 6 In this tutorial we will see what are the primitive data types, how to define variables, which are their default values and what name we can give to these variables.

4. Tutorial Java 6 – #4 Arrays

In this topic we will see how we define and process arrays data structures in Java.

4.1 Tutorial Java – # 4.1 How to add a new element to a Java array

In this post we see what is the solution to the problem of adding a new element to an existing array.

4.2 Tutorial Java 6 – #4.2 How to copy values of an array into another array

In this post are described the methods used to copy one array values into another array.

4.3 Tutorial Java 6 – #4.3 Matrixes and Multidimensional Arrays

In this post we will see what are and how to define multidimensional arrays. The most common multidimensional array is the matrix – a two dimension array.

4.4 How to convert a byte array to a Hex String in Java 

In this post we will see how to convert a byte array to a Hex String in a Java application.

5. Tutorial Java 6 – #5 Flow control statements

In this post we can see how to implement in Java, the basic flow control structures/statements:

  • decision-making structures: if – then, if – then – else, switch;
  • structures for loop blocks: do-while, while – do, enhanced – for;
  • loop control instructions: break, continue;

6. Tutorial Java – #6 Classes and objects

Classes represent the basic principles of object-oriented programming. Classes are abstract concepts, stories, blueprints, describing:

  • characteristics, attributes of an object; these represent what the object knows, what it is;
  • object methods; these represent what the object knows to do, its behavior;

7. Tutorial Java – #7 Reference data type variables

In this post it is described one of the most important concepts of Object Oriented Programming: Every class instance, object, is managed only by reference type variables (for those who know also C++, you could remember that in C++ this rule is not entirely true because objects are also managed by value type variables).

8. Tutorial Java – #8 Understand Stack and Heap

In order to have a deep understanding of the Object Oriented Programming in Java or any other OOP language (like C#) you must know how things are managed internally by the Java process and by the JVM. Of course Java syntax and Java implementations of OOP principles are important but you will have a more clear image about the application resources, memory, performance, argument passing, threads and garbage collection if you put questions beyond How I do that ? or How I write that ?. The real questions should be How or Why it is happening like this ? (of course, at some point you should stop and move forward).

9. Tutorial Java – #9 Garbage collection and memory leaks

Despite the fact that today the hardware technology provide large amounts of Random Access Memory, software developers must pay attention to how they manage the application memory because they can implement wrong solutions that will crush the process or the machine because they ran out of memory.

10. Tutorial Java SCJP – #10 Variable Scope

Many compiler errors are generated because programmers don’t have a clear image on how long variables are available and when they can access them. The variable scope concept  describes the life of a variable, or its availability area, after it was defined.

11. Tutorial Java SCJP – #11 How to use String, StringBuilder and StringBuffer

The most used data types for variables in any programming language are boolean values, numeric primitive values and “strings” (or arrays) of characters. In contrast with C or C++, in Java handling strings is different because:

  • in Java every char is a 16 bit Unicode value, and not 1 byte;
  • in Java, strings values are managed by String objects;
  • in Java, the syntax allows you to use Strings as primitive data types (you can use = operator to initialize them)
  • in Java, Strings are immutable objects, meaning that once are created, they can’t change their value.

12. Tutorial Java SCJP – #12 Immutable, String and Integer

Immutable objects are objects that don’t change their value once they are created. The most known immutable object in Java is String. Besides String, there is another immutable object, and this is Integer (the class and not the primitive) which has an interesting behavior for values between -128 and 127.

13. Tutorial Java SCJP – #13 Packages and Class access modifiers

Two important concept of Object Oriented Programming is to separate entities based on their functionality or logic and to hide data and behavior within a class (encapsulation). For that you have classes used to define entities that have attributes and a behavior (their methods). At a higher level, for a good organization of the application modules you can use packages to separate the work of different programmers or to aggregate classes in modules based on their logic or utility.

14. Tutorial Java SCJP – #14 Methods and passing variables into methods

In Java, methods define the object behavior or implement different functionalities at class level (for static methods). If variables (value type or references) represent the static part of Java programming,then methods represent the dynamic part because methods are equivalent to code blocks that are executed and that are processing some variables.

14.1 Tutorial Java SCJP – #14.1 What is shadowing a variable

Shadowing occurs when you define a method with input parameters that have names identical to a static variables or instance variables.

14.2 Tutorial Java SCJP – #14.2 How to define methods with variable argument lists – var-args
Starting with Java 5.0 you can define methods with variable argument lists (var-args). These methods can be used in situations when you don’t know the exact number of arguments. These is also available in other programing languages and even I is not intensively used, it is a topic for the SCJP exam.

15. Tutorial Java SCJP – #15 Wrapper classes for primitive types

In Java there are 2 important categories of data types: references and primitives. Most of the time, numeric values, chars and boolean values are used as primitives because it is more efficient as processing speed and memory requirements. Despite that, there are scenarios (like using Collections) when it is needed to store primitive values inside objects. For that, Java provides a set of classes used to wrap primitive values in an object.

16. Tutorial Java SCJP – #16 Constructors

In a class you can define methods, but there is a special type of methods which are used to solve a particular problem, to construct objects. Constructor methods are special because of their role and because they have a lot rules regarding declaration and usage.

17. Tutorial Java SCJP – #17 Access modifiers for methods and attributes

Access modifiers represents ways to give or to restrict access to class variables and methods. One reason is the encapsulation concept that states that instance variables are not accessed directly, but only through access methods (prefixed with get or set). Another reason is to control how the class is used and how and what values are getting into instance variables (ex. if you implement the Person class that has a age instance variable you don’t want to allow other programmers to initialize it directly with any value because they can put a negative one)

18. Tutorial Java SCJP – #18 Initialization blocks

In order to process something you need values. And values are usually stored in static variables, local variables (defined in methods) or instance variables (nonstatic variables defined in classes). In order to initialize a variable you can do it at definition or later in a method (constructor or not). Despite these two common solutions, there is another way using initialization blocks.

Initialization blocks are blocks of codes defined between { and }. At this point they are like methods blocks, but the main difference is that initialization blocks don’t have  a name. They are like methods but without the method header (return type, name, parameter list).

19. Tutorial Java SCJP – #19 Enumerated lists or Enums

There are logically situations in which a variable must have values restricted to a specific range or set that is defined in the solution specifications. Let’s imagine that you must develop a Java applications that manages Vehicles and the engine type must take one value from the {GASOLINE, DIESEL, HYBRID, ELECTRICAL} set. You can define the engine type as a String or as an int and you can validate every time the input value. For strings you can compare the input value with “gasoline”, “diesel” and so on. For integer you can assume that GASOLINE is 1, DIESEL is 2, … and check the values based on this logic. This is a possible approach but it’s not ok because you can make easily mistakes and because you complicate a really simple procedure.

Like it? Then share this post or check the external adds. Sharing is the best way to appreciate the author.