
E.g.Ĥ.5 Always include a constructor (even if the body is empty).Ĥ.6 Always include superclass constructor call. Import statements explicitly naming every class are preferred over importing whole packages. Never use default (package private) access. Specify all fields and methods as either private, public, or protected. The elements of a class definition appear (if present) in the following order: package statement import statements class comment class header field definitions constructors methods.Ĥ.2 Fields may not be public (except for final fields). Do not comment obvious statements - assume your reader understands Java!Ĥ.1 Order of declarations: fields, constructors, methods.

#Objects first with java code#
In other words: they should start with the comment symbol /**.ģ.4 Code comments (only) where necessary.Ĭomments in the code should be included where the code is not obvious or difficult to understand (while preference should be given to make the code obvious or easy to understand where possible), and where it helps understanding of a method. The important thing is that a reader must be able to recognise if two version are not the same, and be able to determine which one is newer.Ĭlass and method comments must be recognised by Javadoc. This means at least between methods, but also between logical parts within a method.ģ.1 Every class has a class comment at the top.Įvery person who has contributed to the class has to be named as an author or has to be otherwise appropriately credited.Ī version number can be a simple number, a date, or other formats. Use blank lines to separate logical blocks of code. For example:Ģ.5 Always use braces in control structures.īraces are used in if-statements and loops even if the body is only a single statement.Ģ.6 Use a space before the opening brace of a control structure's block.Ģ.8 Use a blank line between methods (and constructors). The closing brace is on a separate line, aligned under the keyword that defines the block. The braces for class and method blocks are on separate lines and are at the same indentation level, for example:Ģ.4 For all other blocks, braces open at the end of a line.Īll other blocks open with braces at the end of the line that contains the keyword defining the block. numberOfItems.Ĭonstants occasionally use underscores to indicate compound identifiers: MAXIMUM_SIZEĢ.1 One level of indentation is four spaces.Ģ.2 All statements within a block are indented one level.Ģ.3 Braces for classes and methods are alone on one line.

Accessor methods with boolean return values are often called is Something(.), for example, isEmpty().ġ.2 Class names start with a capital letter.ġ.4 Method and variable names start with lowercase letters.Īll three - class, method and variable names - use capital letters in the middle to increase readability of compound identifiers, e.g.

Simple accessor methods should be named get Something(.). Simple mutator methods should be named set Something(.). We learn best by doing, and BlueJ enables the user to ‘do’.Use descriptive names for all identifiers (names of classes, variables and methods). In other words objects become real entities which can be manipulated and examined interactively in the workspace rather than abstract data structures that come and go while a program is running. It’s a workbench that enables the user to instantiate classes, run methods, interrogate fields etc. However it’s not simply a Java IDE like Eclipse, JCreator etc. BlueJ presents a clean development environment that allows the building, running and debugging of Java code. The first and more obvious thing about the book is that it is supplied with a copy of the BlueJ, the interactive programming environment designed to help teach Java.

Along with Head First Java this is also one of the few books which seems to really engage the reader and which pays close attention to how it is we best learn. It succeeds admirably in teaching both the language and the principles that underpin the language. TBR writes “Aimed clearly at a classroom audience, ‘Objects First With Java’ is a title that can be recommended to all who want an introduction to Java and/or an introduction to object oriented programming.
