In this tutorial you will learn more Java and will look at Java generic classes and methods. This will allow you to write a simple Java app that you can then use in your IDE
About this Tutorial –
Objectives –
This course is aimed at object-oriented developers (e.g. C++ or C#) who need to transition into Java. It is also aimed at those learning to program for the first time; the course covers the Java programming constructs and APIs quickly, focussing on the differences between Java and other OO languages.
Audience
This training course is aimed at OO developers who need to transition into Java.
Prerequisites
No previous experience in Java programming is required. But any experience you do have in programming will help. Also no experience in eclipse is required. But again any experience you do have with programming development environments will be a valuable.
Experience using a contemporary OO language such as C++ or C# would be useful but is not required.
Contents
The Java course cover these topics and more:
- Flow Control: Decision making: if and if-else; The switch statement; Looping: for loops; while loops; do-while loops; for-each style loops; Assertionsv
- Concurrency: Overview of multithreading; Creating new threads; Object locking; Using wait, notify, and notifyAll
- Collections: Overview of Java SE collection classes; Generics; Using List-based collection classes; Using Set-based collection classes; Using Map-based collection classes; Collection techniques
Exam Preparation
The Java course will help you prepare for these certifications:
- Oracle Certified Java Associate – Exam 1Z0-803
- Oracle Certified Java Professional – Exam 1Z0-804
Quick Access
Overview
Estimated Time – 2 Hours
Not what you are looking? Try the next tutorial – Exceptions and Assertions
- Collections vs. Arrays
- A collection is an object that holds a group of other objects
- Some collection types (e.g. ArrayList) actually use arrays internally to store the data
- Differences between arrays and collections:
- Arrays are a Java language feature – Collections are standard Java classes, in the java.util package
- Arrays are pretty basic – Collections provide lots of useful methods to manipulate contents
- Arrays are fixed size – Collections are resizable
- Arrays can store primitive types as well as objects – Collections store only objects
- Arrays are processed using indexes – Collections are usually processed without using indexes
- A collection is an object that holds a group of other objects
- Simple Code Examples
- This code uses arrays:
public static void demoUsingArrays() {
String[] countries = new String[3];
countries[0] = "Norway";
countries[1] = "Sweden";
countries[2] = "Denmark";
for (int i = 0; i < countries.length; i++))
System.out.println(countries[i]);
}
- View code file.
- Equivalent code, using collections – See next section for discussion of <> generics syntax
import java.util.*;
...
public static void demoUsingCollections() {
ArrayList<String> countries = new ArrayList<String>();
countries.add("Norway");
countries.add("Sweden");
countries.add("Denmark");
for (String country: countries)
System.out.println(country);
}
- View code file.
- This code uses arrays:
- Common Collection Classes / Interfaces
- Understanding the Classes / Interfaces
- Collection
- Set
- Set-based collections guarantee element uniqueness
- E.g. HashSet uses hash codes to ensure element uniqueness
- List
- List-based collections store elements sequentially, by position
- E.g. ArrayList stores elements internally as an array
- E.g. LinkedList stores elements internally as a linked list
- Map
- Map-based collections store key/value pairs
- E.g. HashMap arranges items by using hash codes
- E.g. TreeMap arranges items in a tree
Lab 1: The need for generics
Lab 2: Using collections
Lab 3: Defining generic classes
Lab 4: Defining generic methods
Well done. You have completed the tutorial in the Java course. The next tutorial is
11. Exceptions and Assertions
Copyright © 2016 TalkIT®
If you would like to see more content like this in the future, please fill-in our quick survey.