-1

I am new to Java and I came to know about -classpath and -cp . I have a question about them.

Q1) Are -classpath and -cp same or is there any difference between them ?

Q2) Also I read this :

Setting the CLASSPATH can be tricky and should be performed with care.

here Java Doc and Just wanted to know why said it like this ? Why should I be careful while using it ?

Thanks in Advance.

praggi
  • 7
  • 4

2 Answers2

0

1 -cp and -classpath both are same

2

Setting the CLASSPATH can be tricky and should be performed with care.

Here author is referring to CLASSPATH environment variable, if you set this environment variable all the jvm will get the set classpath by default

You don't know what all JVM are going to run in advance and so setting this env variable is tricky

jmj
  • 237,923
  • 42
  • 401
  • 438
0

The flags -classpath and -cp are identical. One is just provided as a short form of the other.

These flags add to the class path for an individual invocation of Java. This is appropriate, since you typically need the application to have access to some extra classes.

Setting the CLASSPATH environment variable will affect all invocations. This could affect the default classes loaded. That's why it's not recommended unless you know what you're doing.

Hod
  • 2,236
  • 1
  • 14
  • 22