Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

Resources:

###Resources: YouYou should start using try-with-resources. This statment does some work for you with resources that implement AutoCloseable. It closes these resources for you, so you don't have to worry about file-locks and remaining database connections:

File file = new File("C:/text.txt");
try(Scanner scanner = new Scanner(file, "utf-8")){
 //your code here ;)
}

You also shouldn't throw Exception in the main method of your program. This can be very confusing to users. Instead you main-method should handle all exceptions "gracefully" by being wrapped into a try-catch-block.

###Conditionals:

Conditionals:

if(!Character.isLetter(c)){
 continue;
}

This is an early return statement for the purpose of following conditions, meaning you don't have to write else if in your next condition.

Naming

###Naming hashMap is not a good name. The map you use is not a Hash-Map, and treeMap would also not explain what the map does, what it contains.

You might want to rename it to characterMap

all else equal, your naming is nice and consistent, and tells exactly what the variables do. You nicely follow camelCase-conventions. Keep it up!

###Summary:

Summary:

Your code reads nicely and is easily understandable. You follow naming conventions and have descriptive and understandable variable names. You should work on your exception handling and the use of resources.

###Resources: You should start using try-with-resources. This statment does some work for you with resources that implement AutoCloseable. It closes these resources for you, so you don't have to worry about file-locks and remaining database connections:

File file = new File("C:/text.txt");
try(Scanner scanner = new Scanner(file, "utf-8")){
 //your code here ;)
}

You also shouldn't throw Exception in the main method of your program. This can be very confusing to users. Instead you main-method should handle all exceptions "gracefully" by being wrapped into a try-catch-block.

###Conditionals:

if(!Character.isLetter(c)){
 continue;
}

This is an early return statement for the purpose of following conditions, meaning you don't have to write else if in your next condition.

###Naming hashMap is not a good name. The map you use is not a Hash-Map, and treeMap would also not explain what the map does, what it contains.

You might want to rename it to characterMap

all else equal, your naming is nice and consistent, and tells exactly what the variables do. You nicely follow camelCase-conventions. Keep it up!

###Summary:

Your code reads nicely and is easily understandable. You follow naming conventions and have descriptive and understandable variable names. You should work on your exception handling and the use of resources.

Resources:

You should start using try-with-resources. This statment does some work for you with resources that implement AutoCloseable. It closes these resources for you, so you don't have to worry about file-locks and remaining database connections:

File file = new File("C:/text.txt");
try(Scanner scanner = new Scanner(file, "utf-8")){
 //your code here ;)
}

You also shouldn't throw Exception in the main method of your program. This can be very confusing to users. Instead you main-method should handle all exceptions "gracefully" by being wrapped into a try-catch-block.

Conditionals:

if(!Character.isLetter(c)){
 continue;
}

This is an early return statement for the purpose of following conditions, meaning you don't have to write else if in your next condition.

Naming

hashMap is not a good name. The map you use is not a Hash-Map, and treeMap would also not explain what the map does, what it contains.

You might want to rename it to characterMap

all else equal, your naming is nice and consistent, and tells exactly what the variables do. You nicely follow camelCase-conventions. Keep it up!

Summary:

Your code reads nicely and is easily understandable. You follow naming conventions and have descriptive and understandable variable names. You should work on your exception handling and the use of resources.

deleted 4 characters in body
Source Link
Vogel612
  • 25.5k
  • 7
  • 59
  • 141

###Resources: You should start using try-with-resources. This statment does some work for you with resources that implement AutoCloseable. It closes these resources for you, so you don't have to worry about file-locks and remaining database connections:

try(File file = new File("C:/text.txt");
try(Scanner scanner = new Scanner(file, "utf-8")){
 //your code here ;)
}

You also shouldn't throw Exception in the main method of your program. This can be very confusing to users. Instead you main-method should handle all exceptions "gracefully" by being wrapped into a try-catch-block.

###Conditionals:

if(!Character.isLetter(c)){
 continue;
}

This is an early return statement for the purpose of following conditions, meaning you don't have to write else if in your next condition.

###Naming hashMap is not a good name. The map you use is not a Hash-Map, and treeMap would also not explain what the map does, what it contains.

You might want to rename it to characterMap

all else equal, your naming is nice and consistent, and tells exactly what the variables do. You nicely follow camelCase-conventions. Keep it up!

###Summary:

Your code reads nicely and is easily understandable. You follow naming conventions and have descriptive and understandable variable names. You should work on your exception handling and the use of resources.

###Resources: You should start using try-with-resources. This statment does some work for you with resources that implement AutoCloseable. It closes these resources for you, so you don't have to worry about file-locks and remaining database connections:

try(File file = new File("C:/text.txt");
Scanner scanner = new Scanner(file, "utf-8")){
 //your code here ;)
}

You also shouldn't throw Exception in the main method of your program. This can be very confusing to users. Instead you main-method should handle all exceptions "gracefully" by being wrapped into a try-catch-block.

###Conditionals:

if(!Character.isLetter(c)){
 continue;
}

This is an early return statement for the purpose of following conditions, meaning you don't have to write else if in your next condition.

###Naming hashMap is not a good name. The map you use is not a Hash-Map, and treeMap would also not explain what the map does, what it contains.

You might want to rename it to characterMap

all else equal, your naming is nice and consistent, and tells exactly what the variables do. You nicely follow camelCase-conventions. Keep it up!

###Summary:

Your code reads nicely and is easily understandable. You follow naming conventions and have descriptive and understandable variable names. You should work on your exception handling and the use of resources.

###Resources: You should start using try-with-resources. This statment does some work for you with resources that implement AutoCloseable. It closes these resources for you, so you don't have to worry about file-locks and remaining database connections:

File file = new File("C:/text.txt");
try(Scanner scanner = new Scanner(file, "utf-8")){
 //your code here ;)
}

You also shouldn't throw Exception in the main method of your program. This can be very confusing to users. Instead you main-method should handle all exceptions "gracefully" by being wrapped into a try-catch-block.

###Conditionals:

if(!Character.isLetter(c)){
 continue;
}

This is an early return statement for the purpose of following conditions, meaning you don't have to write else if in your next condition.

###Naming hashMap is not a good name. The map you use is not a Hash-Map, and treeMap would also not explain what the map does, what it contains.

You might want to rename it to characterMap

all else equal, your naming is nice and consistent, and tells exactly what the variables do. You nicely follow camelCase-conventions. Keep it up!

###Summary:

Your code reads nicely and is easily understandable. You follow naming conventions and have descriptive and understandable variable names. You should work on your exception handling and the use of resources.

Source Link
Vogel612
  • 25.5k
  • 7
  • 59
  • 141

###Resources: You should start using try-with-resources. This statment does some work for you with resources that implement AutoCloseable. It closes these resources for you, so you don't have to worry about file-locks and remaining database connections:

try(File file = new File("C:/text.txt");
 Scanner scanner = new Scanner(file, "utf-8")){
 //your code here ;)
}

You also shouldn't throw Exception in the main method of your program. This can be very confusing to users. Instead you main-method should handle all exceptions "gracefully" by being wrapped into a try-catch-block.

###Conditionals:

if(!Character.isLetter(c)){
 continue;
}

This is an early return statement for the purpose of following conditions, meaning you don't have to write else if in your next condition.

###Naming hashMap is not a good name. The map you use is not a Hash-Map, and treeMap would also not explain what the map does, what it contains.

You might want to rename it to characterMap

all else equal, your naming is nice and consistent, and tells exactly what the variables do. You nicely follow camelCase-conventions. Keep it up!

###Summary:

Your code reads nicely and is easily understandable. You follow naming conventions and have descriptive and understandable variable names. You should work on your exception handling and the use of resources.

lang-java

AltStyle によって変換されたページ (->オリジナル) /