Talk:Programming:Java

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

Contents

[edit] TOC

Having two TOCs looks somewhat messy. It might be nicer to integrate some of the pages and make it more consistent (what's on the main page, what's not).

[edit] Programming style

Does anybody think it would be good to use the same programming style throughout this book? I know many people prefer the Sun standard, but I prefer braces on the next line i.e.

void someMethod()
{ smeStatement;
  return;
}

[edit] My Comments

Why not call the Statements and Expressions section Operators, since that's what you are discussing there. There is no such thing as a statement anyways (? surely a statement is either a simple satement - a series of tokens ending with a semicolon, or a complex statement - a series of statements enclosed in curly brackets. The definition of the flow control constructs like if, for and while all use the concept of a statement) , and an expression is simply a portion of code using an operator for assignment and/or comparison purpose. I think Operators and Expressions, or simply Operators, would be a much better header.

This is not a correct use of Java programming language terms. A statement has a specific meaning which is very different than operators/operations (which usually denote things like unary or binary operations like +, *, etc.). There is such a thing as a statement in Java -- if statements, while statements, etc. See the JLS: 14 Blocks and Statements. I think it is imperative that this wikibook use the same terms as the JLS. For a Java wikibook, Statements and Expressions should be two completely different articles/modules due to their complexity. --djb 01:06, 27 October 2005 (UTC)

Also, as for coding style, I am used to the PHP style of programming, with starting brace on the same line, closing brace on a new line. Like so:

function test() {
  var a = true;
}

Although I know this is not the standard. I say for the purpose of WikiBooks we should stick to the standard, which would be the brace on a new line, and only that brace:

function test()
{
  var a = true;
}

I'm pretty sure that Sun has similar convetions to PHP- (see: Official Sun Code Conventions). The non-standard style seems a bit clearer, as the braces always align and such. --Mikm 19:43, 21 May 2005 (UTC)

[edit] Java standard is Java standard!

I'm of the mind that teaching someone the wrong way, then telling them "Oh yeah, this way, isn't really how you'll see it" is a HORRIBLE way to teach! The Java standard formatting typically is and always should be used in teaching the Java language!

[edit] Appropriate?

Does anybody else here think that the "if" statements is inappropriate for a book?

[edit] Explain

What is innappropriate about them?


[edit] Never Mind

never mind, it seems someone has changed them. It used to read something like: if (age < 18) Sys.out.prtln("You can't smoke); else if (age < 21) SYs.out.prtln("You can't drink but you can smoke"); else if (age > 21) Sys.out.println("Have a beer!");

Of course, the example was written in real Java instead of the pseudo-Java code I've used here.

[edit] OK

Yes, I thought the same thing, so I changed it.

[edit] request for info

I'm taking a programming course in Turing, and I've started to teach myself Java. I'd really like to know how to get data from the keyboard, declare variables, assign variables value and work with arrays using for loops (some of that is already covered here, and in Wikipedia, you don't have to repeat it, though peherhaps you should):

var names:flexible array 1..0 of string %declare a flexible array of strings (Size 0)
var number:int %declare an int
var temp:string %declare a string
put "How many names?"..
get number %get data from keyboard
for i:1..number
 get names(i) %assign array entries value from keyboard
end for
for decreasing i:number-1..1
 for j:1..i                   %bubble sort the array entries
  if names(j)>name(j+1) then
   temp:=names(j)
   names(j):=names(j+1)
   names(j+1):=temp
  end if
 end for
end for
for i:1..upper(names)
 put names(i)                %print the sorted entries to the screen
end for

Thanks

// messi 21:01, 2 Jun 2005 (UTC)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SortStrings {

  public static void main(String[] args) throws IOException {
    BufferedReader console = new BufferedReader(new InputStreamReader(System.in));

    System.out.print("How many names? ");
    final int number = Integer.parseInt(console.readLine(), 10);

    String[] names = new String[number];
    for (int i = 0; i < number; i++) {
      names[i] = console.readLine();
    }

    for (int i = number; i > 0; i--) {
      for (int j = 1; j < i; j++) {
        if (names[j - 1].compareTo(names[j]) > 0) {
          String temp = names[j - 1];
          names[j - 1] = names[j];
          names[j] = temp;
        }
      }
    }

    for (int i = 0; i < number; i++) {
      System.out.println(names[i]);
    }
  }
}


[edit] installing Java

It seems to me that the biggest stumbling block is getting everything installed (although, technically, all these platform-specific details don't have anything to do with the Java language itself.) Consider adding a click-here-type-this installation guide, something like::

  • download and install the latest version of the Java SDK (currently J2SE 5.0 from http://java.sun.com/ , which comes with the NetBeans IDE).
  • download and install your favorite development environment. (If you don't like the NetBeans IDE, you could use Eclipse from http://eclipse.org , or your favorite text editor and the command line).
  • add a reference to the bin directory of the SDK to your PATH (see below for details).
  • Remove the CLASSPATH variable, if it exists (modern versions of Java don't need it). (Or, if you need it for some other reason, make sure it includes a period character, referring to the current directory).

[edit] editing PATH on Windows 95 and 98

In the root folder of your main hard drive, find AUTOEXEC.BAT and open it with Notepad. Add a line like the following to the very end:

 PATH C:\PROGRA%1\sun\bin;%PATH%

If you installed the SDK into some directory other than "C:\PROGRA%1\sun", replace that with the name of the directory where you installed the SDK.

Check for any lines that begin

 SET CLASSPATH=

. If you don't find any, save AUTOEXEC.BAT and reboot the computer.

[edit] editing PATH on Windows NT and 2000 and ME and XP

Choose "Start | Settings | Control Panel | System | Advanced | Environment Variables".

Edit the PATH variable. If your path *was*

 PATH c:\windows;c:\windows\system32;

and you installed the SDK into

 C:\Program Files\sun\

your new PATH should look like

 PATH C:\Program Files\sun\bin;c:\windows;c:\windows\system32;

.

Check for a CLASSPATH variable. If you don't find any, click the Apply button, then reboot the computer.


[edit] editing PATH on Linux

...

[edit] then

Then start up your chosen IDE and type the "hello world" program ...

...

compile and run ...

If you get the output "Hello, World!" then everything has been set up and is working together properly.


[edit] Java tools

Some tools (such as IDEs and, of course, the SDK) are useful even for beginners.

Other tools are not necessary, and perhaps confusing, when learning to write programs -- but people maintaining a lot of code find them useful:

Should we mention such tools in an "advanced tools and techniques" section?


Why not ? See Programming:C_plus_plus. --Panic 02:55, 4 November 2005 (UTC)

[edit] French Version Is Better

The French version is better. You could take a leaf out of its book. --Caudax 23:54, 18 September 2005 (GMT)

[edit] Maps & Collections

I disgree with the statement "Conceptually, a map is not a collection of elements. A map is an assignment of values to keys. " A Map is a collection where values are stored and retrieved by key, but it is still a collection. Unless my idea of the meaning of collections is quite wrong.

[edit] Wikibooks:Naming policy

You might want to consider the WB:NP. You current naming convention is depreciated and has several disadvantages - like it has no navigational links. Also you worthy effort is neiter considered a book nor a section inside a book. See wikistats which implements an exstensive book and section detector.

--Krischik T 07:15, 11 October 2005 (UTC)

I'd like to see us adopt the WB:NP standard. This wikibook is very small right now so it would be easy to do. We only have the following pages to rename (so it will be easier now rather than later):
Current: Becomes:
Programming:Java Java Programming
Programming:Java:Overview Java Programming/Overview
Programming:Java Foundations Java Programming/Foundation
Programming:Java Conditional Statements Java Programming/Syntax/Statements/Conditional
Programming:Java Exceptions and Inheritance Java Programming/Exceptions
Programming:Java Loop statements Java Programming/Statements/Loops
Programming:Java Collections Java Programming/Class Library/Collections
Programming:Java Comments Java Programming/Syntax/Lexical Elements/Comments
I am actually working on a proposed detailed structure/outline for the book. I'll post that after I have a chance to refine it. --djb 02:21, 28 October 2005 (UTC)

I would rather like to see more flat structure: Java Programming/Conditional Statements. This option is suggested by naming policy. --Derbeth talk 00:18, 12 November 2005 (UTC)

I agree with Derbeth. How does this look? --DavidCary 01:53, 16 January 2006 (UTC)

Current: Becomes:
Programming:Java Java
Programming:Java:Overview Java/Overview
Programming:Java Foundations Java/Foundation
Programming:Java Conditional Statements Java/Conditional Statements
Programming:Java Exceptions and Inheritance Java/Exceptions
Programming:Java Loop statements Java/Loops
Programming:Java Collections Java/Collections
Programming:Java Comments Java/Comments
Java/JavaDoc

[edit] Syntax conventions

Are there syntax/formatting conventions for this book (and other programming language books)? For example, should keywords be in monospace bold font such as if else catch throw and other program snippets in monospace; comments in italics:

if ("Java".equals(language)) // if they asked for Java
  { JavaCompilerFactory.newCompiler().compile(program); }

and within text references to keywords or variables:

Use a throws clause to indicate what exceptions a method may throw.
The catch (exception-type identifier) clause is used to define an exception handler.

--Djb 01:55, 26 October 2005 (UTC)

[edit] It has been suggested that Programming:The way of the program be merged into this book or chapter.

Programming:Java has a call for discussion on merging with Programming:The way of the program. Please post your comments about this proposal in this section.


I disagree with the proposal. I like the idea of a general purpose module such as Programming:The way of the program but, as much as I like and support Java, I do not agree that Java is "the way": there is no one way. The module on programming should be language independent; we do not want to alienate C++ or C# or Lisp or Scheme or ... programmers. --djb 03:41, 26 October 2005 (UTC)

This is a self teach/reference book for on the JAVA language. So it should NOT be merged with the general purpose module, as Djb said, there is no one way. --asm2750 9:58, 3 Nov 2005 (PST)

The title of this book is very misleading. I turned to it expecting an outline to general methods about programming, instead it is a Java textbook. While merging might not be the best way forward - the title of this book should be altered.

Conrad.Irwin 23:10, 27 February 2007 (UTC)

[edit] Proposed Book Outline

I have created a proposed outline for the module on Programming Java, see Java Programming. This outline also uses the recommended subpage structure (see Talk:Programming:Java#Wikibooks:Naming policy). (Sorry if I've violated WikiBooks etiquette; I had a hard time finding information on how WikiBooks is meant to work... This seemed to be the right way to handle this.)

Please discuss...

[edit] Additional sub-page

Please rename and incorporate Transwiki:Packages in Java into this book. Uncle G 14:37, 15 November 2005 (UTC)

Personal tools
Create a book
  • Add wiki page
  • Collections help