Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
Improve this question
I watched a video about composition and inheritance.
In this video I saw two different examples of code syntax that I have not seen before.
Generally the code looks like java but I don't recognize these two code snippets.
Would appriciate if someone would explain what the code does and if the code is java or another language.
Thanks!
First code:
public void replacePixel(Pixel[,] pixels] {....}
Here it is the syntax [,] that is new to me.
What does it do?
Second code:
void saveClicked(){
file?.load(image);
}
Here is is the syntax ?.
What does it do?
Tried to use a online java compiler and the syntax did not seem to work.
public void replacePixel(Pixel[,] pixels) {....}
Im not sure if this is valid for Java, but in C#:
[,] here means that as an argument you want to get two-dimensional array. If you want three-dimensional array you can use [,,] and so on.
void saveClicked(){
file?.load(image);
}
Here ? is a conditional operator that says: if file is not null then do file.load(image). Otherwise, if file is null do nothing. This can be converted to:
void saveClicked(){
if(file != null){
file.load(image);
}
}
Related
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 5 years ago.
Improve this question
guys.....Please help!!!
This is the picture of a textbook page that I'm reading
So I'm reading this textbook which is totally horrible, they just give codes out without any explanation.....And this is my first class in Java, I've never coded in any language before......So like a textbook without explanation just totally....you know....give me a super hard time....
Back to topic, in the picture, there are 2 sets of codes, A and B.....I understand B......But I do not get why in A, it used value.length instead of inputs.length? Isn't the array name in this code is inputs??? Is there any specific reason has to use value.length instead of array name.length???
the book clearly has an error, don't worry, should be inputs instead values, I say it with confidence because no variable values was ever initiated
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I've tried my utmost to reproduce this in another way, but it seems that only this line gives the error (please excuse the comment):
return foo.containsKey(MARKET_DATA) && !foo.get(MARKET_DATA).isMissing();/*mapping code can inject a Missing type*/;
However I type this it gives me an error: "unreachable statement". Why is this?
This is clear if you remove the comment:
return foo.containsKey(MARKET_DATA) && !foo.get(MARKET_DATA).isMissing();;
Note well the two semicolons at the end: empty statements are allowed in Java, but this particular empty statement is unreachable as the previous statement always returns.
(For the avoidance of doubt, a comment should not be terminated with a ;).
The issue is because of the ; after the comment:
/*mapping code can inject a Missing type*/;
The compiler thinks there is another statement after the return statement. If you delete the ; after the comment it will work fine (or put it inside the comment).
As per Java specs ; is a empty statement. So there is a statement after return
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
this is my first post here. I'm taking my first class in Java and I have come across a question which I believe is a trick question. I know that reserved words can't be used as identifiers and identifiers are only supposed to use upper/lowercase letters, 0-9, $, and _. long is a reserved word, but would using LONG be ok since Java is case sensitive? I have looked all over google for the answer for this. I could not find an answer on stack overflow so sorry if this is answered elsewhere on the forum!
Thanks!
I think you may have figured out by yourself that reserve words are also case sensitive when you say that Java is case sensitive.
Using LONG as identifier would not cause any problem for the Java compiler, but the problem is variable name LONG may not mean much and might not contribute to a readable code
The compiler will allow you to use LONG as an identifier.
Your fellow programmers, however, will try to hold you back.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Currently new to java, and right now I'm doing an assignment involving if else statements. Can someone please why javac is reading my else as dangling? My syntax should be right unless I am missing something here.
You have to remove your Semicolon after the if-statement. Otherwise the braces after the if are not executed.
I hope this will fix your Problem.
if(Statement);
{
//The Content would not be executed in realtion to the if-statemen
}
Otherwise:
if(Statement)
{
//The Content would be executed in realtion to the if-statemen
}
remove the semicolon(;) after the if statement
You have a semicolon after your if. Remove it.
You have to remove the ; at the end of the line starting with if.
change :
if(...);
{
////
}
to
if(...)
{
////
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
so how may I check that? There are 36'000 files and on every event call I would need to check it, there could be plenty of these situations like: "nukasa" or "Nukasa" or "nUkasa", how may I detect all of these if I have one file name like: "NUKASA" or "nukasa" by event calling.
It's work with File not String. I just get String and then I need to work with File to check if in folder exists same file names just in Uppercase or Lowercase.
Please refer below the snippet I want to show as an example:
File sampleFile = new File("Nukasa");
String valueToCheck = "NUKASA";
if(sampleFile.getName().equalsIgnoreCase(valueToCheck))
{
//Logic you want to code goes here
}
Alternatively, you can use file.getName().toUpperCase().equals(valueToCheck) (if you assign upper case string to the variable valueToCheck). Same applies to toLowerCase() method also
CAUTION: This approach works fine as long as the Locale is of English language. For other languages, it won't work as expected. So, equalsIgnoreCase() is the best way. Credits to the person who suggested this
For case insensitive string comparison, use the String method str1.equalsIgnoreCase(str2).