Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
If I split a String permIp, Is there a specific naming convention that is considered to be correct that I should follow for the String[] that I create, such as permIps, permIpSplit or splitPermIp? Or is this a matter of personal preference?
permIpSplit seems fine. The naming convention should be camel casing and ensuring that it conveys the correct meaning to the people reading it apart from you. So including split in the variable name should do.
That all depends on what code style you have decided to go with. There is no set rule for naming conventions. There are lots of examples of different code styles but they are all just guidelines. A good place to start might be googles though.
https://google-styleguide.googlecode.com/svn/trunk/javaguide.html#s5.2.7-local-variable-names
There is no naming convention for the spiltted String[] array. Use usual java naming convention for variable name which is suitable for array and also suitable for the original String which is being splitted.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I was wondering what is the reason behind this and why we cannot use any symbol than those two, I think I never use a variable with those symbols but it is worth to know the cause
The $ in variables is a historical convention that is commonly used in Linux systems (among other languages) to call variables. In a Linux system, if I set a variable, I call it with this key (i.e. x = 4, echo $x).
Underscores and Camel Case are 2 common ways to identify multi-word variables. If I want to declare the variable iLoveJava or I_Love_Java, both are easily readable.
Of course, all of this is a rationalization of stylistic choices made by Sun Microsystems when they made the language, but I think it's a fair interpretation ;). If you want more details on why the others aren't used in detail, the link posted by Sercan is excellent information as well.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
In many programming languages, the array index begins with 0. Is there a reason why it was designed so?
According to me, it would have been more convenient if the length of the array was equal to the last index. We could avoid most of the ArrayIndexOutOfBounds exceptions.
I can understand when it comes to a language like C. C is an old language and the developers may have not thought about the issues and discomfort. But in case of modern languages like java, they still had a chance to redefine the design. Why have they chosen to keep it the same?
Is it somehow related to working of operating systems or did they actually wanted to continue with the familiar behaviour or design structure (though new programmers face a lot of problems related to this)?
An array index is just a memory offset.
So the first element of an array is at the memory it is already pointing to, which is simply
*(arr) == *(arr+0).
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have to deal with a domain object that's real name is 351K-Report. According to the Java naming convention its forbidden to use a number at the beginning of an identifier.
I don't want to fully spell out the number. And, I also think that it's a bad idea to place an underline in front of the number.
But what is the recommended alternative?
UPDATE
There are also other reports, like SpecReport, TopReport, LF10Report and so on. So I'm very doubtful that inverting parts of the noun changes the meaning of the whole project.
Maybe reverse it. For example:
report351K
That would be very bad..
Imagine this:
int 1d = 3;
double d = 1d * 2;
What would be d?
Alternatives:
Since variables that begins with _ usually indicates for class member, I would use report351K.
if you really want to do this then _351KReport but I don't think you should do this. try to make something meaningful of it and at the same time is convineient to Java
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
In Java, there's a naming convention for classes, interfaces, packages, methods, variables and constants. I'm just wondering if there is a naming convention for JSF XHTML pages.
Here are a few variants that came up to my mind:
MyPage.xhtml
myPage.xhtml
my-page.xhtml
mypage.xhtml
There's no need to think of xhtml pages as something different from plain html pages. In the end, if a user has to type it out, then it would help to have a simple page name (just like we would name any html page).
To give you an example, even a company like Apple who are so specific about using the correct case for their products, still maintain a URL such as http://www.apple.com/iphone! (iPhone is written as iphone)
To summarize I would say, don't use capital letters in URL, and try not to use special characters either.
Camel-case starting with a lowercase letter is good, I use hyphens to distinguish modules/ subpages/ subelements.
For example:
productList.xhtml
productEdit.xhtml
productEdit-buttons.xhtml
productReport.xhtml
customerAddress.xhtml
customerAddress-map.xhtml
Not a formal convention, but it works well. Being able to modularize or identify fragments or sub-functions is useful.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
We are writing a hierarchy of classes that implement various ways to represent languages. There is a base LanguageCode class with several subclasses, including ISO1LanguageCode for ISO 639-1 codes (example: 'en'), ISO2LanguageCode for ISO 639-2 codes (example: 'eng'), and HumanReadableLanguageCode (example: 'English'). At any time, we need to be able to convert between any two of the subclasses. Is there some design pattern magic we could use here to help?
Note:
Our first idea was to standardize the base class and make each subclass write a conversion routine between itself and the standard on the base class. That way, to convert between ISO2LanguageCode and HumanReadableLanguageCode, use LanguageCode as a bridge.
There is only one set of languages. Each language has an -1 code, a useless -2 code, and a -3 code. And a human-readable name. So make one enum with accessors to return the different codes, and multiple lookup static methods.