In UML, if there’s a class A having an object of type B as member, then A depends on B.
But I haven’t understood if the dependency is valid even if A doesn’t have any field of type B, but it uses an object of type B in it’s method, for example:
public class A
{
A()
{}
public void print()
{
B b=new B();
System.out.println(b);
}
}
This case, would it means that A depends on B?
This all depends on what “depends” means.
In terms of Java, A depends on B when the code for A will not compile or run without B being present.
In terms of UML, “depends” is not a term that is used. If you for example have an arrow from class A to class B in a UML diagram, that means that A somehow knows about B. How that is implemented in the programming language of your choice depends.
Warning: Highly opinionated statement follows!
Avoid UML like the plague. Take it from someone who’s worked with it for a long time.