java.net.PasswordAuthentication Class in Java Last Updated : 28 Mar, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report PasswordAuthentication class is provided by package java.net for implementing networking applications, and it is used in those cases when it is required to hold the data that will be used by the Authenticator. It holds the username and password. Syntax of its constructors : PasswordAuthentication(String userName, char[] password)This will create new PasswordAuthentication object for the given username and password. The given user password is cloned before it is stored in the new PasswordAuthentication object. Method Return TypegetUserName()Returns the username.getPassword()Returns the user password.Method details: getUserName() : This will give the username and is return a string value.getPassword() : This will return user password and return char array.Methods it inherited from class java.lang.Object : equals()toString()hashCode()clone()getClass()finalize()notify()notifyAll() Java // Java Program to illustrate the // java.net.PasswordAuthentication // Class import java.io.*; import java.net.PasswordAuthentication; class GFG { public static void main(String args[]) { GFG acc = new GFG(); acc.proceed(); } private void proceed() { // Initializing the user name String userName = "Geek"; // Initializing the password - This is a char // array since the PasswordAuthentication // supports this argument char[] password = { 'g', 'e', 'e', 'k', 'g', 'o', 'r', 'g', 'e', 'e', 'k', 's' }; PasswordAuthentication passwordAuthentication = new PasswordAuthentication(userName, password); System.out.println( "UserName: " + passwordAuthentication.getUserName()); // The below getPassword actually returns the // reference to the password as per the Java API // documentation. System.out.println( "Password: " + passwordAuthentication.getPassword()); // You can get the password in normal string System.out.println( "Password: " + String.copyValueOf( passwordAuthentication.getPassword())); } } OutputUserName: Geek Password: [C@4e50df2e Password: geekgorgeeks Comment More infoAdvertise with us Next Article java.net.URLConnection Class in Java M maheswaripiyush9 Follow Improve Article Tags : Java Java-net-package Practice Tags : Java Similar Reads java.net.URLConnection Class in Java URLConnection Class in Java is an abstract class that represents a connection of a resource as specified by the corresponding URL. It is imported by the java.net package. The URLConnection class is utilized for serving two different yet related purposes, Firstly it provides control on interaction wi 5 min read java.net.SecureCacheResponse Class in Java The SecureCacheResponse Class in Java represents a cache response originally retrieved through secure means. Syntax: Class Declaration public abstract class SecureCacheResponse extends CacheResponse The constructor for this class is as follows SecureCacheResponse() Now, the methods of this class are 3 min read Java.util.jar.JarEntry class in Java This class is used to represent a JAR file entry. Constructors : JarEntry(JarEntry je) : Creates a new JarEntry with fields taken from the specified JarEntry object. JarEntry(String name) : Creates a new JarEntry for the specified JAR file entry name. JarEntry(ZipEntry ze) : Creates a new JarEntry w 2 min read Console readPassword() method in Java with Examples The readPassword() method of Console class in Java is of two types: 1. The readPassword() method of Console class in Java is used to read a password or passphrase from the console with disabled echoing. Syntax: public char[] readPassword() Parameters: This method does not accept any parameter. Retur 4 min read Generating Password and OTP in Java You may go through the generate a one time password or unique identification url article before this for a better understanding of how to generate passwords and OTP in Java. Have you ever clicked on "Forgot Password" and received a new password or OTP instantly on your email or phone? This process u 5 min read Java.net.JarURLConnection class in Java Prerequisite - JAR files in Java What is a Jar file? JavaArchive(JAR) bundles all the classes in one package. Since the archive is compressed and can be downloaded in a single HTTP connection, it is often faster to download the archive than to download individual classes. Although jar bundles all th 4 min read Like