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
 
Setting up individual variables, and arrays, in Java - some commented examples

In Java, variables must be defined before they have an initial value assigned to them, and they must have an initial value assigned to them before the value thay contain is used; there's no automatic assumption that a new name is a variable, nor is there an assumption made of what type of data a variable can contain.

[Here]'s an example of a "first day program" that I wrote on yesterday's Starting Java Course showing this setup of variables, calculations using them, and output. Keyboard input in Java isn't straightforward, so I used a class of my own to provide a method which hides the complicated bits of that stage within in - and that's [here].

Following of from that example for newcomers to coding, I provided an example with a loop - [here] - showing the same principle in use, but now with a repeating block of code too. Note - in both of theses examples - how vital it is to have to code well commented to make it followable!

Arrays similarly need to be defined (telling Java what type of data they'll contain) and their length needs to be set up / memory allocated too via the new keyword. Arrays in Java start at position number 0, so an array with 7 members has elements numbered 0 through to 6 inclusive (it's very easy for this to confuse you!)

You'll want to set up an array, you'll want to fill it with values. You'll want to echo those values out, find the lowest and highest values, and do a lot more. I've just written an (over)commented example [here] so you can see how many of those things are done ... no longer on the first day of the course and just for newcomers to Java ... we're now into the Java Bootcamp Course!.
(written 2010-11-09)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
J703 - Java - Variables
  [4345] Incrementing a variable in Java - Pre and Post Increment - (2014-12-08)
  [4324] Learning to program - variables and constants - (2014-11-22)
  [3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
  [3365] Turning bright delegates into bright and knowledgable ones - (2011-07-21)
  [3278] Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. - (2011-05-05)
  [3041] Java - basic rules for arithmetic, variables and conversion - (2010-11-10)
  [2153] Class Loading and Variable Conversion in Java - (2009-05-02)
  [2148] Variable scope in Java Servlets and other web applications - (2009-05-01)
  [1448] Question on division (Java) - Also Perl, PHP, Python ... - (2007-11-28)
  [127] Conversion and coercion in Java - (2004-11-22)

J704 - Java - Loops and Conditional Statements
  [4427] Java example - for loop and conditionals from course exercise - (2015-02-16)
  [4346] A behaviour driven example of writing a Java program - (2014-12-09)
  [4323] Learning to program - Loop statements such as while - (2014-11-22)
  [4322] Learning to Program - the conditional statement (if) - (2014-11-21)
  [3397] Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18)
  [3200] How a for loop works Java, Perl and other languages - (2011-03-12)
  [2734] for and foreach in Java - (2010-04-22)
  [1696] Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)
  [1582] Ruby, C, Java and more - getting out of loops - (2008-03-19)
  [1220] for loop - how it works (Perl, PHP, Java, C, etc) - (2007-06-06)
  [353] Wimbledon Neck - (2005-06-20)

J705 - Java - Arrays
  [4428] Using the lead - passing arrays and other collections in Java - (2015-02-16)
  [4413] Binomial Coefficient (Pascal Triangle) objects in Java - (2015-02-03)
  [4347] Arrays in Java - an introduction for newcomers - (2014-12-10)
  [3118] Arrays of arrays - or 2D arrays. How to program tables. - (2011-01-02)
  [3039] Fresh Paint - Java Arrays - (2010-11-09)
  [2648] Java arrays - are they true arrays or not? - (2010-02-23)
  [1614] When an array is not an array - (2008-04-17)
  [1498] Java is a dynamic language .... (and comparison) - (2008-01-08)
  [1497] Training Season Starts again! - (2008-01-07)


Back to
Looking back and forward personally - 6 years each way
Previous and next
or
Horse's mouth home
Forward to
Fresh Paint - Java Arrays
Some other Articles
Least Common Ancestor - what is it, and a Least Common Ancestor algorithm implemented in Perl
Doing several things at the same time - Java threads
Setting up individual variables, and arrays, in Java - some commented examples
Looking back and forward personally - 6 years each way
Sending out an email containing HTML from within a PHP page
How to display information from a database within a web page
Birth Notice - Aeryn Cassandra Ellis
Rail services back to Radstock?
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/3038_Set ... mples.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat