![]() Similarly, r is a good variable name for describing Polar coordinates (unfortunately there's no theta key, but if you can get the θ character it's also acceptable for a polar coordinate (a little more work than it's probably worth)). x and y (for coordinates): These are what we actually call Cartesian coordinates, so they're actually great variable names for this purpose (but, again, only for coordinates).Note that this only applies to these specific names it does not extrapolate to naming other objects. Graphics g & Random r: These are okay only for these objects only because they're common Java conventions.Only the following one-letter variable names should be used: It's usually best to avoid abbreviations. Abbreviations should not be used unless they are generally accepted abbreviations or very obvious, like num for number. As a general rule of thumb, class and variable names should be nouns, and method names should be verbs. Similarly, the name of a method should describe the task of the method. The name of a variable should describe the value it stores and what it represents. ![]() Constant Names These should be SCREAMING_CASED, in all uppercase with words separated by underscores. Class Names These should be PascalCased, a subset of camel casing where the first letter of the first word is also uppercased. Here are the casing conventions we use for different kinds of names in Java: Method & Variable Names These should be camelCased, a convention where the first letter of every word after the first is uppercased. We have certain conventions for how we name things in Java. If this results in lines of code that are too long, you should see the section on long lines and wrapping it is not acceptable to split prints into multiple statements because they are too long. Rather than have a bunch of adjacent print statements, you should combine them into one where you can.In general, you shouldn't need to use \n in CSE 142. \n should never be used in print or println statements.Printing an empty String ( ("")) is considered bad style it makes the intention to print a blank line less clear. You should always print a blank line using ().There are a few basic rules you should follow for printing in Java: Public static void main ( String args ) Printing ![]() For example, there is no line break after the brace if it is followed by else. The closing curly brace should be on a line by itself at the same level of indentation as the line with the opening curly brace, only if that brace terminates a statement or terminates the body of a method, constructor, or class. An opening curly brace should be placed at the end of the line that opened it. Lots of languages use curly braces, and Java has its a convention for how to use them. In Java, curly braces are used to compartmentalize blocks of code. Conventions are things that don't affect whether the code will compile, but are just generally accepted as part of writing good Java code, and are things that you should adhere to ensure you are writing good, readable code. Java syntax is writing code in a way that allows it to compile.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |