File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes indentation help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "indentation help" Watch "indentation help" New topic

indentation help

Mohan Mehra
Ranch Hand

Joined: Jul 28, 2011
Posts: 73
String password = "root123";
args1[5] = oidName;
Connection conn = null;

look at the above lines and tell me is it the correct way of indentation. i.e., including space before and after "=" sign.
John Jai

Joined: May 31, 2011
Posts: 1776
This might interest you Indentation and Spacing
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 160

That's fine.

Check out this link: Style Guide

"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
Mohan Mehra wrote:is it the correct way of indentation* spacing

It is a commonly used way of spacing. The 'correct' way is whatever the style guide you are using says. If you don't have a style guide, then the 'correct' way is whatever style you prefer.

*Indentation is how far the first non-white space character is from the left edge.

Winston Gutkowski

Joined: Mar 17, 2011
Posts: 8927

Mohan Mehra wrote:look at the above lines and tell me is it the correct way of indentation. i.e., including space before and after "=" sign.

What you have looks fine to me.

Other than a few very general rules, such as:
1. Spacing improves readability.
2. Uses spaces for indentation, NOT tabs.
3. Follow basic naming conventions - class names start with a capital letter; most other things (fields, methods and parameters) start with a lowercase letter.
4. Be consistent.
you are probably the best person to decide what is clearest for you.

As for the links you've been given, remember that they are guidelines, NOT rules (even though they're written like rules).
Specifically, there are "rules" in those pages that I don't follow:
  • I always use ALL_CAPS for public constants.
  • I ignore most of section 3, because I simply don't agree with it (especially 3.1, which is utter nonsense).
  • I follow Sun's convention (see below) for matching braces ({}).
  • but that doesn't mean you have to.

    I will say again though - whatever you do decide, be consistent about it.

    The guidelines from Sun itself can be found here.


    Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
    Articles by Winston can be found here
    Roberto Perillo

    Joined: Dec 28, 2007
    Posts: 2271

    Winston Gutkowski wrote:The guidelines from Sun itself can be found here.

    This is exactly the code conventions that I use, with the exception that it suggests 80 columns, and I normally use at least 160.

    Cheers, Bob "John Lennon" Perillo
    SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
    subject: indentation help
    It's not a secret anymore!