What exactly is <code> in Java [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Edit: Thanks for the quick answers. Please mark this question for deletion. It doesn't serve SO in any way.
I was reading an article here {Listing 2. Iterating a file
} and what stumped me was the literal <code> written in Java! - I've never seen that before - I now get it's meaning somewhat but has it been there since beginning or is it a new feature.
I am reproducing part of the code here..
return new Iterable<String>() {
public <code>Iterator</code><String> iterator() {
return new <code>Iterator</code><String>() {
public boolean hasNext() {
return line != null;
.....

It's an error in the HTML markup of the site. Rightclick page and view source. It's been marked up as <code>Iterator</code> instead of <code>Iterator</code>.
This has nothing to do with Java. You might contact the site/page author to have them to fix it.

It's probably a remnant of generating code using JavaDoc. The <code></code> tags are used to highlight Java code in JavaDoc, in which it generates a Courier New font.

Haha I think it's just HTML that's mistakenly shown as Java code, it's not part of the language. :)

I think that is a HTML formatting error. They are trying to use their custom code tag within another code tag.

That's not valid java. I think it's a typo.

After all the correct answers an alternative explanation:
It is to protect the code by making it uncompilable. That way no-one can steal it:)

Related

Local variable is redundant [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am new to android, can anyone tell me what why is emailresult redundant?
From what I understand is that I retrieve textToUse from another method and name it email here, and then use email to undergo the matcher.find() with the result named emailresult. I then returned emailresult and after that returned the entire email.
I have mess around with it some time, like deleting emailresult and just use email. But then I will still have to create another variable to go under this location:
String emailresult = email.substring(matcher.start(), matcher.end());
It is redundant because you aren't doing anything with emailresult after assigning it a value besides returning it. You can simply do the following without the need to create a variable:
return email.substring(matcher.start(), matcher.end());
There is no need to create a variable
return email.substring(matcher.start(), matcher.end());

Math.max are there some Syntax errors I'm not seeing? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
These lines are the culprit:
I was getting negative numbers so I decided to use the Math.max to ensure that the results would be no less than 0, but now I'm getting errors. My search just found me this method to use, but is there some particular Syntax I need in this form?
x.hp-=Math.max(0,(y.atk-x.def));
y.hp-=Math.max(0,(x.atk-y.def));
Everything works now, Thanks.
The incorrect edit was due to a redundant ( opening parentheses.
) is missing in for Math.max method. i.e (Math.max(0,(y.atk-x.def)))
(Math.max(0,(x.atk-y.def)))
(Math.max(0,(y.atk-x.def)))
end both with " ) "
Contrary to other answers here,
(Math.max(0,(y.atk-x.def))
has an extra parenthesis, at the beginning. Remove it:
Math.max(0,(y.atk-x.def))
You can indeed put an extra pair around the whole thing, as you have started to do, and as other answers appear to insist is necessary, but it isn't. It's redundant.

Dead code in Java/Android [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
is there a way to tell the compiler in Java or Android to not remove some statements in code -which are intended to clean up variables after use to prevent any data remnant in ram-??
would creating a dummy method solve this issue??
these statements basically set the variables to their type-based initial values..
Thanks in advance!
The code that you describe is not dead code.
Dead code is code that will never execute.
Here is an example:
private int secretSchmarr;
public boolean blammo()
{
boolean returnValue;
secretSchmarr = calculateSecretValue();
returnValue = useSecretValue(secretSchmarr);
secretSchmarr = 99; // this is not dead code.
return returnValue;
secretSchmarr = 98; // This is dead code because it can never execute.
}
I answer under the odd assumption that you have a good reason to believe that the code is still useful even though it is dead.
Store the value false in some obfuscated form that the compiler can't understand. Then, conditionally branch to that code using your obfuscated value. The compiler will not know it is dead, so it will not be removed.
I'll use a file for my example, but it is probably not the most efficient way. Say your code that the compiler thinks is dead code was in a function called myCode(). Assume that fin is reading from a file that only contains false followed by EOF
if(Boolean.parseBoolean(fin.next()))
myCode();

Usage of UUID.randomUUID(), a type 4 UUID [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I know this may be a weird question to be asking, but I came across this method and is not too sure of it's purpose.
I been reading online for it's explanation, but did not find one that is easily understood.
What I need is not a code, but rather why should it be implemented.
The snippet code are as follow:
private PrintWriter out;
private static final String end = "067e6162-3b6f-4ae2-a171-2470b63dff00 ";
//generated using the above method, UUID.randomUUID()
public static String getEnd() {
return end;
}
private void sendOutputToClientFile(String str) {
out.println(str);
out.println();
out.println(end);
}
The codes are found inside a server file, and is supposedly use to denote the end of message.
But what purpose does it serve here and why is it necessary?
P.S : I would prefer a layman's term of explanation...
The code writes the random string that is assumed (and with astronomic level of probability very likely to be true) unique, no other calls to UUID.randomUUID will probably ever produce it. Probably this string is checked at another end as the "end of stream" sequence.
Most likely the designer was not able to reserve any particular char sequence to mark the end of the data stream, and for some reason could not use the usual IO methods either. It is highly unlikely that such string will appear inside the stream as well for some reason just by chance.

Will this print a file? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
What would this code do?
FileStream object = new FileStream("c:\input_final.txt",true);
I thought it would not run because they are not two \ and therefore see it as a escape character. Am I wrong and would it print/show/open the file?
No. It will not, because it is not legal code.
Unless you have a custom class FileStream (which you have not posted) then I assume you meant one of -
FileOutputStream which will not work because c:\input_final.txt is not a valid String; \i is not a valid escape sequence.
and
FileInputStream does not have a constructor that takes a boolean as the second argument.
Will this print a file?
No.
It is not valid code. It won't compile ... let alone run!
It is most likely that you mean something like this:
... = new FileOutputStream("c:\\input_final.txt",true);
which says "create an output stream for appending to file "c:\input_final.txt". But even that WILL NOT "print" or "show" the file, or "open" it in an application / browser / editor or whatever.

Categories

Resources