Website name in java program [duplicate] - java

This question already has answers here:
My java code has an obvious error. Why does it compile and run?
(2 answers)
Why doesn't putting a random http link in code cause a compilation error? [duplicate]
(2 answers)
Closed 9 years ago.
public class Main
{
public static void main(String[] args)
{
http://google.com
System.out.println("Welcome");
}
}
Why is this code not getting a compilation error? and why did it get a compilation error if we write this url name after System.out.println("Welcome"); ??

Because it's a label followed by a comment.

Related

I have an error in my Java program, it is visible on Eclipse IDE [duplicate]

This question already has answers here:
What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?
(26 answers)
What is the "String args[]" parameter in the main method?
(18 answers)
Closed 1 year ago.
I have the same error in every code I run on Eclipse IDE or on Notepad, Also it was not earlier. In this code I also having same error which I mentioned below
Code:
package WorkJava;
public class TypeCast{
public static void main(String ar[]) {
int sum=0;
for(int i=0;i<5;i++) {
int a=Integer.parseInt(ar[i]);
sum=sum+a;
}
System.out.println("the sum="+sum);
}
error:-
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at WorkJava.TypeCast.main(TypeCast.java:1
you are getting the error because you are not passing program arguments so to pass it in eclipse open your class click run on the menu bar the run configurations then argument then in program arguments type 5 integers like the following with spaces.
2 0 4 5 6

Error: Could not find or load main class Check.java [duplicate]

This question already has answers here:
How to run a .class file that is part of a package from cmd?
(13 answers)
Closed 2 years ago.
I have Check class in my ua.kiev.prog package.
It is Checkclass :
package main.java.ua.kiev.prog;
public class Check {
public static void main(String[] args) {
System.out.println("Hello world");}
}
I need to run program from console and I am trying in console :
C:\PROJECTS FOR FOXMINDED\CHECK\src\main\java\ua\kiev\prog>javac Check.java
And when I am trying to run :
C:\PROJECTS FOR FOXMINDED\CHECK\src\main\java\ua\kiev\prog>java Check.java
Error: Could not find or load main class Check.java
In my system variables I have :
CLASSPATH : D:\Java\jdk1.8.0_202\lib
PATH : D:\Java\jdk1.8.0_202\bin
Appreciate for each help!
The (qualified) name of your class is main.java.ua.kiev.prog.Check, not Check.java, so use java main.java.ua.kiev.prog.Check instead. The java command doesn't and cannot do anything with source files.
Make sure you're running from C:\PROJECTS FOR FOXMINDED\CHECK\src

Why does java assertion have no effect? [duplicate]

This question already has answers here:
Assertion not working
(3 answers)
Closed 2 years ago.
i have this code:
public class C {
public static void main(String[] args) {
assert (9 < 6):"wrong";
System.out.println("ok");
}
}
I compile with "javac C.java".
I execute with "java C".
It prints "ok". Why does it not work?
Best regards.
as assertions are usually used for debugging they need to be enabled explicitly. hence, add -ea or -enableassertions parameter when starting your program java -ea C

How this program compiled and run successfully? [duplicate]

This question already has answers here:
Java Label usage [duplicate]
(2 answers)
Closed 6 years ago.
The below program compiled successfully and run without any errors. As per my understanding is should have thrown error in line 4. Can somebody explain?
class Test{
public static void main(String args[]) {
// my favorite website is
http://www.stackoverflow.com/questions/ask
System.out.println("hello world");
}
}
No, it's not an error, "http:" works here as the name of the label and "//" starts the comments which is ignored.

Running .class file from cmd [duplicate]

This question already has answers here:
What does "Could not find or load main class" mean?
(61 answers)
Closed 8 years ago.
Thats code:
package helloWorld;
public class helloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
What's wrong? I am pretty newb.
You need to specify the classpath:
java -cp C:\Users\jklh\Desktop\java_files\helloWorld\bin helloWorld.helloWorld

Categories