User Tools

Site Tools


basics:intro

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
basics:intro [2007/02/23 10:24]
bdefrain
basics:intro [2021/02/05 13:49] (current)
Line 1: Line 1:
 +[[basics:intro|Intro]]
 +[[basics:ex1|Ex1]]
 +[[basics:ex2|Ex2]]
 +[[basics:ex3|Ex3]]
 +[[basics:ex4|Ex4]]
 +[[basics:ex5|Ex5]]
 +[[basics:ex6|Ex6]]
 +[[basics:ex7|Ex7]]
 ====== The Basics: Intro ====== ====== The Basics: Intro ======
  
-In this exercise, you will use aspects to instrument a dummy class in order to get acquainted with the basic techniques of AspectJ.+In this exercise, you will use aspects to instrument a dummy class in order to get acquainted with the basic techniques of AspectJ: pointcuts, advices and inter-type declarations.
  
 ===== Set-up ===== ===== Set-up =====
  
-  - Create a **new AspectJ Project** in Eclipse +  - Create a **new AspectJ Project** in Eclipse 
-  - Create the following ''Application'' class:+  - Create a **new class** ''Application'' containing the code given below. 
 +  - **Run** the code. Right-click the ''Application'' class and select **Run as...** -> **AspectJ/Java Application** 
 <code aspectj> <code aspectj>
 public class Application { public class Application {
-  public int go = 10; +  public int go = 10; 
-   +   
-  public void start() { +  public void start() { 
-    System.out.println("Starting"); +    System.out.println("Starting"); 
-    stop(go); +    stop(go); 
-  }+  }
  
-  public void stop(int i) { +  public void stop(int i) { 
-    System.out.println("Stopping"); +    System.out.println("Stopping"); 
-  }+  }
  
-  public void exec() throws Exception { +  public void exec() throws Exception { 
-    throw new Exception("An exception"); +    throw new Exception("An exception"); 
-  }+  }
  
-  public static void main(String[] args) { +  public String toString() { 
-    Application t = new Application(); +    return "Application go: " + go; 
-    t.start(); +  } 
-    t.stop(25); + 
-    try { t.exec(); } +  public static void main(String[] arg) { 
-    catch(Exception e) { System.out.println(e);+    Application t = new Application(); 
-  }+    System.out.println(t); 
 +    t.start(); 
 +    t.stop(25); 
 +    try { t.exec(); } 
 +    catch(Exception e) { System.out.println(e);
 +  }
 } }
 </code> </code>
-  Create the following aspect.+ 
 +You should see the following output on the **Console** view (which you can open through **Window** -> **Show View** -> **Console**): 
 + 
 +<code> 
 +Application go: 10 
 +Starting 
 +Stopping 
 +Stopping 
 +java.lang.Exception: An exception 
 +</code> 
 + 
 +<note tip> 
 +In the following steps, you can use Eclipse's Run button (or the shortcut CTRL+F11) to quickly rerun the application using the last run configuration. 
 +</note> 
 + 
 +---- 
 + 
 +Start the Basics track at [[basics:ex1|Exercise 1]].
  
basics/intro.1172222643.txt.gz · Last modified: 2007/02/23 10:24 by bdefrain