Return to Tutorial

Coding in Java with artEoz – exercises

For any comments on the exercises, new ideas, illustrations or interesting memory diagrams, feel free to contact us by forum or by mail.

 Getting started with artEoz

Highlightmarker-green24First steps

Highlightmarker-green24Use predefined or personnal resources

Highlightmarker-green24Objects

Highlightmarker-green24Unreferenced objects

Highlightmarker-green24Function call and call stack visualization

Highlightmarker-green24 Variables scope

Strings

Highlightmarker-green24class String

Highlightmarker-green24class StringBuilder

Highlightmarker-green24 Arrays

Lists

Highlightmarker-green24class ArrayList

Highlightmarker-green24ArrayList iterator

Highlightmarker-green24class LinkedList

Highlightmarker-green24LinkedList iterator

Highlightmarker-green24Linked list personnal class

Dictionaries

Highlightmarker-green24 class HashMap

Highlightmarker-green24 HashMap iterator

Trees

Highlightmarker-green24N-ary trees

Highlightmarker-green24 Inheritance and dynamic binding: we can (finally) understand how it works !
Highlightmarker-green24 Anonymous classes

Anonymous classes

◄ Previous exercise Make sure you have the anonyme resource. If necessary, see the Resources import webpage. The constructor of Ecureuil class instantiate an anonymous class. How many objects are created? Ecureuil ecureuil = new Ecureuil(“Scratch”) ; ecureuil.coder(5) ; String chaine = ecureuil.getNom() ; This anonymous class has no field declaration. Yet the memory diagram …

HashMap class

◄ Previous exercise Next exercise ► Make sure you have the geometrie resource. If necessary, see the Resources import webpage. A table is a function that assigns a value to a key; a key can only have one value. The HashMap <K, V> class is a special implementation table (K is the key type and …

HashMap iterator

◄ Previous exercise Next exercise ► Make sure you have the geometrie resource. If necessary, see the Resources import webpage. The code below creates a dictionary with several points. Which statement allows you to check the iterator on the keys? HashMap<String, Point> table = new HashMap<>(6) ; for (int k=0 ; k < 3 ; …

Inheritance and dynamic biding

◄ Previous exercise Next exercise ► Make sure you have the calc resource. If necessary, see the Resources import webpage. Enter the code below. The Inherited attributes option inherited from the Options menu displays fields inherited from superclasses. What are the specific fields and inherited from an instance of Nombre? from an instance of Somme? …

N-ary trees

◄ Previous exercise Next exercise ► An n-ary tree is a tree in which each node has any number of son. One can use an n-ary tree to represent a dictionary and thus speed up the search. The root has as many son as possible first letters, then each son has as many son as …

Personal linked list class

◄ Previous exercise Next exercise ► Make sure you have the liste chainee resource. If necessary, see the Resources import webpage. Enter this sequence of instructions: ListeChainee<Integer> liste = new ListeChainee<Integer>() ; liste.ajouterTete(new Integer(4)) ; liste.ajouterQueue(new Integer(10)) ; liste.ajouterQueue(new Integer(2)) ; liste.ajouterTete(new Integer(60)) ; liste.supprimer(new Integer(10)) ; liste.supprimer(new Integer(2)) ; and select the step-by-step mode …

First steps with artEoz

Next exercise ► Make sure the Java icon is displayed at the top left of the page. Select a code example fron the drop down menu. The right frame displays the memory diagram corresponding to the execution of all the instructions of your code. You can execute the code step-by-step, select forward  or backward arrows …

Resources import

◄ Previous exercise Next exercise ► The tutorial exercises are based on classes of the java library but also on specific resources developed for this tutorial. Clicking on displays the list of resources that can be used when running a program. Resource documentation here. You can also import your own resources in three formats: a …

Objects

◄ Previous exercise Next exercise ► Make sure you have the geometrie resource If necessary, see the Resources import webpage. Open a new plain code frame and enter the following java code: int i = 5 ; Point p1 = new Point(i,6) ; Point p2 = new Point(7,8) ; Display the memory diagram  How many …

Unreferenced objects

◄ Previous exercise Next exercise ► Make sure you have the geometrie resourceIf necessary, see the Resources import webpage. Open a new plain code frame and enter the following java code: int i = 5 ; Point p1 = new Point(i,6) ; Point p2 = new Point(7,8) ; p1 = null ; Display the memory …

Functions call and call stack visualization

◄ Previous exercise Next exercise ► Make sure you have the geometrie resourceIf necessary, see the Resources import webpage. Open a new plain code frame and enter the following java code: int i = 5 ; Point p1 = new Point(i,6) ; p1.deplacer(i, i*2); Point p2 = new Point(7,8) ; Segment s = new Segment(p1, …

Java variables scope

◄ Previous exercise Next exercise ► Make sure you have the geometrie resourceIf necessary, see the Resources import webpage. Open a new plain code frame and enter the following java code: Point p = new Point(1,2) ; int k ; for (int i = 0 ; i < 3 ; i++) { Point q = …

String class

◄ Previous exercise Next exercise ► The statements below instantiate strings as instances of java.lang.String class in various ways. Can you identify these ways? String c1 = “bon” ; String c2 = “bon” ; String c3 = new String(“bon”) ; String c4 = “jour” ; c4 = c2 + c4 ; The Simplified String display …

StringBuilder class

◄ Previous exercise Next exercise ► If you wish to modify a string, the String class is not appropriate. You have to use the StringBuilder class. Enter this sequence of instructions: StringBuilder sb1 = new StringBuilder(“bon”) ; StringBuilder sb2 = new StringBuilder(“bon”) ; sb2.append(“jour”); Add some instructions which use String to compare memory diagrams. Check …

Arrays

◄ Previous exercise Next exercise ► The following java code declares, instanciates and a one-dimension array of integers: int[] tab = new int[6] ; for (int i = 0 ; i < tab.length ; i++) { tab[i] = 2 * i ; } Run this code and display the memory diagram. What is the label …

ArrayList class

◄ Previous exercise Next exercise ► Make sure you have the geometrie resource. If necessary, see the Resources import webpage. The code below creates a list: ArrayList<Point> liste = new ArrayList<>() ; liste.add(new Point(0,0)); liste.add(new Point(1,1)) ; What is the capacity of this list? ? What is its size? Add to the end of the …

ArrayList iterator

◄ Previous exercise Next exercise ► Make sure you have the geometrie resource. If necessary, see the Resources import webpage. The code below creates a list with some points. Which statement uses the iterator attached to this list? ArrayList<Point> liste = new ArrayList<>() ; for (int k=0 ; k < 5 ; k++) { liste.add(new …

LinkedList class

◄ Previous exercise Next exercise ► Make sure you have the geometrie resource. If necessary, see the Resources import webpage. The code below creates a list LinkedList<Point> liste = new LinkedList<>() ; liste.add(new Point(0,0)); liste.add(new Point(1,1)) ; Run this code in step-by-step mode. How many attributes are included in the memory diagram of an instance …

LinkedList iterator

◄ Previous exercise Next exercise ► Make sure you have the geometrie resource. If necessary, see the Resources import webpage. The code below creates a list with some points. Which statement uses the iterator attached to this list?  LinkedList<Point> liste = new LinkedList<>() ; for (int k=0 ; k < 5 ; k++) { liste.add(new …