650). What does URL stands for?
[A]Uniform Resource Locator
[B]Uniform Resource Latch
[C]Universal Resource Locator
[D]Universal Resource Latch
Show Answer
Correct Answer: Uniform Resource Locator
Notes:
Answer: a
Explanation: URL is Uniform Resource Locator.
651). Which of these exceptions is thrown by URL class’s constructors?
[A] URLNotFound
[B]URLSourceNotFound
[C]MalformedURLException
[D]URLNotFoundException
Show Answer
Correct Answer: MalformedURLException
Notes:
Answer: c
Explanation: None.
652). Which of these methods is used to know host of an URL?
[A] host()
[B]getHost()
[C]GetHost()
[D]gethost()
Show Answer
Correct Answer: getHost()
Notes:
Answer: b
Explanation: None.
653). Which of these methods is used to know the full URL of an URL object?
[A] fullHost()
[B]getHost()
[C]ExternalForm()
[D]toExternalForm()
Show Answer
Correct Answer: toExternalForm()
Notes:
Answer: d
Explanation: None.
654). Which of these class is used to access actual bits or content information of a URL?
[A]URL
[B]URLDecoder
[C]URLConnection
[D]All of the mentioned
Show Answer
Correct Answer: All of the mentioned
Notes:
Answer: d
Explanation: URL, URLDecoder and URLConnection all there are used to access information stored in a URL.
655). What will be the output of the following Java code?
import java.net.*;
class networking
{
public static void main(String[] args) throws MalformedURLException
{
URL obj = new URL("https://www.sanfoundry.com/javamcq");
System.out.print(obj.getProtocol());
}
}
[A]http
[B]https
[C]www
[D]com
Show Answer
Correct Answer: http
Notes:
Answer: a
Explanation: obj.getProtocol() is used to know the protocol used by the host. http stands for hypertext transfer protocol, usually 2 types of protocols are used http and https, where s in https stands for secured.
Output:$ javac networking.java
$ java networking
http
656). What will be the output of the following Java program?
import java.net.*;
class networking
{
public static void main(String[] args) throws MalformedURLException
{
URL obj = new URL("https://www.sanfoundry.com/javamcq");
System.out.print(obj.getPort());
}
}
[A]1
[B]0
[C]-1
[D]garbage value
Show Answer
Correct Answer: -1
Notes:
Answer: c
Explanation: Since we have not explicitly set the port default value that is -1 is printed.
Output:
$ javac networking.java
$ java networking
-1
657). What will be the output of the following Java program?
import java.net.*;
class networking
{
public static void main(String[] args) throws MalformedURLException
{
URL obj = new URL("https://www.sanfoundry.com/javamcq");
System.out.print(obj.getHost());
}
}
[A]sanfoundry
[B]sanfoundry.com
[C] www.sanfoundry.com
[D] https://www.sanfoundry.com/javamcq
Show Answer
Correct Answer: www.sanfoundry.com
Notes:
Answer: c
Explanation: None.
Output:
$ javac networking.java
$ java networking
www.sanfoundry.com
658). What will be the output of the following Java program?
import java.net.*;
class networking
{
public static void main(String[] args) throws MalformedURLException
{
URL obj = new URL("https://www.sanfoundry.com/javamcq");
System.out.print(obj.toExternalForm());
}
}
[A]sanfoundry
[B]sanfoundry.com
[C]www.sanfoundry.com
[D]https://www.sanfoundry.com/javamcq
Show Answer
Correct Answer: https://www.sanfoundry.com/javamcq
Notes:
Answer: d
Explanation: toExternalForm() is used to know the full URL of an URL object.
Output:
$ javac networking.java
$ java networking
https://www.sanfoundry.com/javamcq