Hello World Examples
[Previous]  [Next] 
|
![]() |
![]() User Manual [Previous]  [Next] Hello World ExamplesAs is customary when introducing a new language, here are some 'hello world' examples for Umple. Load these examples into UmpleOnline by clicking on the links. Then generate Java code by clicking on the 'Generate' button. Next click on the 'download zip file' link and run 'javac' on the result or else compile it in Eclipse. First example below: This looks identical to how a Java 'hello world' example would look, illustrating a key feature of Umple: Umple adds features to existing languages: Code in the original language can and does remain the same. Umple just replaces and simplifies some (or a lot) of it. Second example below: This shows some very simple features of Umple: An attribute, an association, a generalization, some Java methods and the mixin capability:
Umple and UML: Here is the class diagram of the second example in UML. If you click on the 'open in UmpleOnline' link, you will see the UML diagram generated. You can then edit the UML diagram to change the code, or change the code to edit the UML diagram. ![]() Example Showing a Simple Class with a Main Method/* * Simple Hello World example for Umple. * Compile this with Umple and it will generate Java * that is essentially the same. * * You could just as readily compile this code directly * with javac. However, this serves as the starting point: * Other examples in this manual show other things you * can do with Umple */ class HelloWorld { public static void main(String [ ] args) { System.out.println("Hello World"); } } Load the above code into UmpleOnline Example Showing Three Classes with an Association and Attributes (Diagram is Above)/* * Introductory example of Umple showing classes, * attribute, association, generalization, methods * and the mixin capability. Generate java and run this. * * The output will be: * The mentor of Tom The Student is Nick The Mentor * The students of Nick The Mentor are [Tom The Student] */ class Person { name; // Attribute, string by default String toString () { return(getName()); } } class Student { isA Person; } class Mentor { isA Person; } association { 0..1 Mentor -- * Student; } class Person { // Notice that we are defining more contents for Person // This uses Umple's mixin capability public static void main(String [ ] args) { Mentor m = new Mentor("Nick The Mentor"); Student s = new Student("Tom The Student"); s.setMentor(m); System.out.println("The mentor of " + s + " is " + s.getMentor()); System.out.println("The students of " + m + " are " + m.getStudents()); } } Load the above code into UmpleOnline Example Showing a Simple Class with a Main Method for Python Generation/* * Simple Hello World example for Umple. * Compile this with Umple and it will generate Java * that is essentially the same. * * You could just as readily compile this code directly * with javac. However, this serves as the starting point: * Other examples in this manual show other things you * can do with Umple */ class HelloWorld { public static void main(String [ ] args) { print("Hello World") } } Load the above code into UmpleOnline Example Showing Three Classes with an Association and Attributes (Diagram is Above) for Python Generation/* * Introductory example of Umple showing classes, * attribute, association, generalization, methods * and the mixin capability. Generate java and run this. * * The output will be: * The mentor of Tom The Student is Nick The Mentor * The students of Nick The Mentor are [Tom The Student] */ class Person { name; // Attribute, string by default String __str__() { return self.getName() } } class Student { isA Person; } class Mentor { isA Person; } association { 0..1 Mentor -- * Student; } class Person { // Notice that we are defining more contents for Person // This uses Umple's mixin capability public static void main(String [ ] args) { import Mentor import Student m = Mentor.Mentor("Nick The Mentor") s = Student.Student("Tom The Student") s.setMentor(m) print("The mentor of " + str(s) + " is " + str(s.getMentor())) print("The students of " + str(m) + " are " + str(list(map(str, m.getStudents())))) } } Load the above code into UmpleOnline |