-1
public class TransparentProxy {
private static ProxyServer _proxyserver = null;
private static TransparentProxy _instance = null;

public TransparentProxy() {

}

public static void main(String args[]) throws Exception {
    TransparentProxy.getInstance();
}

I understand everything except the public TransparentProxy() {}. Why is it empty? What is its purpose? Why is it exempt from having a return type? I have looked it up but can't get an exact answer. Thanks

3 Answers3

0

From the tutorial of the initial part of - Learning the Java Language

A class contains constructors that are invoked to create objects from the class blueprint.
Constructor declarations look like method declarations—except that they use the name of the class and have no return type.

You don't have to provide any constructors for your class, but you must be careful when doing this. The compiler automatically provides a no-argument, default constructor for any class without constructors. This default constructor will call the no-argument constructor of the superclass.

It looks like you've not read through the basics of Java language yet, you should go through them.

Community
  • 1
  • 1
Swapnil
  • 8,201
  • 4
  • 38
  • 57
0

This is an empty constructor. It has no return types and named as the class name.

An empty constructor is needed to create a new instance via reflection by your persistence framework. If you don't provide any additional constructors with arguments for the class, you don't need to provide an empty constructor because you get one per default.

Kaidul
  • 15,409
  • 15
  • 81
  • 150
0

public TransparentProxy() {} ---is a Constructor

Java constructors are the methods with the same name as the Class with no return type/value. They are called or invoked when an object of class is created and can't be called explicitly. An object of a class is created using the new keyword. Ex: TransparentProxy proxy = new TransparentProxy();

Three types of Constructors are present.

1. Default Constructor

JVM internally declares a constructor when no constructor in specified. This is to allow a class to create an instance of it. Also, an Interface in Java does not have a constructor and hence no instances/object can be created.

2. Zero argument Constructor

A constructor defined with no arguments is called a Zero argument Constructor. You may use it to initialize variables to some value to begin with. All objects/instances of the class will have the same initial values.

3. Constructor with arguments

Its a constructor defined with arguments which initialize the variables of the class at the time of object creation. Every object/instance created of that class will have different initial values depending on the values passed to the constructor.

A constructor can be overloaded with different type of arguments or the number of arguments. It cannot be overrided in a sub class.

Read here -- Why do constructors not return values?

Community
  • 1
  • 1