Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, 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").


 

 


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

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


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., 2021: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4422_Obj ... -Java.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb