Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java programing style

  1. #1
    Member
    Join Date
    Dec 2012
    Posts
    127
    My Mood
    Angelic
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Java programing style

    Does each of these style have a name? I only know that the 2nd one is call " Top down" but no idea what the 1st and 3rd style call. Thanks

    public class HelloWorldV1
    {
    //main method
    public static void main(String[] args)
    {
        System.out.println("Hello, Virtual World!");
        System.out.println("It is a great day for programming.");
    }
    }

    public class HelloWorldV2
    {
    //print two lines of text
    public static void printTwoLines( )
    {
         System.out.println("Hello, Virtual World!");
         System.out.println("It is a great day for programming.")
    }
    //main method
    public static void main(String [] args)
    {
         printTwoLines();
    }
    }

    public class HelloWorldV3
    {
    //default constructor
    HelloWorldV3()
    {
    }
    //print two lines of text
    public void printTwoLines( )
    {
         System.out.println("Hello, Virtual World!");
         System.out.println("It is a great day for programming.");
    }
    //main method
    public static void main(String [] args)
    {
         HelloWorldV3 hello = new HelloWorldV3( );
         hello.printTwoLines();
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,354
    Thanks
    49
    Thanked 2,206 Times in 2,179 Posts

    Default Re: Java programing style

    One part of programming is properly formatting source code. None of the above sources are properly formatted. Nested statements should be indented to make for easier reading of the logic.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Dec 2012
    Posts
    127
    My Mood
    Angelic
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: Java programing style

    It is better now?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,354
    Thanks
    49
    Thanked 2,206 Times in 2,179 Posts

    Default Re: Java programing style

    Its closer. There should only be two statements that start in the first column: first and last.
    There should never be two }s one directly above the other.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Is AJAX related with java programing or .Net?
    By sagar124 in forum Java Theory & Questions
    Replies: 1
    Last Post: December 26th, 2012, 10:28 PM
  2. Java programing help plz!
    By qazwsx in forum Java Theory & Questions
    Replies: 1
    Last Post: July 21st, 2012, 07:01 PM
  3. need help with Doubly-Linked list programing in java
    By bulutbey in forum Algorithms & Recursion
    Replies: 3
    Last Post: August 22nd, 2011, 01:51 PM
  4. java thread programing.
    By parisa in forum Member Introductions
    Replies: 1
    Last Post: July 26th, 2011, 01:38 PM
  5. Noob that needs some clearing up with Java style programming
    By looneylu in forum Java Theory & Questions
    Replies: 3
    Last Post: January 23rd, 2011, 10:27 PM