Skip to content

Commit 19a5b1f

Browse files
committed
initial commit
0 parents  commit 19a5b1f

8 files changed

Lines changed: 104 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lib/
2+
.vscode/
3+

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Getting Started
2+
3+
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
4+
5+
## Folder Structure
6+
7+
The workspace contains two folders by default, where:
8+
9+
- `src`: the folder to maintain sources
10+
- `lib`: the folder to maintain dependencies
11+
12+
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
13+
14+
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
15+
16+
## Dependency Management
17+
18+
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).

src/App.class

461 Bytes
Binary file not shown.

src/App.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class App {
2+
public static void main(String[] args) throws Exception {
3+
System.out.println("Hello, World!");
4+
}
5+
}

src/network_get.class

1.87 KB
Binary file not shown.

src/network_get.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.io.*;
2+
import java.net.HttpURLConnection;
3+
import java.net.URL;
4+
5+
public class network_get {
6+
public static void main(String[] args) throws IOException {
7+
URL url = new URL("https://jsonplaceholder.typicode.com/posts/1");
8+
HttpURLConnection con = (HttpURLConnection) url.openConnection();
9+
con.setRequestMethod("GET");
10+
11+
int status = con.getResponseCode();
12+
BufferedReader in = new BufferedReader(
13+
new InputStreamReader(con.getInputStream()));
14+
String inputLine;
15+
StringBuilder content = new StringBuilder();
16+
while ((inputLine = in.readLine()) != null) {
17+
content.append(inputLine);
18+
}
19+
in.close();
20+
21+
System.out.println("Response Code: "+status);
22+
System.out.println("GET Post: "+content);
23+
System.out.println();
24+
}
25+
}

src/network_post.class

2.48 KB
Binary file not shown.

src/network_post.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import java.io.*;
2+
import java.net.HttpURLConnection;
3+
import java.net.MalformedURLException;
4+
import java.net.URL;
5+
6+
public class network_post {
7+
public static void main(String[] args) throws MalformedURLException,
8+
9+
IOException {
10+
11+
URL myUrl = new URL("https://jsonplaceholder.typicode.com/posts/");
12+
HttpURLConnection conn = (HttpURLConnection) myUrl.openConnection();
13+
14+
conn.setRequestMethod("POST");
15+
16+
conn.setDoOutput(true);
17+
18+
OutputStream out = conn.getOutputStream();
19+
20+
String postedString = "Hi!!! We have posted something!!! Yay!!!";
21+
22+
out.write(postedString.getBytes());
23+
24+
int responseCode = conn.getResponseCode();
25+
System.out.print("Value of http created is: " + conn.HTTP_CREATED + "\n");
26+
if (responseCode == conn.HTTP_CREATED) {
27+
System.out.print("This is the response Code: " + responseCode + "\n");
28+
System.out.print("This is the response Message from server: " + conn.
29+
30+
getResponseMessage() + "\n");
31+
32+
} else
33+
System.out.print("GO HOME EVERYBODY :( ");
34+
35+
InputStreamReader in = new InputStreamReader(conn.getInputStream());
36+
37+
BufferedReader buffer = new BufferedReader(in);
38+
39+
StringBuffer fromServer = new StringBuffer();
40+
41+
String eachLine = null;
42+
43+
while ((eachLine = buffer.readLine()) != null) {
44+
fromServer.append(eachLine);
45+
fromServer.append(System.lineSeparator());
46+
}
47+
48+
buffer.close();
49+
50+
System.out.print("Here is our posted content :\n" + fromServer);
51+
System.out.println();
52+
}
53+
}

0 commit comments

Comments
 (0)