Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in toturials, it say to invoke a method from external package first it is needed to create an object from the class, and then use the period to invoke the method:

1. packageclassname objectname = new packageclassname();
2. objectname.themethod();


but most the libraries found on the net, use the method like this:

import java.io.IOException;  
import org.jsoup.Jsoup;  
import org.jsoup.nodes.Document;  
public class FirstJsoupExample{  
    public static void main( String[] args ) throws IOException{  
                Document doc = Jsoup.connect("http://www.javatpoint.com").get();  
                String title = doc.title();  
                System.out.println("title is: " + title);  
    }  
} 


what is exactly the
Document doc = Jsoup.connect("http://www.javatpoint.com").get();
section? since it doesn't look like creating an object neither apears like invoking a method using an onject name?

What I have tried:

in several toturials on the net, including the oracle toturial, they all use the usual way which is mentionaed at the first:

1. packageclassname objectname = new packageclassname();
2. objectname.themethod();
Posted
Updated 20-Mar-22 21:33pm
Comments
Richard MacCutchan 21-Mar-22 4:36am    
If you read the Jsoup documentation you will see the answer.

1 solution

Jsoup.connect is a static method (i.e. you don't need an object instance in order to to call it) that returns a Connection object (see HttpConnection (jsoup Java HTML Parser 1.14.3 API)[^] ). In turn, the method get of the Connection object returns a Document object (see Connection (jsoup Java HTML Parser 1.14.3 API)[^] ).
The code you posted is a shortcut for
Java
//..
Connection conn = Jsoup.connect("http://www.javatpoint.com"); // static method returning a connection object
//..
Document doc = conn.get(); // 'standard' method of the Connection object, returning a Document object.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900