Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #21016

Re: "Hello world!" without a public class?

X-Received by 10.66.80.34 with SMTP id o2mr7848096pax.9.1357461849363; Sun, 06 Jan 2013 00:44:09 -0800 (PST)
Received by 10.50.11.196 with SMTP id s4mr789006igb.9.1357461849116; Sun, 06 Jan 2013 00:44:09 -0800 (PST)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!f6no4414424pbd.1!news-out.google.com!s9ni85391pbb.0!nntp.google.com!f6no4414415pbd.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.java.programmer
Date Sun, 6 Jan 2013 00:44:08 -0800 (PST)
In-Reply-To <public-20130106091348@ram.dialup.fu-berlin.de>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=173.164.137.214; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
NNTP-Posting-Host 173.164.137.214
References <public-20130106091348@ram.dialup.fu-berlin.de>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <40a19d18-6655-4256-85b9-6954e2f10b84@googlegroups.com> (permalink)
Subject Re: "Hello world!" without a public class?
From Lew <lewbloch@gmail.com>
Injection-Date Sun, 06 Jan 2013 08:44:09 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Xref csiph.com comp.lang.java.programmer:21016

Show key headers only | View raw


Stefan Ram wrote:
> »class HelloWorldApp {
>     public static void main(String[] args) {
>         System.out.println("Hello World!"); // Display the string.
>     }
> }
> «
> 
> http://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html
> 
>   There is no »public« in front of »class« in Oracles Tutorial!
> 
>   What should I teach in my classes?

Depends on the kinds of students you have, I should think.

There's pedagogical merit in teaching the good habits first and the 
exceptional cases later. So you could begin with only 'public' classes 
overall, let alone for the main one, mentioning briefly at first that 
there is a way to drop the 'public' that you'll explain later.

As for 'final', that's harder. Hardly anyone in the field uses it, 
myself included, because most classes basically aren't inherited so it's 
not really risky to leave it out, and also there's a benefit to making 
classes heritable for test purposes.

I think as a teacher I would use 'final' nearly always for classes, and 
explain to the class (of students) that I'm being picky, but for good 
reason. Also I'd mention that heritable classes support a certain style of 
test code, and teach it once inheritance had been covered.

>     1.) »public class HelloWorldApp« (because this is most common IIRC)

First time you deal with class definition, show all these forms once.

>     2.) »class HelloWorldApp« (because this is in Oracles tutorial)

Mention that this rarely occurs in practice.

>     3.) »final class HelloWorldApp« (because this class is not designed
>         for inheritance and Bloch says that one should not inherit from
>         it in this case and the students can as well get used to this
>         right from the start)

package-private again - same brief mention.

>     4.) »public final class HelloWorldApp« (combination of »1.)« and »3.)«)

Go with this but explain that practice can differ.

Break the 'final' later when there is a pedagogical and good-code reason to.

Just off the top of my head - I haven't put nearly the thought into this that 
you have.

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: "Hello world!" without a public class? Lew <lewbloch@gmail.com> - 2013-01-06 00:44 -0800
  Re: "Hello world!" without a public class? Robert Klemme <shortcutter@googlemail.com> - 2013-01-06 11:47 +0100

csiph-web