Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This Category lists all questions related to Java programming language
How can we set java path in windows 10
Following are the steps for setting the java path in window 10 :- 1- Go to the Search box and type advanced system settings in it. Now click on the View advanced system settings. 2- Select the Advanced tab and then click environment variables. 3- In the system, variables click the New button. Now inRead more
Following are the steps for setting the java path in window 10 :-
1- Go to the Search box and type advanced system settings in it. Now click on the View advanced system settings.
2- Select the Advanced tab and then click environment variables.
3- In the system, variables click the New button. Now in the edit system variable, type variable name as JAVA_PATH and variable path as the path where the JDK folder is saved and click on OK button Usually the path of the JDK file will be C:\Program Files\Java\jdk1.8.0_60.
4- Now in the system variables go to the path and click the edit button.
5- Click the New button.
6- Now add the following path: %JAVA_HOME%\bin
I hope this helps.
See lessHow can I define a global variable in java
There is no global variable in Java. However, we have a static keyword that we can use to define a global variable by doing something like the below: public class A { public static String var1 = "Oraask"; public static int var2 = 37; } A.var1; A.var2; But be careful because if this class gets unloadRead more
There is no global variable in Java. However, we have a static keyword that we can use to define a global variable by doing something like the below:
But be careful because if this class gets unloaded, you will end up with an undefined null error that is difficult to catch.
See lessHow to get absolute value in java?
Firstly what is absolute value ? it's basically the number value regardless of it's sign so for example if we have a -5 number. So the absolute value of it is 5 without the sign. try below example on any editor to get clear idea : double doubleVar = -130.63; int intVar = 931; double doubleVar2 = 64.Read more
Firstly what is absolute value ?
it’s basically the number value regardless of it’s sign so for example if we have a -5 number. So the absolute value of it is 5 without the sign.
try below example on any editor to get clear idea :
The output of above example is :
Best Regards.
See lessHow to get input in java?
In Java the Scanner class allows the user to take input from the console. It belongs to the java.util package.It is used to read the input of primitive types like int, double, long, short, float, and byte. You can use this example below to understand the way the Scanner class helps to take input froRead more
In Java the Scanner class allows the user to take input from the console. It belongs to the java.util package.It is used to read the input of primitive types like int, double, long, short, float, and byte.
You can use this example below to understand the way the Scanner class helps to take input from the user
import java.util.*;
See lessclass UserInputDemo1
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in); //System.in is a standard input stream
System.out.print(“Enter your name: “);
String str= sc.nextLine(); //reads string
System.out.print(“Your name is : “+str);
}
}
Output :
Your name is : Sourav //In this case I have taken Input as Sourav so it is printing in the console as Your name is : Sourav
What is the difference between i++ and ++i in Java?
They both increment the number with value 1 but but ++i increment the number before the current expression is evaluted, whereas i++ increment the number after the expression is evaluated for example int i=5; int z=i++; //z equals 5 here int x=++i; //x equals 6 here
They both increment the number with value 1
but but ++i increment the number before the current expression is evaluted, whereas i++ increment the number after the expression is evaluated
for example
int i=5;
int z=i++; //z equals 5 here
int x=++i; //x equals 6 here
What does this sign operator “+=” do in java?
Hi @Olivier, it common that z += 5.6 are equivalent to z = z + 5.6, it's one the assignment operators it takes the value of z then add 5.6 to it and at the end store the new result into z ex: double z = 5.5 z += 0.1 // the result of z now is : (5.6) but be careful in java because if "z" is not of tyRead more
Hi Olivier,
it common that z += 5.6 are equivalent to z = z + 5.6, it’s one the assignment operators it takes the value of z then add 5.6 to it and at the end store the new result into z
ex:
but be careful in java because if “z” is not of type double you will get an compilation error.
hope this help.
Fatal Error EXCEPTION ACCESS VIOLATION (0xc0000005) when trying to run WEB (PIA) Server
this may be because of java compatibility, so try to delete all the Java files and cleaned the %PATH% and installed it again.
this may be because of java compatibility, so try to delete all the Java files and cleaned the %PATH% and installed it again.
See lessHow to create ArrayList from array in Java ?
you can use :[code]List<Integer> intList = new ArrayList<Integer>(Arrays.asList(a));[/code]
you can use :
[code]
See lessList<Integer> intList = new ArrayList<Integer>(Arrays.asList(a));
[/code]
How to convert milliseconds to mins, seconds in java ?
you can use java.util.concurrent.TimeUnit class Read more [code] String.format("%d mins, %d secs", TimeUnit.MILLISECONDS.toMinutes(milli), TimeUnit.MILLISECONDS.toSeconds(milli) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(milli)) ); [/code] If TimeUnit or toMinutes are unsupported (Read more
you can use java.util.concurrent.TimeUnit class Read more
[code]
String.format(“%d mins, %d secs”,
TimeUnit.MILLISECONDS.toMinutes(milli),
TimeUnit.MILLISECONDS.toSeconds(milli) –
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(milli))
);
[/code]
If TimeUnit or toMinutes are unsupported (such as on Android before API version 9), use the following equations:
[code]
See lessint seconds = (int) (milliseconds / 1000) % 60 ;
int minutes = (int) ((milliseconds / (1000*60)) % 60);
int hours = (int) ((milliseconds / (1000*60*60)) % 24);
[/code]
How to avoid != null statements in java ?
If you use (or planning to use) JetBrains IntelliJ IDEA, a Java IDE, you can use some particular annotations developed by them. Basically, you've got @Nullable and @NotNull. You can use in method and parameters, like this: [code] @NotNull public static String helloWorld() { return "Hello World"; } [Read more
If you use (or planning to use) JetBrains IntelliJ IDEA, a Java IDE, you can use some particular annotations developed by them.
Basically, you’ve got @Nullable and @NotNull.
You can use in method and parameters, like this:
[code]
@NotNull public static String helloWorld() {
return “Hello World”;
}
[/code]
or
[code]
@Nullable public static String helloWorld() {
return “Hello World”;
}
[/code]
The second example won’t compile (in IntelliJ IDEA).
When you use the first helloWorld() function in another piece of code:
[code]
public static void main(String[] args)
{
String result = helloWorld();
if(result != null) {
System.out.println(result);
}
}
[/code]
Now the IntelliJ IDEA compiler will tell you that the check is useless, since the helloWorld() function won’t return null, ever.
Using parameter
[code]
void someMethod(@NotNull someParameter) { }
[/code]
if you write something like:
[code]
someMethod(null);
[/code]
This won’t compile.
Last example using @Nullable
[code]
@Nullable iWantToDestroyEverything() { return null; }
[/code]
Doing this
[code]
iWantToDestroyEverything().something();
[/code]
And you can be sure that this won’t happen. 🙂
It’s a nice way to let the compiler check something more than it usually does and to enforce your contracts to be stronger. Unfortunately, it’s not supported by all the compilers.
In IntelliJ IDEA 10.5 and on, they added support for any other @Nullable @NotNull implementations.
See blog post More flexible and configurable @Nullable/@NotNull annotations.
See less