Does method overloading make code more readable? [closed] - 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
I have read on many blogs and website that method overloading make code more readable:
Method overloading increases the readability of the program.(Source)
where as official documentation say:
Overloaded methods should be used sparingly, as they can make code
much less readable.

In that case you have to do some observation to come to the conclusions
Which is better?
Case 1
System.out.print(“Hello”);
System.out.print(12);
OR
Case 2
System.out.printString(“Hello”);
System.out.printInt(12);
As seen Case 1 is more readable and can be remember easily in comparison to Case 2 . This above Case 1 print method is overloaded as seen in source . So thats why java creator dint implement Case 2.
Hence ill go with overloading is more readable and also if its not readable then java developers would have implemented Case 2.

Related

Which is better check the integer is 0 or check the variable is null? [closed]

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 tried to search the internet but I didn't see it's been asked. So our lecturer told us, we must write our own linked-list from scratch. Inside the linkedlist have head and tail pointing at another when you add item. Suppose if inside I already add a working integer counter. My question is I have 2 option to check if the linkedlist is empty:
check the head is null
check the counter is 0
my question is which is better in term of efficiency? I know the checking is millisecond matter, but I want to know, in theory, which one got better advantage over another? Sorry I'm not taking Operating System, I not know much the theory.
If you're asking which has better performance, they'll be exactly the same. In both cases you're doing a field or property access followed by a numeric comparison against a constant value. (null is just 0 as a memory address.)

Why java variables can only contain underscore and dollar sign [closed]

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.

What is the "proper" form in which to write Java? [closed]

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
Personally, I write my Java like this:
class xyz {
...
}
OR
if (condition) {
...
}
etcetera...
In so many examples, I see code written like this:
class xyz
{
...
}
OR
if (condition)
{
...
}
etcetera...
To me, my way makes the most sense because not only does it take less lines to write, but (again, in my opinion) looks more proper and professional. I'd love to know people's opinions - and reasoning behind them - as to which form is better and why.
The first one with opening braces on the same line is almost the standard Java programming guideline for years.
The original Sun Java guideline, that was never updated since 1999.
http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141270.html
Google Java guideline
https://google.github.io/styleguide/javaguide.html#s4.1-braces
Android style
https://source.android.com/source/code-style.html
On the opposite side, many open source platforms like Apache/maven advocate brace in new line

Why didn't they design array index to start from 1? [closed]

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).

Java naming convention for identifiers that begin with a number [closed]

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

Categories