Is there something wrong with my indentation?












0














This may be off topic, but a teacher of mine recently said that my indentation was incorrect but gave a very vague reason of what was wrong and I do not think anything is wrong with my indentation when I code. Below is a program I wrote and my teacher said that the indentation is annoying and incorrect to read.



    import java.util.Scanner; 

public class SecretCode {


public static boolean isValidLength (String stringChecker) // Checks to see is user the String that was input by the user is valid.
{
if (stringChecker.length() >= 2 && stringChecker.length() <= 12) // Determines how long the String is.
{
return true; // It is valid.
}
else
{
return false; // It is invalid.
}
}

public static int charToAscii (String stringToAscii) // Converts the String inputted by the user and converts it to an Ascii value. The values are stored and return as an int.
{
int stringValue = 0;
for (int x = 0; x < stringToAscii.length(); x++) // Loop to parse through the String and add all the Ascii values.
{
stringValue += (int) stringToAscii.charAt(x); // Adder.
}

return stringValue; // Returns final value of String.
}

public static int getNumDigits (int totalDigits) // Gets the total number of digits in an int.
{
return (int) (Math.log10(totalDigits) + 1); // This will return the total amount of digits using a logarithmic function You can also do String.valueOf(totalDigits).length();
}

public static String getSecretCode (int secretCodeConversion) // Converts Ascii values into two separate characters.
{
String secretCode = new String (); // String instantiation. Proper syntax for declaring a String. There is not

int num1, num2; // Variable declaration

num1 = (secretCodeConversion % 10000) / 100; // Splits the numbers into two. This gets first two digits.
num2 = (secretCodeConversion % 100); // Second two digits.

if (num1 <= 65)
{
num1 += 61; // Ensures a letter is possible.
}
if (num2 <= 65)
{
num2 += 61; // Ensures a letter is possible for num2. This could have been short-circuited by an 'or' operator.
}

secretCode += Character.toString((char) num1) + Character.toString((char) num2); // Concatenates the two numbers back into a String.

return secretCode; // Return secret code.
}


public static void main(String args) {
String secretCode = new String (); // User input
Scanner sc = new Scanner (System.in); // Instantiates Scanner object to read input.
System.out.println ("Please enter the String you would like to make a secret code?");
secretCode = sc.next(); // Input

while (isValidLength(secretCode) == false) // Checks to see low long secret message it is to make sure it is valid.
{
System.out.println ("Please enter the String you would like to make a secret code?");
secretCode = sc.next(); // Loops until true.
}

sc.close(); // No more need for Scanner.

int sumOfDigits = charToAscii(secretCode); // Data for output requirements.

if (getNumDigits(sumOfDigits) % 2 != 0)
{
sumOfDigits *= 10;
}

if (sumOfDigits <= 4000)
{
sumOfDigits *= 4;
}

if (getNumDigits(sumOfDigits) % 2 != 0)
{
sumOfDigits /= 10;
}

System.out.println();
System.out.println();

System.out.println ("Your Secret Coded Message Is: " + getSecretCode(sumOfDigits));

System.out.println();
System.out.println();

System.out.println ("Additional Data:");
System.out.println ("_______________________");

System.out.println ("String Input: " + '"' + secretCode + '"');
System.out.println ("Sum of Ascii Codes: " + charToAscii(secretCode));
System.out.println ("Secret Code in Ascii Numbers " + sumOfDigits);
}
} // This bracket is part of the code, but I could not get the formatting to work.


My teacher said that everything was on the left border, but I believe the things that are on the left border do not have any other place to go. I have looked at other programmers and I have looked at other Java code on Github and I think I am doing everything correctly. I do not know what she was talking about?










share|improve this question




















  • 4




    All of your methods need to be indented. They shouldn't be at the same indentation level as public class SecretCode {
    – Carcigenicate
    Nov 19 '18 at 14:52






  • 3




    As long as it's consistent, hard to disagree. Most IDEs will have an automatic formatting tool you can configure and apply by the way.
    – Mena
    Nov 19 '18 at 14:52










  • @Carcigenicate That is a StackOverFlow Error. In the actual IDE and what was checked, those methods were initially indented.
    – Hasnain Ali
    Nov 19 '18 at 14:54






  • 1




    Unless he noticed that you're mixing tabs and spaces, which is hard to tell here.
    – Carcigenicate
    Nov 19 '18 at 14:56






  • 1




    Why didn't you ask your teacher!? It's his/her job to teach you - why not ask "can you tell me exactly what's wrong with my indentation, and what I should do to fix it?" It's hard for people here to read your teacher's mind! If the teacher can't explain the problem to you, then consider trying to acquire a new teacher.
    – DaveyDaveDave
    Nov 19 '18 at 15:35


















0














This may be off topic, but a teacher of mine recently said that my indentation was incorrect but gave a very vague reason of what was wrong and I do not think anything is wrong with my indentation when I code. Below is a program I wrote and my teacher said that the indentation is annoying and incorrect to read.



    import java.util.Scanner; 

public class SecretCode {


public static boolean isValidLength (String stringChecker) // Checks to see is user the String that was input by the user is valid.
{
if (stringChecker.length() >= 2 && stringChecker.length() <= 12) // Determines how long the String is.
{
return true; // It is valid.
}
else
{
return false; // It is invalid.
}
}

public static int charToAscii (String stringToAscii) // Converts the String inputted by the user and converts it to an Ascii value. The values are stored and return as an int.
{
int stringValue = 0;
for (int x = 0; x < stringToAscii.length(); x++) // Loop to parse through the String and add all the Ascii values.
{
stringValue += (int) stringToAscii.charAt(x); // Adder.
}

return stringValue; // Returns final value of String.
}

public static int getNumDigits (int totalDigits) // Gets the total number of digits in an int.
{
return (int) (Math.log10(totalDigits) + 1); // This will return the total amount of digits using a logarithmic function You can also do String.valueOf(totalDigits).length();
}

public static String getSecretCode (int secretCodeConversion) // Converts Ascii values into two separate characters.
{
String secretCode = new String (); // String instantiation. Proper syntax for declaring a String. There is not

int num1, num2; // Variable declaration

num1 = (secretCodeConversion % 10000) / 100; // Splits the numbers into two. This gets first two digits.
num2 = (secretCodeConversion % 100); // Second two digits.

if (num1 <= 65)
{
num1 += 61; // Ensures a letter is possible.
}
if (num2 <= 65)
{
num2 += 61; // Ensures a letter is possible for num2. This could have been short-circuited by an 'or' operator.
}

secretCode += Character.toString((char) num1) + Character.toString((char) num2); // Concatenates the two numbers back into a String.

return secretCode; // Return secret code.
}


public static void main(String args) {
String secretCode = new String (); // User input
Scanner sc = new Scanner (System.in); // Instantiates Scanner object to read input.
System.out.println ("Please enter the String you would like to make a secret code?");
secretCode = sc.next(); // Input

while (isValidLength(secretCode) == false) // Checks to see low long secret message it is to make sure it is valid.
{
System.out.println ("Please enter the String you would like to make a secret code?");
secretCode = sc.next(); // Loops until true.
}

sc.close(); // No more need for Scanner.

int sumOfDigits = charToAscii(secretCode); // Data for output requirements.

if (getNumDigits(sumOfDigits) % 2 != 0)
{
sumOfDigits *= 10;
}

if (sumOfDigits <= 4000)
{
sumOfDigits *= 4;
}

if (getNumDigits(sumOfDigits) % 2 != 0)
{
sumOfDigits /= 10;
}

System.out.println();
System.out.println();

System.out.println ("Your Secret Coded Message Is: " + getSecretCode(sumOfDigits));

System.out.println();
System.out.println();

System.out.println ("Additional Data:");
System.out.println ("_______________________");

System.out.println ("String Input: " + '"' + secretCode + '"');
System.out.println ("Sum of Ascii Codes: " + charToAscii(secretCode));
System.out.println ("Secret Code in Ascii Numbers " + sumOfDigits);
}
} // This bracket is part of the code, but I could not get the formatting to work.


My teacher said that everything was on the left border, but I believe the things that are on the left border do not have any other place to go. I have looked at other programmers and I have looked at other Java code on Github and I think I am doing everything correctly. I do not know what she was talking about?










share|improve this question




















  • 4




    All of your methods need to be indented. They shouldn't be at the same indentation level as public class SecretCode {
    – Carcigenicate
    Nov 19 '18 at 14:52






  • 3




    As long as it's consistent, hard to disagree. Most IDEs will have an automatic formatting tool you can configure and apply by the way.
    – Mena
    Nov 19 '18 at 14:52










  • @Carcigenicate That is a StackOverFlow Error. In the actual IDE and what was checked, those methods were initially indented.
    – Hasnain Ali
    Nov 19 '18 at 14:54






  • 1




    Unless he noticed that you're mixing tabs and spaces, which is hard to tell here.
    – Carcigenicate
    Nov 19 '18 at 14:56






  • 1




    Why didn't you ask your teacher!? It's his/her job to teach you - why not ask "can you tell me exactly what's wrong with my indentation, and what I should do to fix it?" It's hard for people here to read your teacher's mind! If the teacher can't explain the problem to you, then consider trying to acquire a new teacher.
    – DaveyDaveDave
    Nov 19 '18 at 15:35
















0












0








0







This may be off topic, but a teacher of mine recently said that my indentation was incorrect but gave a very vague reason of what was wrong and I do not think anything is wrong with my indentation when I code. Below is a program I wrote and my teacher said that the indentation is annoying and incorrect to read.



    import java.util.Scanner; 

public class SecretCode {


public static boolean isValidLength (String stringChecker) // Checks to see is user the String that was input by the user is valid.
{
if (stringChecker.length() >= 2 && stringChecker.length() <= 12) // Determines how long the String is.
{
return true; // It is valid.
}
else
{
return false; // It is invalid.
}
}

public static int charToAscii (String stringToAscii) // Converts the String inputted by the user and converts it to an Ascii value. The values are stored and return as an int.
{
int stringValue = 0;
for (int x = 0; x < stringToAscii.length(); x++) // Loop to parse through the String and add all the Ascii values.
{
stringValue += (int) stringToAscii.charAt(x); // Adder.
}

return stringValue; // Returns final value of String.
}

public static int getNumDigits (int totalDigits) // Gets the total number of digits in an int.
{
return (int) (Math.log10(totalDigits) + 1); // This will return the total amount of digits using a logarithmic function You can also do String.valueOf(totalDigits).length();
}

public static String getSecretCode (int secretCodeConversion) // Converts Ascii values into two separate characters.
{
String secretCode = new String (); // String instantiation. Proper syntax for declaring a String. There is not

int num1, num2; // Variable declaration

num1 = (secretCodeConversion % 10000) / 100; // Splits the numbers into two. This gets first two digits.
num2 = (secretCodeConversion % 100); // Second two digits.

if (num1 <= 65)
{
num1 += 61; // Ensures a letter is possible.
}
if (num2 <= 65)
{
num2 += 61; // Ensures a letter is possible for num2. This could have been short-circuited by an 'or' operator.
}

secretCode += Character.toString((char) num1) + Character.toString((char) num2); // Concatenates the two numbers back into a String.

return secretCode; // Return secret code.
}


public static void main(String args) {
String secretCode = new String (); // User input
Scanner sc = new Scanner (System.in); // Instantiates Scanner object to read input.
System.out.println ("Please enter the String you would like to make a secret code?");
secretCode = sc.next(); // Input

while (isValidLength(secretCode) == false) // Checks to see low long secret message it is to make sure it is valid.
{
System.out.println ("Please enter the String you would like to make a secret code?");
secretCode = sc.next(); // Loops until true.
}

sc.close(); // No more need for Scanner.

int sumOfDigits = charToAscii(secretCode); // Data for output requirements.

if (getNumDigits(sumOfDigits) % 2 != 0)
{
sumOfDigits *= 10;
}

if (sumOfDigits <= 4000)
{
sumOfDigits *= 4;
}

if (getNumDigits(sumOfDigits) % 2 != 0)
{
sumOfDigits /= 10;
}

System.out.println();
System.out.println();

System.out.println ("Your Secret Coded Message Is: " + getSecretCode(sumOfDigits));

System.out.println();
System.out.println();

System.out.println ("Additional Data:");
System.out.println ("_______________________");

System.out.println ("String Input: " + '"' + secretCode + '"');
System.out.println ("Sum of Ascii Codes: " + charToAscii(secretCode));
System.out.println ("Secret Code in Ascii Numbers " + sumOfDigits);
}
} // This bracket is part of the code, but I could not get the formatting to work.


My teacher said that everything was on the left border, but I believe the things that are on the left border do not have any other place to go. I have looked at other programmers and I have looked at other Java code on Github and I think I am doing everything correctly. I do not know what she was talking about?










share|improve this question















This may be off topic, but a teacher of mine recently said that my indentation was incorrect but gave a very vague reason of what was wrong and I do not think anything is wrong with my indentation when I code. Below is a program I wrote and my teacher said that the indentation is annoying and incorrect to read.



    import java.util.Scanner; 

public class SecretCode {


public static boolean isValidLength (String stringChecker) // Checks to see is user the String that was input by the user is valid.
{
if (stringChecker.length() >= 2 && stringChecker.length() <= 12) // Determines how long the String is.
{
return true; // It is valid.
}
else
{
return false; // It is invalid.
}
}

public static int charToAscii (String stringToAscii) // Converts the String inputted by the user and converts it to an Ascii value. The values are stored and return as an int.
{
int stringValue = 0;
for (int x = 0; x < stringToAscii.length(); x++) // Loop to parse through the String and add all the Ascii values.
{
stringValue += (int) stringToAscii.charAt(x); // Adder.
}

return stringValue; // Returns final value of String.
}

public static int getNumDigits (int totalDigits) // Gets the total number of digits in an int.
{
return (int) (Math.log10(totalDigits) + 1); // This will return the total amount of digits using a logarithmic function You can also do String.valueOf(totalDigits).length();
}

public static String getSecretCode (int secretCodeConversion) // Converts Ascii values into two separate characters.
{
String secretCode = new String (); // String instantiation. Proper syntax for declaring a String. There is not

int num1, num2; // Variable declaration

num1 = (secretCodeConversion % 10000) / 100; // Splits the numbers into two. This gets first two digits.
num2 = (secretCodeConversion % 100); // Second two digits.

if (num1 <= 65)
{
num1 += 61; // Ensures a letter is possible.
}
if (num2 <= 65)
{
num2 += 61; // Ensures a letter is possible for num2. This could have been short-circuited by an 'or' operator.
}

secretCode += Character.toString((char) num1) + Character.toString((char) num2); // Concatenates the two numbers back into a String.

return secretCode; // Return secret code.
}


public static void main(String args) {
String secretCode = new String (); // User input
Scanner sc = new Scanner (System.in); // Instantiates Scanner object to read input.
System.out.println ("Please enter the String you would like to make a secret code?");
secretCode = sc.next(); // Input

while (isValidLength(secretCode) == false) // Checks to see low long secret message it is to make sure it is valid.
{
System.out.println ("Please enter the String you would like to make a secret code?");
secretCode = sc.next(); // Loops until true.
}

sc.close(); // No more need for Scanner.

int sumOfDigits = charToAscii(secretCode); // Data for output requirements.

if (getNumDigits(sumOfDigits) % 2 != 0)
{
sumOfDigits *= 10;
}

if (sumOfDigits <= 4000)
{
sumOfDigits *= 4;
}

if (getNumDigits(sumOfDigits) % 2 != 0)
{
sumOfDigits /= 10;
}

System.out.println();
System.out.println();

System.out.println ("Your Secret Coded Message Is: " + getSecretCode(sumOfDigits));

System.out.println();
System.out.println();

System.out.println ("Additional Data:");
System.out.println ("_______________________");

System.out.println ("String Input: " + '"' + secretCode + '"');
System.out.println ("Sum of Ascii Codes: " + charToAscii(secretCode));
System.out.println ("Secret Code in Ascii Numbers " + sumOfDigits);
}
} // This bracket is part of the code, but I could not get the formatting to work.


My teacher said that everything was on the left border, but I believe the things that are on the left border do not have any other place to go. I have looked at other programmers and I have looked at other Java code on Github and I think I am doing everything correctly. I do not know what she was talking about?







java indentation code-formatting






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 16:13









Raf

4,48611835




4,48611835










asked Nov 19 '18 at 14:50









Hasnain Ali

283




283








  • 4




    All of your methods need to be indented. They shouldn't be at the same indentation level as public class SecretCode {
    – Carcigenicate
    Nov 19 '18 at 14:52






  • 3




    As long as it's consistent, hard to disagree. Most IDEs will have an automatic formatting tool you can configure and apply by the way.
    – Mena
    Nov 19 '18 at 14:52










  • @Carcigenicate That is a StackOverFlow Error. In the actual IDE and what was checked, those methods were initially indented.
    – Hasnain Ali
    Nov 19 '18 at 14:54






  • 1




    Unless he noticed that you're mixing tabs and spaces, which is hard to tell here.
    – Carcigenicate
    Nov 19 '18 at 14:56






  • 1




    Why didn't you ask your teacher!? It's his/her job to teach you - why not ask "can you tell me exactly what's wrong with my indentation, and what I should do to fix it?" It's hard for people here to read your teacher's mind! If the teacher can't explain the problem to you, then consider trying to acquire a new teacher.
    – DaveyDaveDave
    Nov 19 '18 at 15:35
















  • 4




    All of your methods need to be indented. They shouldn't be at the same indentation level as public class SecretCode {
    – Carcigenicate
    Nov 19 '18 at 14:52






  • 3




    As long as it's consistent, hard to disagree. Most IDEs will have an automatic formatting tool you can configure and apply by the way.
    – Mena
    Nov 19 '18 at 14:52










  • @Carcigenicate That is a StackOverFlow Error. In the actual IDE and what was checked, those methods were initially indented.
    – Hasnain Ali
    Nov 19 '18 at 14:54






  • 1




    Unless he noticed that you're mixing tabs and spaces, which is hard to tell here.
    – Carcigenicate
    Nov 19 '18 at 14:56






  • 1




    Why didn't you ask your teacher!? It's his/her job to teach you - why not ask "can you tell me exactly what's wrong with my indentation, and what I should do to fix it?" It's hard for people here to read your teacher's mind! If the teacher can't explain the problem to you, then consider trying to acquire a new teacher.
    – DaveyDaveDave
    Nov 19 '18 at 15:35










4




4




All of your methods need to be indented. They shouldn't be at the same indentation level as public class SecretCode {
– Carcigenicate
Nov 19 '18 at 14:52




All of your methods need to be indented. They shouldn't be at the same indentation level as public class SecretCode {
– Carcigenicate
Nov 19 '18 at 14:52




3




3




As long as it's consistent, hard to disagree. Most IDEs will have an automatic formatting tool you can configure and apply by the way.
– Mena
Nov 19 '18 at 14:52




As long as it's consistent, hard to disagree. Most IDEs will have an automatic formatting tool you can configure and apply by the way.
– Mena
Nov 19 '18 at 14:52












@Carcigenicate That is a StackOverFlow Error. In the actual IDE and what was checked, those methods were initially indented.
– Hasnain Ali
Nov 19 '18 at 14:54




@Carcigenicate That is a StackOverFlow Error. In the actual IDE and what was checked, those methods were initially indented.
– Hasnain Ali
Nov 19 '18 at 14:54




1




1




Unless he noticed that you're mixing tabs and spaces, which is hard to tell here.
– Carcigenicate
Nov 19 '18 at 14:56




Unless he noticed that you're mixing tabs and spaces, which is hard to tell here.
– Carcigenicate
Nov 19 '18 at 14:56




1




1




Why didn't you ask your teacher!? It's his/her job to teach you - why not ask "can you tell me exactly what's wrong with my indentation, and what I should do to fix it?" It's hard for people here to read your teacher's mind! If the teacher can't explain the problem to you, then consider trying to acquire a new teacher.
– DaveyDaveDave
Nov 19 '18 at 15:35






Why didn't you ask your teacher!? It's his/her job to teach you - why not ask "can you tell me exactly what's wrong with my indentation, and what I should do to fix it?" It's hard for people here to read your teacher's mind! If the teacher can't explain the problem to you, then consider trying to acquire a new teacher.
– DaveyDaveDave
Nov 19 '18 at 15:35














3 Answers
3






active

oldest

votes


















2














Not long ago, I reviewed the Java Coding Conventions from companies like Oracle, Google, Twitter and Spring. Surprisingly there is quite a bit to say when it comes to indentation and formatting and here is a brief summary and useful links that could help you write easy to read and maintainable code.



I wrote a short article about java coding best practices for those interested to read more.




  1. 2-4 spaces for indentation (Google recommends +2 spaces)

  2. Line length range recommended should be between 70 to 120 (max)

  3. When it comes to wrapping lines break after comma and before an operator

  4. Keep the opening brace { at the end of same line as signature of the method and keywords (i.e. if, for, etc keywords)

  5. Use end of line comments // only when you have a few words to say about the line. If the length of the comment is more than a few words you should make use of /* */ or /* */ for multi line comment

  6. When the method signature is long then break to new line and use 8 spaces to differentiate between method arguments and method body

  7. Declare each variable in its own line rather than int i,j,k;

  8. No space between method name and parenthesis ( however, there should be 1 space between reserved keywords (i.e. if, for) and the parenthesis - this would help easily visually differentiate between method and other constructs

  9. Methods are separated by a blank line

  10. A blank space should appear after a comma in argument list

  11. space pad operators (i.e. +,-,%, etc.) and=`

  12. Many more - please see the links below


Here is your code using some of the above points



import java.util.Scanner; 

public class SecretCode {

// Checks to see is user the String that was input by the user is valid.

public static boolean isValidLength(String stringChecker) {
// Determines length check
if ((stringChecker.length() >= 2) && (stringChecker.length() <= 12)) {
return true;
} else {
return false;
}
}

/*
* Converts the String inputted by the user and converts it to an Ascii value.
* The values are stored and return as an int.
*/
public static int charToAscii (String stringToAscii) {
int stringValue = 0;

// Loop to parse through the String and add all the Ascii values.

for (int x = 0; x < stringToAscii.length(); x++) {
stringValue += (int) stringToAscii.charAt(x); // Adder.
}

return stringValue;
}

/*
* Gets the total number of digits in an int.
* This will return the total amount of digits using a logarithmic function You
* can also do String.valueOf(totalDigits).length();
*/

public static int getNumDigits (int totalDigits) {
return (int) (Math.log10(totalDigits) + 1);
}

// Converts Ascii values into two separate characters.

public static String getSecretCode (int secretCodeConversion) {
String secretCode = new String ();

// Splits the numbers into two. This gets first two digits
int num1 = (secretCodeConversion % 10000) / 100;

// Second two digits - use proper variable naming i.e. firstTwoDigits, secondDigits etc.
int num2 = (secretCodeConversion % 100);

if (num1 <= 65) {
num1 += 61; // Ensures a letter is possible.
}
if (num2 <= 65) {
// Ensures a letter is possible for num2. This could have been short-circuited by an 'or' operator.
num2 += 61;
}

secretCode += Character.toString((char) num1) + Character.toString((char) num2);

return secretCode;
}

public static void main(String args) {
String secretCode = new String ();

// Instantiates Scanner object to read input.
Scanner sc = new Scanner (System.in);

System.out.println ("Please enter the String you would like to make a secret code?");
secretCode = sc.next();

// Checks to see low long secret message it is to make sure it is valid.

while (isValidLength(secretCode) == false) {
System.out.println ("Please enter the String you would like to make a secret code?");
secretCode = sc.next(); // Loops until true.
}

sc.close(); // No more need for Scanner.

int sumOfDigits = charToAscii(secretCode);

if (getNumDigits(sumOfDigits) % 2 != 0) {
sumOfDigits *= 10;
}

if (sumOfDigits <= 4000) {
sumOfDigits *= 4;
}

if (getNumDigits(sumOfDigits) % 2 != 0) {
sumOfDigits /= 10;
}

System.out.println();
System.out.println();

System.out.println ("Your Secret Coded Message Is: " + getSecretCode(sumOfDigits));

System.out.println();
System.out.println();

System.out.println ("Additional Data:");
System.out.println ("_______________________");

System.out.println ("String Input: " + '"' + secretCode + '"');
System.out.println ("Sum of Ascii Codes: " + charToAscii(secretCode));
System.out.println ("Secret Code in Ascii Numbers " + sumOfDigits);
}
}


Here are things you could improve in your code




  • Over-commented - sometimes it's clear what a line is doing don't add comment, only add comment when the code is complex and it's hard to read

  • Variable naming, make it easy to understand what a variable is storing

  • Indentation

  • Use of type of comment

  • Lack of javadoc comments


There are many positives in your code too. I like the method naming, the way you have divided it into methods. You are on right path, read some of the following coding conventions for java and you are all set.



Oracle Java Style Guide - https://www.oracle.com/technetwork/java/codeconventions-150003.pdf



Google Java Style Guide - https://google.github.io/styleguide/javaguide.html



Spring Framework Style Guide - https://github.com/spring-projects/spring-framework/wiki/Code-Style



Twitter Java Style Guide - https://github.com/twitter/commons/blob/master/src/java/com/twitter/common/styleguide.md






share|improve this answer



















  • 1




    Subjective, but indentation is probably better to be 2 spaces. Seems to be the most common defacto standard nowadays (also Google's Java Style). 2 spaces helps you abide to the max 120 line length more easily (most IDEs include indent as part of it). Also 2 spaces helps you see the code without horizontal scrolling in 3-way diffs while merging conflicts.
    – jbx
    Nov 19 '18 at 15:36










  • IMO something in between 2-4 spaces is way to go. I did notice that Google recommended +2 spaces and some other companies use 4 spaces. I have shared links to a few of the companies coding guidelines that matter (so we are not biased to one)
    – Raf
    Nov 19 '18 at 16:09



















0














Your methods are not indented inside the class. They seem to be in the same level as the class on your code. The other method level indentation looks fine. Try to format it in your IDE and you will see the difference. The structure should be similar to below.



class Order
{
// fields

// constructors

// methods
}





share|improve this answer





























    -1














    Indentation is a particular standard that we follow across code in all classes uniformly. To start with I can say




    1. Your commenting style is not readable in screen width.

    2. The start and closing for flower brackets is not same across ex: see main method.


    Having said that anybody can have their own style of formatting and indenting there is nothing wrong with it.






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377133%2fis-there-something-wrong-with-my-indentation%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      Not long ago, I reviewed the Java Coding Conventions from companies like Oracle, Google, Twitter and Spring. Surprisingly there is quite a bit to say when it comes to indentation and formatting and here is a brief summary and useful links that could help you write easy to read and maintainable code.



      I wrote a short article about java coding best practices for those interested to read more.




      1. 2-4 spaces for indentation (Google recommends +2 spaces)

      2. Line length range recommended should be between 70 to 120 (max)

      3. When it comes to wrapping lines break after comma and before an operator

      4. Keep the opening brace { at the end of same line as signature of the method and keywords (i.e. if, for, etc keywords)

      5. Use end of line comments // only when you have a few words to say about the line. If the length of the comment is more than a few words you should make use of /* */ or /* */ for multi line comment

      6. When the method signature is long then break to new line and use 8 spaces to differentiate between method arguments and method body

      7. Declare each variable in its own line rather than int i,j,k;

      8. No space between method name and parenthesis ( however, there should be 1 space between reserved keywords (i.e. if, for) and the parenthesis - this would help easily visually differentiate between method and other constructs

      9. Methods are separated by a blank line

      10. A blank space should appear after a comma in argument list

      11. space pad operators (i.e. +,-,%, etc.) and=`

      12. Many more - please see the links below


      Here is your code using some of the above points



      import java.util.Scanner; 

      public class SecretCode {

      // Checks to see is user the String that was input by the user is valid.

      public static boolean isValidLength(String stringChecker) {
      // Determines length check
      if ((stringChecker.length() >= 2) && (stringChecker.length() <= 12)) {
      return true;
      } else {
      return false;
      }
      }

      /*
      * Converts the String inputted by the user and converts it to an Ascii value.
      * The values are stored and return as an int.
      */
      public static int charToAscii (String stringToAscii) {
      int stringValue = 0;

      // Loop to parse through the String and add all the Ascii values.

      for (int x = 0; x < stringToAscii.length(); x++) {
      stringValue += (int) stringToAscii.charAt(x); // Adder.
      }

      return stringValue;
      }

      /*
      * Gets the total number of digits in an int.
      * This will return the total amount of digits using a logarithmic function You
      * can also do String.valueOf(totalDigits).length();
      */

      public static int getNumDigits (int totalDigits) {
      return (int) (Math.log10(totalDigits) + 1);
      }

      // Converts Ascii values into two separate characters.

      public static String getSecretCode (int secretCodeConversion) {
      String secretCode = new String ();

      // Splits the numbers into two. This gets first two digits
      int num1 = (secretCodeConversion % 10000) / 100;

      // Second two digits - use proper variable naming i.e. firstTwoDigits, secondDigits etc.
      int num2 = (secretCodeConversion % 100);

      if (num1 <= 65) {
      num1 += 61; // Ensures a letter is possible.
      }
      if (num2 <= 65) {
      // Ensures a letter is possible for num2. This could have been short-circuited by an 'or' operator.
      num2 += 61;
      }

      secretCode += Character.toString((char) num1) + Character.toString((char) num2);

      return secretCode;
      }

      public static void main(String args) {
      String secretCode = new String ();

      // Instantiates Scanner object to read input.
      Scanner sc = new Scanner (System.in);

      System.out.println ("Please enter the String you would like to make a secret code?");
      secretCode = sc.next();

      // Checks to see low long secret message it is to make sure it is valid.

      while (isValidLength(secretCode) == false) {
      System.out.println ("Please enter the String you would like to make a secret code?");
      secretCode = sc.next(); // Loops until true.
      }

      sc.close(); // No more need for Scanner.

      int sumOfDigits = charToAscii(secretCode);

      if (getNumDigits(sumOfDigits) % 2 != 0) {
      sumOfDigits *= 10;
      }

      if (sumOfDigits <= 4000) {
      sumOfDigits *= 4;
      }

      if (getNumDigits(sumOfDigits) % 2 != 0) {
      sumOfDigits /= 10;
      }

      System.out.println();
      System.out.println();

      System.out.println ("Your Secret Coded Message Is: " + getSecretCode(sumOfDigits));

      System.out.println();
      System.out.println();

      System.out.println ("Additional Data:");
      System.out.println ("_______________________");

      System.out.println ("String Input: " + '"' + secretCode + '"');
      System.out.println ("Sum of Ascii Codes: " + charToAscii(secretCode));
      System.out.println ("Secret Code in Ascii Numbers " + sumOfDigits);
      }
      }


      Here are things you could improve in your code




      • Over-commented - sometimes it's clear what a line is doing don't add comment, only add comment when the code is complex and it's hard to read

      • Variable naming, make it easy to understand what a variable is storing

      • Indentation

      • Use of type of comment

      • Lack of javadoc comments


      There are many positives in your code too. I like the method naming, the way you have divided it into methods. You are on right path, read some of the following coding conventions for java and you are all set.



      Oracle Java Style Guide - https://www.oracle.com/technetwork/java/codeconventions-150003.pdf



      Google Java Style Guide - https://google.github.io/styleguide/javaguide.html



      Spring Framework Style Guide - https://github.com/spring-projects/spring-framework/wiki/Code-Style



      Twitter Java Style Guide - https://github.com/twitter/commons/blob/master/src/java/com/twitter/common/styleguide.md






      share|improve this answer



















      • 1




        Subjective, but indentation is probably better to be 2 spaces. Seems to be the most common defacto standard nowadays (also Google's Java Style). 2 spaces helps you abide to the max 120 line length more easily (most IDEs include indent as part of it). Also 2 spaces helps you see the code without horizontal scrolling in 3-way diffs while merging conflicts.
        – jbx
        Nov 19 '18 at 15:36










      • IMO something in between 2-4 spaces is way to go. I did notice that Google recommended +2 spaces and some other companies use 4 spaces. I have shared links to a few of the companies coding guidelines that matter (so we are not biased to one)
        – Raf
        Nov 19 '18 at 16:09
















      2














      Not long ago, I reviewed the Java Coding Conventions from companies like Oracle, Google, Twitter and Spring. Surprisingly there is quite a bit to say when it comes to indentation and formatting and here is a brief summary and useful links that could help you write easy to read and maintainable code.



      I wrote a short article about java coding best practices for those interested to read more.




      1. 2-4 spaces for indentation (Google recommends +2 spaces)

      2. Line length range recommended should be between 70 to 120 (max)

      3. When it comes to wrapping lines break after comma and before an operator

      4. Keep the opening brace { at the end of same line as signature of the method and keywords (i.e. if, for, etc keywords)

      5. Use end of line comments // only when you have a few words to say about the line. If the length of the comment is more than a few words you should make use of /* */ or /* */ for multi line comment

      6. When the method signature is long then break to new line and use 8 spaces to differentiate between method arguments and method body

      7. Declare each variable in its own line rather than int i,j,k;

      8. No space between method name and parenthesis ( however, there should be 1 space between reserved keywords (i.e. if, for) and the parenthesis - this would help easily visually differentiate between method and other constructs

      9. Methods are separated by a blank line

      10. A blank space should appear after a comma in argument list

      11. space pad operators (i.e. +,-,%, etc.) and=`

      12. Many more - please see the links below


      Here is your code using some of the above points



      import java.util.Scanner; 

      public class SecretCode {

      // Checks to see is user the String that was input by the user is valid.

      public static boolean isValidLength(String stringChecker) {
      // Determines length check
      if ((stringChecker.length() >= 2) && (stringChecker.length() <= 12)) {
      return true;
      } else {
      return false;
      }
      }

      /*
      * Converts the String inputted by the user and converts it to an Ascii value.
      * The values are stored and return as an int.
      */
      public static int charToAscii (String stringToAscii) {
      int stringValue = 0;

      // Loop to parse through the String and add all the Ascii values.

      for (int x = 0; x < stringToAscii.length(); x++) {
      stringValue += (int) stringToAscii.charAt(x); // Adder.
      }

      return stringValue;
      }

      /*
      * Gets the total number of digits in an int.
      * This will return the total amount of digits using a logarithmic function You
      * can also do String.valueOf(totalDigits).length();
      */

      public static int getNumDigits (int totalDigits) {
      return (int) (Math.log10(totalDigits) + 1);
      }

      // Converts Ascii values into two separate characters.

      public static String getSecretCode (int secretCodeConversion) {
      String secretCode = new String ();

      // Splits the numbers into two. This gets first two digits
      int num1 = (secretCodeConversion % 10000) / 100;

      // Second two digits - use proper variable naming i.e. firstTwoDigits, secondDigits etc.
      int num2 = (secretCodeConversion % 100);

      if (num1 <= 65) {
      num1 += 61; // Ensures a letter is possible.
      }
      if (num2 <= 65) {
      // Ensures a letter is possible for num2. This could have been short-circuited by an 'or' operator.
      num2 += 61;
      }

      secretCode += Character.toString((char) num1) + Character.toString((char) num2);

      return secretCode;
      }

      public static void main(String args) {
      String secretCode = new String ();

      // Instantiates Scanner object to read input.
      Scanner sc = new Scanner (System.in);

      System.out.println ("Please enter the String you would like to make a secret code?");
      secretCode = sc.next();

      // Checks to see low long secret message it is to make sure it is valid.

      while (isValidLength(secretCode) == false) {
      System.out.println ("Please enter the String you would like to make a secret code?");
      secretCode = sc.next(); // Loops until true.
      }

      sc.close(); // No more need for Scanner.

      int sumOfDigits = charToAscii(secretCode);

      if (getNumDigits(sumOfDigits) % 2 != 0) {
      sumOfDigits *= 10;
      }

      if (sumOfDigits <= 4000) {
      sumOfDigits *= 4;
      }

      if (getNumDigits(sumOfDigits) % 2 != 0) {
      sumOfDigits /= 10;
      }

      System.out.println();
      System.out.println();

      System.out.println ("Your Secret Coded Message Is: " + getSecretCode(sumOfDigits));

      System.out.println();
      System.out.println();

      System.out.println ("Additional Data:");
      System.out.println ("_______________________");

      System.out.println ("String Input: " + '"' + secretCode + '"');
      System.out.println ("Sum of Ascii Codes: " + charToAscii(secretCode));
      System.out.println ("Secret Code in Ascii Numbers " + sumOfDigits);
      }
      }


      Here are things you could improve in your code




      • Over-commented - sometimes it's clear what a line is doing don't add comment, only add comment when the code is complex and it's hard to read

      • Variable naming, make it easy to understand what a variable is storing

      • Indentation

      • Use of type of comment

      • Lack of javadoc comments


      There are many positives in your code too. I like the method naming, the way you have divided it into methods. You are on right path, read some of the following coding conventions for java and you are all set.



      Oracle Java Style Guide - https://www.oracle.com/technetwork/java/codeconventions-150003.pdf



      Google Java Style Guide - https://google.github.io/styleguide/javaguide.html



      Spring Framework Style Guide - https://github.com/spring-projects/spring-framework/wiki/Code-Style



      Twitter Java Style Guide - https://github.com/twitter/commons/blob/master/src/java/com/twitter/common/styleguide.md






      share|improve this answer



















      • 1




        Subjective, but indentation is probably better to be 2 spaces. Seems to be the most common defacto standard nowadays (also Google's Java Style). 2 spaces helps you abide to the max 120 line length more easily (most IDEs include indent as part of it). Also 2 spaces helps you see the code without horizontal scrolling in 3-way diffs while merging conflicts.
        – jbx
        Nov 19 '18 at 15:36










      • IMO something in between 2-4 spaces is way to go. I did notice that Google recommended +2 spaces and some other companies use 4 spaces. I have shared links to a few of the companies coding guidelines that matter (so we are not biased to one)
        – Raf
        Nov 19 '18 at 16:09














      2












      2








      2






      Not long ago, I reviewed the Java Coding Conventions from companies like Oracle, Google, Twitter and Spring. Surprisingly there is quite a bit to say when it comes to indentation and formatting and here is a brief summary and useful links that could help you write easy to read and maintainable code.



      I wrote a short article about java coding best practices for those interested to read more.




      1. 2-4 spaces for indentation (Google recommends +2 spaces)

      2. Line length range recommended should be between 70 to 120 (max)

      3. When it comes to wrapping lines break after comma and before an operator

      4. Keep the opening brace { at the end of same line as signature of the method and keywords (i.e. if, for, etc keywords)

      5. Use end of line comments // only when you have a few words to say about the line. If the length of the comment is more than a few words you should make use of /* */ or /* */ for multi line comment

      6. When the method signature is long then break to new line and use 8 spaces to differentiate between method arguments and method body

      7. Declare each variable in its own line rather than int i,j,k;

      8. No space between method name and parenthesis ( however, there should be 1 space between reserved keywords (i.e. if, for) and the parenthesis - this would help easily visually differentiate between method and other constructs

      9. Methods are separated by a blank line

      10. A blank space should appear after a comma in argument list

      11. space pad operators (i.e. +,-,%, etc.) and=`

      12. Many more - please see the links below


      Here is your code using some of the above points



      import java.util.Scanner; 

      public class SecretCode {

      // Checks to see is user the String that was input by the user is valid.

      public static boolean isValidLength(String stringChecker) {
      // Determines length check
      if ((stringChecker.length() >= 2) && (stringChecker.length() <= 12)) {
      return true;
      } else {
      return false;
      }
      }

      /*
      * Converts the String inputted by the user and converts it to an Ascii value.
      * The values are stored and return as an int.
      */
      public static int charToAscii (String stringToAscii) {
      int stringValue = 0;

      // Loop to parse through the String and add all the Ascii values.

      for (int x = 0; x < stringToAscii.length(); x++) {
      stringValue += (int) stringToAscii.charAt(x); // Adder.
      }

      return stringValue;
      }

      /*
      * Gets the total number of digits in an int.
      * This will return the total amount of digits using a logarithmic function You
      * can also do String.valueOf(totalDigits).length();
      */

      public static int getNumDigits (int totalDigits) {
      return (int) (Math.log10(totalDigits) + 1);
      }

      // Converts Ascii values into two separate characters.

      public static String getSecretCode (int secretCodeConversion) {
      String secretCode = new String ();

      // Splits the numbers into two. This gets first two digits
      int num1 = (secretCodeConversion % 10000) / 100;

      // Second two digits - use proper variable naming i.e. firstTwoDigits, secondDigits etc.
      int num2 = (secretCodeConversion % 100);

      if (num1 <= 65) {
      num1 += 61; // Ensures a letter is possible.
      }
      if (num2 <= 65) {
      // Ensures a letter is possible for num2. This could have been short-circuited by an 'or' operator.
      num2 += 61;
      }

      secretCode += Character.toString((char) num1) + Character.toString((char) num2);

      return secretCode;
      }

      public static void main(String args) {
      String secretCode = new String ();

      // Instantiates Scanner object to read input.
      Scanner sc = new Scanner (System.in);

      System.out.println ("Please enter the String you would like to make a secret code?");
      secretCode = sc.next();

      // Checks to see low long secret message it is to make sure it is valid.

      while (isValidLength(secretCode) == false) {
      System.out.println ("Please enter the String you would like to make a secret code?");
      secretCode = sc.next(); // Loops until true.
      }

      sc.close(); // No more need for Scanner.

      int sumOfDigits = charToAscii(secretCode);

      if (getNumDigits(sumOfDigits) % 2 != 0) {
      sumOfDigits *= 10;
      }

      if (sumOfDigits <= 4000) {
      sumOfDigits *= 4;
      }

      if (getNumDigits(sumOfDigits) % 2 != 0) {
      sumOfDigits /= 10;
      }

      System.out.println();
      System.out.println();

      System.out.println ("Your Secret Coded Message Is: " + getSecretCode(sumOfDigits));

      System.out.println();
      System.out.println();

      System.out.println ("Additional Data:");
      System.out.println ("_______________________");

      System.out.println ("String Input: " + '"' + secretCode + '"');
      System.out.println ("Sum of Ascii Codes: " + charToAscii(secretCode));
      System.out.println ("Secret Code in Ascii Numbers " + sumOfDigits);
      }
      }


      Here are things you could improve in your code




      • Over-commented - sometimes it's clear what a line is doing don't add comment, only add comment when the code is complex and it's hard to read

      • Variable naming, make it easy to understand what a variable is storing

      • Indentation

      • Use of type of comment

      • Lack of javadoc comments


      There are many positives in your code too. I like the method naming, the way you have divided it into methods. You are on right path, read some of the following coding conventions for java and you are all set.



      Oracle Java Style Guide - https://www.oracle.com/technetwork/java/codeconventions-150003.pdf



      Google Java Style Guide - https://google.github.io/styleguide/javaguide.html



      Spring Framework Style Guide - https://github.com/spring-projects/spring-framework/wiki/Code-Style



      Twitter Java Style Guide - https://github.com/twitter/commons/blob/master/src/java/com/twitter/common/styleguide.md






      share|improve this answer














      Not long ago, I reviewed the Java Coding Conventions from companies like Oracle, Google, Twitter and Spring. Surprisingly there is quite a bit to say when it comes to indentation and formatting and here is a brief summary and useful links that could help you write easy to read and maintainable code.



      I wrote a short article about java coding best practices for those interested to read more.




      1. 2-4 spaces for indentation (Google recommends +2 spaces)

      2. Line length range recommended should be between 70 to 120 (max)

      3. When it comes to wrapping lines break after comma and before an operator

      4. Keep the opening brace { at the end of same line as signature of the method and keywords (i.e. if, for, etc keywords)

      5. Use end of line comments // only when you have a few words to say about the line. If the length of the comment is more than a few words you should make use of /* */ or /* */ for multi line comment

      6. When the method signature is long then break to new line and use 8 spaces to differentiate between method arguments and method body

      7. Declare each variable in its own line rather than int i,j,k;

      8. No space between method name and parenthesis ( however, there should be 1 space between reserved keywords (i.e. if, for) and the parenthesis - this would help easily visually differentiate between method and other constructs

      9. Methods are separated by a blank line

      10. A blank space should appear after a comma in argument list

      11. space pad operators (i.e. +,-,%, etc.) and=`

      12. Many more - please see the links below


      Here is your code using some of the above points



      import java.util.Scanner; 

      public class SecretCode {

      // Checks to see is user the String that was input by the user is valid.

      public static boolean isValidLength(String stringChecker) {
      // Determines length check
      if ((stringChecker.length() >= 2) && (stringChecker.length() <= 12)) {
      return true;
      } else {
      return false;
      }
      }

      /*
      * Converts the String inputted by the user and converts it to an Ascii value.
      * The values are stored and return as an int.
      */
      public static int charToAscii (String stringToAscii) {
      int stringValue = 0;

      // Loop to parse through the String and add all the Ascii values.

      for (int x = 0; x < stringToAscii.length(); x++) {
      stringValue += (int) stringToAscii.charAt(x); // Adder.
      }

      return stringValue;
      }

      /*
      * Gets the total number of digits in an int.
      * This will return the total amount of digits using a logarithmic function You
      * can also do String.valueOf(totalDigits).length();
      */

      public static int getNumDigits (int totalDigits) {
      return (int) (Math.log10(totalDigits) + 1);
      }

      // Converts Ascii values into two separate characters.

      public static String getSecretCode (int secretCodeConversion) {
      String secretCode = new String ();

      // Splits the numbers into two. This gets first two digits
      int num1 = (secretCodeConversion % 10000) / 100;

      // Second two digits - use proper variable naming i.e. firstTwoDigits, secondDigits etc.
      int num2 = (secretCodeConversion % 100);

      if (num1 <= 65) {
      num1 += 61; // Ensures a letter is possible.
      }
      if (num2 <= 65) {
      // Ensures a letter is possible for num2. This could have been short-circuited by an 'or' operator.
      num2 += 61;
      }

      secretCode += Character.toString((char) num1) + Character.toString((char) num2);

      return secretCode;
      }

      public static void main(String args) {
      String secretCode = new String ();

      // Instantiates Scanner object to read input.
      Scanner sc = new Scanner (System.in);

      System.out.println ("Please enter the String you would like to make a secret code?");
      secretCode = sc.next();

      // Checks to see low long secret message it is to make sure it is valid.

      while (isValidLength(secretCode) == false) {
      System.out.println ("Please enter the String you would like to make a secret code?");
      secretCode = sc.next(); // Loops until true.
      }

      sc.close(); // No more need for Scanner.

      int sumOfDigits = charToAscii(secretCode);

      if (getNumDigits(sumOfDigits) % 2 != 0) {
      sumOfDigits *= 10;
      }

      if (sumOfDigits <= 4000) {
      sumOfDigits *= 4;
      }

      if (getNumDigits(sumOfDigits) % 2 != 0) {
      sumOfDigits /= 10;
      }

      System.out.println();
      System.out.println();

      System.out.println ("Your Secret Coded Message Is: " + getSecretCode(sumOfDigits));

      System.out.println();
      System.out.println();

      System.out.println ("Additional Data:");
      System.out.println ("_______________________");

      System.out.println ("String Input: " + '"' + secretCode + '"');
      System.out.println ("Sum of Ascii Codes: " + charToAscii(secretCode));
      System.out.println ("Secret Code in Ascii Numbers " + sumOfDigits);
      }
      }


      Here are things you could improve in your code




      • Over-commented - sometimes it's clear what a line is doing don't add comment, only add comment when the code is complex and it's hard to read

      • Variable naming, make it easy to understand what a variable is storing

      • Indentation

      • Use of type of comment

      • Lack of javadoc comments


      There are many positives in your code too. I like the method naming, the way you have divided it into methods. You are on right path, read some of the following coding conventions for java and you are all set.



      Oracle Java Style Guide - https://www.oracle.com/technetwork/java/codeconventions-150003.pdf



      Google Java Style Guide - https://google.github.io/styleguide/javaguide.html



      Spring Framework Style Guide - https://github.com/spring-projects/spring-framework/wiki/Code-Style



      Twitter Java Style Guide - https://github.com/twitter/commons/blob/master/src/java/com/twitter/common/styleguide.md







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Dec 1 '18 at 0:16

























      answered Nov 19 '18 at 15:29









      Raf

      4,48611835




      4,48611835








      • 1




        Subjective, but indentation is probably better to be 2 spaces. Seems to be the most common defacto standard nowadays (also Google's Java Style). 2 spaces helps you abide to the max 120 line length more easily (most IDEs include indent as part of it). Also 2 spaces helps you see the code without horizontal scrolling in 3-way diffs while merging conflicts.
        – jbx
        Nov 19 '18 at 15:36










      • IMO something in between 2-4 spaces is way to go. I did notice that Google recommended +2 spaces and some other companies use 4 spaces. I have shared links to a few of the companies coding guidelines that matter (so we are not biased to one)
        – Raf
        Nov 19 '18 at 16:09














      • 1




        Subjective, but indentation is probably better to be 2 spaces. Seems to be the most common defacto standard nowadays (also Google's Java Style). 2 spaces helps you abide to the max 120 line length more easily (most IDEs include indent as part of it). Also 2 spaces helps you see the code without horizontal scrolling in 3-way diffs while merging conflicts.
        – jbx
        Nov 19 '18 at 15:36










      • IMO something in between 2-4 spaces is way to go. I did notice that Google recommended +2 spaces and some other companies use 4 spaces. I have shared links to a few of the companies coding guidelines that matter (so we are not biased to one)
        – Raf
        Nov 19 '18 at 16:09








      1




      1




      Subjective, but indentation is probably better to be 2 spaces. Seems to be the most common defacto standard nowadays (also Google's Java Style). 2 spaces helps you abide to the max 120 line length more easily (most IDEs include indent as part of it). Also 2 spaces helps you see the code without horizontal scrolling in 3-way diffs while merging conflicts.
      – jbx
      Nov 19 '18 at 15:36




      Subjective, but indentation is probably better to be 2 spaces. Seems to be the most common defacto standard nowadays (also Google's Java Style). 2 spaces helps you abide to the max 120 line length more easily (most IDEs include indent as part of it). Also 2 spaces helps you see the code without horizontal scrolling in 3-way diffs while merging conflicts.
      – jbx
      Nov 19 '18 at 15:36












      IMO something in between 2-4 spaces is way to go. I did notice that Google recommended +2 spaces and some other companies use 4 spaces. I have shared links to a few of the companies coding guidelines that matter (so we are not biased to one)
      – Raf
      Nov 19 '18 at 16:09




      IMO something in between 2-4 spaces is way to go. I did notice that Google recommended +2 spaces and some other companies use 4 spaces. I have shared links to a few of the companies coding guidelines that matter (so we are not biased to one)
      – Raf
      Nov 19 '18 at 16:09













      0














      Your methods are not indented inside the class. They seem to be in the same level as the class on your code. The other method level indentation looks fine. Try to format it in your IDE and you will see the difference. The structure should be similar to below.



      class Order
      {
      // fields

      // constructors

      // methods
      }





      share|improve this answer


























        0














        Your methods are not indented inside the class. They seem to be in the same level as the class on your code. The other method level indentation looks fine. Try to format it in your IDE and you will see the difference. The structure should be similar to below.



        class Order
        {
        // fields

        // constructors

        // methods
        }





        share|improve this answer
























          0












          0








          0






          Your methods are not indented inside the class. They seem to be in the same level as the class on your code. The other method level indentation looks fine. Try to format it in your IDE and you will see the difference. The structure should be similar to below.



          class Order
          {
          // fields

          // constructors

          // methods
          }





          share|improve this answer












          Your methods are not indented inside the class. They seem to be in the same level as the class on your code. The other method level indentation looks fine. Try to format it in your IDE and you will see the difference. The structure should be similar to below.



          class Order
          {
          // fields

          // constructors

          // methods
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 15:02









          joemokenela

          1466




          1466























              -1














              Indentation is a particular standard that we follow across code in all classes uniformly. To start with I can say




              1. Your commenting style is not readable in screen width.

              2. The start and closing for flower brackets is not same across ex: see main method.


              Having said that anybody can have their own style of formatting and indenting there is nothing wrong with it.






              share|improve this answer


























                -1














                Indentation is a particular standard that we follow across code in all classes uniformly. To start with I can say




                1. Your commenting style is not readable in screen width.

                2. The start and closing for flower brackets is not same across ex: see main method.


                Having said that anybody can have their own style of formatting and indenting there is nothing wrong with it.






                share|improve this answer
























                  -1












                  -1








                  -1






                  Indentation is a particular standard that we follow across code in all classes uniformly. To start with I can say




                  1. Your commenting style is not readable in screen width.

                  2. The start and closing for flower brackets is not same across ex: see main method.


                  Having said that anybody can have their own style of formatting and indenting there is nothing wrong with it.






                  share|improve this answer












                  Indentation is a particular standard that we follow across code in all classes uniformly. To start with I can say




                  1. Your commenting style is not readable in screen width.

                  2. The start and closing for flower brackets is not same across ex: see main method.


                  Having said that anybody can have their own style of formatting and indenting there is nothing wrong with it.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 '18 at 15:01









                  Raghuveer

                  95021235




                  95021235






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377133%2fis-there-something-wrong-with-my-indentation%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                      SQL update select statement

                      'app-layout' is not a known element: how to share Component with different Modules