This is a program which demonstrate the working of parseLong When i run this in bluej it gave me output as as given below
But when i ran this in console in ubuntu terminal by compiling using the command javac it gave me compilation error as given below
Only change i made to compile in javac was changing the line public void main()
to public static void main(String args[])
when i ran in ubuntu terminal
it gave me error as
LongDemo.java:8: error: cannot find symbol
long a = Long.parseLong("1452");
^
symbol: method parseLong(String)
location: class Long
LongDemo.java:9: error: cannot find symbol
long b = Long.parseLong("26");
^
symbol: method parseLong(String)
location: class Long
LongDemo.java:10: error: cannot find symbol
long c = Long.parseLong("54");
^
symbol: method parseLong(String)
location: class Long
3 errors
But when i ran ran using the prefix java.lang.Long.parseLong in ubuntu terminal
it worked fine
Why is it behaving like this in different scenarios
Here is the program
import java.lang.*;
public class LongDemo {
public void main() {
// parses the string argument
long a = Long.parseLong("1452");
long b = Long.parseLong("26");
long c = Long.parseLong("54");
long m = a * b * c;
System.out.print("Value after multiplying = " + m);
}
}
My java version
midhun@midhun-Vostro-15-3568:~$ java -version
openjdk version "11.0.16" 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)
Output Value after multiplying = 2038608