even if it involves telling me that starting with Ideone is not the best choice for whatever reasons.
As a beginner, starting with Ideone is not the best choice IMO. For a number of reasons:
- It is not a good practice to use
import xxx.xxx.*
. Only import the things that you actually need. In this case, you don't even need to import anything (because the things that you need are part of thejava.lang
package. - In IdeOne the filename is "Main.java" and there is no way to change that, which means that you will not learn that a public class in a file must have the same name as the file itself. I.e. the
public class SomeClass
must go in a file namedSomeClass.java
. - In IdeOne you are not able to declare a package name. A package name is mainly used to identify projects and the author of the code and so on. They are usually your domain-name backwards. For example, as I own
zomis.net
my package names arenet.zomis.someproject
. If you don't own a domain, well... make one up for now.com.jamal
could work for you. Either way, usage of the "default"-package (i.e. not declaring a package at all) is discouraged. - In IdeOne there is no direct feedback for compiler errors. You have to click "Run" on your code to make sure that it has no compiler errors. In all modern Java IDEs you automatically get such feedback whenever you have finished writing a line of code (sometimes you have to hit Ctrl+S to save though before it will show the errors properly). This may not feel important at first, but once you get used to it you will really miss the feature in other IDEs.
As for the code itself, it isn't that bad. It is good that you removed IdeOne's throws Exception
declaration.
Greg has already covered the aspects of the conditional operator, so there is only one thing I can possibly comment about, but this is just a personal opinion more than anything else and feel free to completely ignore this comment.
for (int i = 1; i <= 100; ++i) {
In Java, it is more common in such for-loops to use i++
rather than ++i
. Although this has no effect whatsoever in this case, and I'm sure you're aware of the differences between i++
and ++i
from your C++ (or is it ++C?) experience.
When using ++i
or i++
alone (i.e. without an assignment to another variable), there is a myth that there is a performance difference in C++ and C, while apparently that is not the case that is not the case.
In Java, it is also it is also exactly the same exactly the same (the same applies for C# applies for C#, if you're wondering).
Of course, using i++
or ++i
always matters when adding another assignment. If i = 1
:
a = i++
will makea == 1
a = ++i
will makea == 2
i == 2
after the statement in both cases
even if it involves telling me that starting with Ideone is not the best choice for whatever reasons.
As a beginner, starting with Ideone is not the best choice IMO. For a number of reasons:
- It is not a good practice to use
import xxx.xxx.*
. Only import the things that you actually need. In this case, you don't even need to import anything (because the things that you need are part of thejava.lang
package. - In IdeOne the filename is "Main.java" and there is no way to change that, which means that you will not learn that a public class in a file must have the same name as the file itself. I.e. the
public class SomeClass
must go in a file namedSomeClass.java
. - In IdeOne you are not able to declare a package name. A package name is mainly used to identify projects and the author of the code and so on. They are usually your domain-name backwards. For example, as I own
zomis.net
my package names arenet.zomis.someproject
. If you don't own a domain, well... make one up for now.com.jamal
could work for you. Either way, usage of the "default"-package (i.e. not declaring a package at all) is discouraged. - In IdeOne there is no direct feedback for compiler errors. You have to click "Run" on your code to make sure that it has no compiler errors. In all modern Java IDEs you automatically get such feedback whenever you have finished writing a line of code (sometimes you have to hit Ctrl+S to save though before it will show the errors properly). This may not feel important at first, but once you get used to it you will really miss the feature in other IDEs.
As for the code itself, it isn't that bad. It is good that you removed IdeOne's throws Exception
declaration.
Greg has already covered the aspects of the conditional operator, so there is only one thing I can possibly comment about, but this is just a personal opinion more than anything else and feel free to completely ignore this comment.
for (int i = 1; i <= 100; ++i) {
In Java, it is more common in such for-loops to use i++
rather than ++i
. Although this has no effect whatsoever in this case, and I'm sure you're aware of the differences between i++
and ++i
from your C++ (or is it ++C?) experience.
When using ++i
or i++
alone (i.e. without an assignment to another variable), there is a myth that there is a performance difference in C++ and C, while apparently that is not the case.
In Java, it is also exactly the same (the same applies for C#, if you're wondering).
Of course, using i++
or ++i
always matters when adding another assignment. If i = 1
:
a = i++
will makea == 1
a = ++i
will makea == 2
i == 2
after the statement in both cases
even if it involves telling me that starting with Ideone is not the best choice for whatever reasons.
As a beginner, starting with Ideone is not the best choice IMO. For a number of reasons:
- It is not a good practice to use
import xxx.xxx.*
. Only import the things that you actually need. In this case, you don't even need to import anything (because the things that you need are part of thejava.lang
package. - In IdeOne the filename is "Main.java" and there is no way to change that, which means that you will not learn that a public class in a file must have the same name as the file itself. I.e. the
public class SomeClass
must go in a file namedSomeClass.java
. - In IdeOne you are not able to declare a package name. A package name is mainly used to identify projects and the author of the code and so on. They are usually your domain-name backwards. For example, as I own
zomis.net
my package names arenet.zomis.someproject
. If you don't own a domain, well... make one up for now.com.jamal
could work for you. Either way, usage of the "default"-package (i.e. not declaring a package at all) is discouraged. - In IdeOne there is no direct feedback for compiler errors. You have to click "Run" on your code to make sure that it has no compiler errors. In all modern Java IDEs you automatically get such feedback whenever you have finished writing a line of code (sometimes you have to hit Ctrl+S to save though before it will show the errors properly). This may not feel important at first, but once you get used to it you will really miss the feature in other IDEs.
As for the code itself, it isn't that bad. It is good that you removed IdeOne's throws Exception
declaration.
Greg has already covered the aspects of the conditional operator, so there is only one thing I can possibly comment about, but this is just a personal opinion more than anything else and feel free to completely ignore this comment.
for (int i = 1; i <= 100; ++i) {
In Java, it is more common in such for-loops to use i++
rather than ++i
. Although this has no effect whatsoever in this case, and I'm sure you're aware of the differences between i++
and ++i
from your C++ (or is it ++C?) experience.
When using ++i
or i++
alone (i.e. without an assignment to another variable), there is a myth that there is a performance difference in C++ and C, while apparently that is not the case.
In Java, it is also exactly the same (the same applies for C#, if you're wondering).
Of course, using i++
or ++i
always matters when adding another assignment. If i = 1
:
a = i++
will makea == 1
a = ++i
will makea == 2
i == 2
after the statement in both cases
even if it involves telling me that starting with Ideone is not the best choice for whatever reasons.
As a beginner, starting with Ideone is not the best choice IMO. For a number of reasons:
- It is not a good practice to use
import xxx.xxx.*
. Only import the things that you actually need. In this case, you don't even need to import anything (because the things that you need are part of thejava.lang
package. - In IdeOne the filename is "Main.java" and there is no way to change that, which means that you will not learn that a public class in a file must have the same name as the file itself. I.e. the
public class SomeClass
must go in a file namedSomeClass.java
. - In IdeOne you are not able to declare a package name. A package name is mainly used to identify projects and the author of the code and so on. They are usually your domain-name backwards. For example, as I own
zomis.net
my package names arenet.zomis.someproject
. If you don't own a domain, well... make one up for now.com.jamal
could work for you. Either way, usage of the "default"-package (i.e. not declaring a package at all) is discouraged. - In IdeOne there is no direct feedback for compiler errors. You have to click "Run" on your code to make sure that it has no compiler errors. In all modern Java IDEs you automatically get such feedback whenever you have finished writing a line of code (sometimes you have to hit Ctrl+S to save though before it will show the errors properly). This may not feel important at first, but once you get used to it you will really miss the feature in other IDEs.
As for the code itself, it isn't that bad. It is good that you removed IdeOne's throws Exception
declaration.
Greg has already covered the aspects of the conditional operator, so there is only one thing I can possibly comment about, but this is just a personal opinion more than anything else and feel free to completely ignore this comment.
for (int i = 1; i <= 100; ++i) {
In Java, it is more common in such for-loops to use i++
rather than ++i
. Although this has no effect whatsoever in this case, and I'm sure you're aware of the differences between i++
and ++i
from your C++ (or is it ++C?) experience.
When using ++i
or i++
alone (i.e. without an assignment to another variable), there is a myth that there is a performance difference in C++ and C, while apparently that is not the case.
In Java, it is also exactly the same (the same applies for C#, if you're wondering).
Of course, using i++
or ++i
always matters when adding another assignment. If i = 1
:
a = i++
will makea == 1
a = ++i
will makea == 2
i == 2
after the statement in both cases
even if it involves telling me that starting with Ideone is not the best choice for whatever reasons.
As a beginner, starting with Ideone is not the best choice IMO. For a number of reasons:
- It is not a good practice to use
import xxx.xxx.*
. Only import the things that you actually need. In this case, you don't even need to import anything (because the things that you need are part of thejava.lang
package. - In IdeOne the filename is "Main.java" and there is no way to change that, which means that you will
- In IdeOne you are not able to declare a package name. A package name is mainly used to identify projects and the author of the code and so on. They are usually your domain-name backwards. For example, as I own
zomis.net
my package names arenet.zomis.someproject
. If you don't own a domain, well... make one up for now.com.jamal
could work for you. Either way, usage of the "default"-package (i.e. not declaring a package at all) is discouraged. - In IdeOne there is no direct feedback for compiler errors. You have to click "Run" on your code to make sure that it has no compiler errors. In all modern Java IDEs you automatically get such feedback whenever you have finished writing a line of code (sometimes you have to hit Ctrl+S to save though before it will show the errors properly). This may not feel important at first, but once you get used to it you will really miss the feature in other IDEs.
As for the code itself, it isn't that bad. It is good that you removed IdeOne's throws Exception
declaration.
Greg has already covered the aspects of the conditional operator, so there is only one thing I can possibly comment about, but this is just a personal opinion more than anything else and feel free to completely ignore this comment.
for (int i = 1; i <= 100; ++i) {
In Java, it is more common in such for-loops to use i++
rather than ++i
. Although this has no effect whatsoever in this case, and I'm sure you're aware of the differences between i++
and ++i
from your C++ (or is it ++C?) experience.
When using ++i
or i++
alone (i.e. without an assignment to another variable), there is a myth that there is a performance difference in C++ and C, while apparently that is not the case.
In Java, it is also exactly the same (the same applies for C#, if you're wondering).
Of course, using i++
or ++i
always matters when adding another assignment. If i = 1
:
a = i++
will makea == 1
a = ++i
will makea == 2
i == 2
after the statement in both cases
even if it involves telling me that starting with Ideone is not the best choice for whatever reasons.
As a beginner, starting with Ideone is not the best choice IMO. For a number of reasons:
- It is not a good practice to use
import xxx.xxx.*
. Only import the things that you actually need. In this case, you don't even need to import anything (because the things that you need are part of thejava.lang
package. - In IdeOne the filename is "Main.java" and there is no way to change that, which means that you will not learn that a public class in a file must have the same name as the file itself. I.e. the
public class SomeClass
must go in a file namedSomeClass.java
. - In IdeOne you are not able to declare a package name. A package name is mainly used to identify projects and the author of the code and so on. They are usually your domain-name backwards. For example, as I own
zomis.net
my package names arenet.zomis.someproject
. If you don't own a domain, well... make one up for now.com.jamal
could work for you. Either way, usage of the "default"-package (i.e. not declaring a package at all) is discouraged. - In IdeOne there is no direct feedback for compiler errors. You have to click "Run" on your code to make sure that it has no compiler errors. In all modern Java IDEs you automatically get such feedback whenever you have finished writing a line of code (sometimes you have to hit Ctrl+S to save though before it will show the errors properly). This may not feel important at first, but once you get used to it you will really miss the feature in other IDEs.
As for the code itself, it isn't that bad. It is good that you removed IdeOne's throws Exception
declaration.
Greg has already covered the aspects of the conditional operator, so there is only one thing I can possibly comment about, but this is just a personal opinion more than anything else and feel free to completely ignore this comment.
for (int i = 1; i <= 100; ++i) {
In Java, it is more common in such for-loops to use i++
rather than ++i
. Although this has no effect whatsoever in this case, and I'm sure you're aware of the differences between i++
and ++i
from your C++ (or is it ++C?) experience.
When using ++i
or i++
alone (i.e. without an assignment to another variable), there is a myth that there is a performance difference in C++ and C, while apparently that is not the case.
In Java, it is also exactly the same (the same applies for C#, if you're wondering).
Of course, using i++
or ++i
always matters when adding another assignment. If i = 1
:
a = i++
will makea == 1
a = ++i
will makea == 2
i == 2
after the statement in both cases
In C++ and C , if you'reWhen using ++i
or i++
in a for loop can have different performance as far as I can tellalone (depending on the compileri.e. without an assignment to another variable), there is a myth that there is a performance difference in C++ and C, while apparently that is not the case.
In Java, it is also exactly the same (the same applies for C# actually, if you're wondering).
Of course, whether you useusing i++
or ++i
always matters in cases such as a = i++;
and a = ++i;
ifwhen adding another assignment. If i = 1
, a = i++
will make a == 1
and a = ++i
will make a == 2
. (will result in i == 2
in both cases):
a = i++
will makea == 1
a = ++i
will makea == 2
i == 2
after the statement in both cases
In C++ and C , if you're using ++i
or i++
in a for loop can have different performance as far as I can tell (depending on the compiler).
In Java, it is exactly the same (the same applies for C# actually, if you're wondering).
Of course, whether you use i++
or ++i
always matters in cases such as a = i++;
and a = ++i;
if i = 1
, a = i++
will make a == 1
and a = ++i
will make a == 2
. (will result in i == 2
in both cases)
When using ++i
or i++
alone (i.e. without an assignment to another variable), there is a myth that there is a performance difference in C++ and C, while apparently that is not the case.
In Java, it is also exactly the same (the same applies for C#, if you're wondering).
Of course, using i++
or ++i
always matters when adding another assignment. If i = 1
:
a = i++
will makea == 1
a = ++i
will makea == 2
i == 2
after the statement in both cases