Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
Python and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Lua, etc
 
Objects - from physical to virtual or abstract - Java

A train, a person, a dog, a signpost, a meal, a station ... they're all similar objects in programming terms. We can set them up in our program, save and restore attributes - and they make an excellent teaching parallel comparing real life things ("objects") of a certain type ("class").

Knighton Station

 
Llandrindod Station - or is that Llandrindod Wells? Craven Arms Land of lost content, Craven Arms

 
Information at Swindon Station


Objects and classes can also be used for more abstract items and structures, such as file handlers, and on our courses we move on and look at the use of classes and objects in this way too. In my most recent day's training, I have used both Station objects of the original (represents something physical) and more abstarct (stream handler) types, with my main code doing no more than providing the wires that link the two.

  public static void main (String [] args) {
    MyStream RailStations = new MyStream(args[0]);
    Stations [] NationalRail = new Stations[3000];
    int stationCount = 0;
  
    String lyne;
    while ((lyne = RailStations.readLine()) != null) {
      NationalRail[stationCount++] = Stations.factory(lyne);
    }
  
    for (int k=0; k       Stations current = NationalRail[k];
      if (current.isitSmall()) {
        System.out.println(current.name + " " +
          current.getPassengers());
      }
    }
    }
  }


For true (production) code, I would have used a Vector or ArrayList object rather than hardcoding a 3000 record limit, and I would have introduced error checking and exceptions into my code, allowing for my factory to be passed poor information that didn't result in an object being returned - by these are "to follow" things at this point in the middle of the course.

Source code (both the main program and the classes) at [here].

Sample output:
  WomanWithCat:dvla5 grahamellis$ java StationStatistics railstats.xyz
  Pilning 146
  Barry Links 86
  Tees-Side Airport 14
  Hensall 184
  Breich 90
  Chapelton 190
  Achanalt 164
  Sugar Loaf 120
  Denton 30
  Acklington 192
  Elton & Orston 72
  Buckenham 100
  Havenhouse 132
  Coombe 60
  Dorking West 16
  Reddish South 56
  WomanWithCat:dvla5 grahamellis$

(written 2015-02-10, updated 2015-02-12)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
J706 - Java - Objects and Classes
  [4413] Binomial Coefficient (Pascal Triangle) objects in Java - (2015-02-03)
  [2651] Calculation within objects - early, last minute, or cached? - (2010-02-26)
  [2616] Defining a static method - Java, Python and Ruby - (2010-02-01)
  [2422] Looking inside Java classes - javap and javadoc - (2009-09-25)
  [2169] When should I use OO techniques? - (2009-05-11)
  [1925] Introduction to Object Oriented Programming - (2008-12-06)
  [1906] Long, Longer, Longest in Java - (2008-11-25)
  [1500] First Class Java. First step and moving forward. - (2008-01-10)
  [1296] An example of Java Inheritance from scratch - (2007-08-08)
  [1163] A better alternative to cutting and pasting code - (2007-04-26)
  [477] Class, static and unbound variables - (2005-10-25)
  [96] Variable Scope - (2004-10-22)

J710 - Java - Extending Classes and More
  [4419] Java Inheritance example - group of classes - step by step - (2015-02-08)
  [4394] Philosophy behind object design - and how I applied in to a Java example - (2015-01-14)
  [4366] Changing what operators do on objects - a comparison across different programming languages - (2014-12-26)
  [4334] Splitting out code into name blocks for clarity and reusability - (2014-11-30)
  [3047] What is a universal superclass? Java / Perl / Python / Other OO languages - (2010-11-13)
  [2860] What methods are available on this Java object? - (2010-07-08)
  [2604] Tips for writing a test program (Ruby / Python / Java) - (2010-01-29)
  [2434] Abstract classes, Interfaces, PHP and Java - (2009-10-03)
  [2185] Abstract Classes - Java - (2009-05-16)
  [1819] Calling base class constructors - (2008-10-03)
  [1556] Java - a demonstration of inheritance on just one page - (2008-02-26)
  [1538] Teaching Object Oriented Java with Students and Ice Cream - (2008-02-12)
  [1501] Java - using super to call a method in the parent class - (2008-01-10)
  [1294] An example of Java Inheritance from scratch - (2007-08-00)
  [1217] What are factory and singleton classes? - (2007-06-04)
  [1066] Final, Finally and Finalize - three special words in Java - (2007-02-05)
  [831] Comparison of Object Oriented Philosophy - Python, Java, C++, Perl - (2006-08-13)
  [656] Think about your design even if you don't use full UML - (2006-03-24)


Back to
How healthy are the stars of stage and screen?
Previous and next
or
Horse's mouth home
Forward to
Campus - about the logos / way marks you have been choosing from
Some other Articles
FileMaker Day to Unix Time conversion
A Welsh valley - what the transport looks like in 2015
Looking Forward - TransWilts Community Rail Partnership and TransWilts CIC
Campus - about the logos / way marks you have been choosing from
Objects - from physical to virtual or abstract - Java
How healthy are the stars of stage and screen?
Flexibility in input - read from file, web resource or keyboard
Melksham Community Campus - which of these potential signs do you like?
Crisp morning, fast run
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2019: 404 The Spa • Melksham, Wiltshire • United Kingdom • SN12 6QL
PH: 01225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4422_Obj ... -Java.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat