Science Cyber

السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ

أَعُوْذُ بِاللِه مِنَ الشََّيْطَانِ الرَّجِيْمِ - بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ

Kumpulan JAVA Programming

Kumpulan materi JAVA
import java.net.*;
class addressIp
{
public static void main (String args[])
{
if (args.length > 0)
{
try
{
// cari semua ip address
InetAddress[] address = InetAddress.getAllByName(args[0]);
// tampilkan semua ip address yang didapat
for (int i=0; i{
System.out.println("Nama: " + address[i].getHostName());
System.out.println("Alamat: " + address[i].getHostAddress());
}
}
// ip address tidak ditemukan
catch (UnknownHostException e)
{
System.out.println("Alamat komputer tidak ditemukan.");
}
} else // argumen tidak ada, tampilkan cara pemakaian program
{
System.out.println("Jalankan dengan perintah: java address \"nama_komputer\"");
System.out.println("Contoh:");
System.out.println("java address google.com");
}
}
}


import java.io.*;
class input2
{
public static void main(String[] args) throws IOException
{
int angka1, angka2;
BufferedReader br;
br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Masukkan Angka1 : ");
angka1 = Integer.parseInt(br.readLine());
System.out.print("Masukkan Angka2 : ");
angka2 = Integer.parseInt(br.readLine());
System.out.println("Angka1 Anda : "+ angka1);
System.out.println("Angka2 Anda : "+ angka2);
}
}

import java.io.*;
class input3
{
public static void main(String[] args) throws IOException
{
int angka1, angka2,jumlah;
BufferedReader br;
br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Masukkan Angka1 : ");
angka1 = Integer.parseInt(br.readLine());
System.out.print("Masukkan Angka2 : ");
angka2 = Integer.parseInt(br.readLine());
System.out.println("Angka1 Anda : "+ angka1);
System.out.println("Angka2 Anda : "+ angka2);
jumlah=angka1 + angka2;
System.out.println("Angka1 + Angka2 : "+ jumlah);
}
}


import java.io.*;
class input4
{
public static void main(String[] args) throws IOException
{
String nama,nim;
int uts,uas;
BufferedReader br;
br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Masukkan Nama Anda : ");
nama= br.readLine();
System.out.print("Masukkan Nim Anda : ");
nim= br.readLine();
System.out.print("Masukkan Nilai UTS : ");
uts = Integer.parseInt(br.readLine());
System.out.print("Masukkan Nilai UAS : ");
uas = Integer.parseInt(br.readLine());
System.out.println("Nama : "+ nama);
System.out.println("Nim : "+ nim);
System.out.println("Nilai UTS : "+ uts);
System.out.println("Nilai UAS : "+ uas);
}
}

import java.net.*;
class myAddress
{
public static void main (String args[])
{
try
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
}
catch (UnknownHostException e)
{
System.out.println("Could not find this computer's address.");
}
}
}

import java.net.*;
class myAddress2
{
public static void main (String args[])
{
try
{
InetAddress address = InetAddress.getByName("www.unisbank.ac.id");
System.out.println(address);
}
catch (UnknownHostException e)
{
System.out.println("Could not find this computer's address.");
}
}
}



import java.net.*;
class myAddressLooping
{
public static void main (String args[])
{
try
{
InetAddress[] address = InetAddress.getAllByName("www.google.com");
for (int i=0; i < address.length; i++)
System.out.println(address [i]);
}
catch (UnknownHostException e)
{
System.out.println("Could not find this computer's address.");
}
}
}



import java.net.*;
import java.io.*;
public class myport
{
public static void main(String[] args)
{
Socket theSocket;
String host = "11.0.3.10";
for (int i = 20; i <=80; i++)
{
try
{
theSocket = new Socket(host, i);
System.out.println("There is a server on port " + i + " of " + host);
}
catch (UnknownHostException e)
{
System.err.println(e);
break;
}
catch (IOException e)
{ }
}
}
}



import java.io.*;
import java.net.*;

public class Reverse {
public static void main(String[] args)throws Exception{
if(args.length !=2){
System.err.println("Usage Error");
System.exit(1);
}

String stringToReverse= URLEncoder.encode(args[1], " UTF-8");

URL url=new URL(args[0]);
URLConnection connection=url.openConnection();
connection.setDoOutput(true);

OutputStreamWriter out=new OutputStreamWriter(connection.getOutputStream());
out.write("string=" + stringToReverse);
out.close();

BufferedReader in= new BufferedReader(new InputStreamReader(connection.getInputStream()));
String decodedString;

while ((decodedString=in.readLine())!=null){
System.out.println(decodedString);
}
in.close();
}
}


import java.net.*;
import java.io.*;
public class serverport
{
public static void main(String[] args)
{
ServerSocket theServer;
for (int i = 1024; i <= 4000; i++)
{
try
{
theServer = new ServerSocket(i);
theServer.close();
}
catch (IOException e)
{
System.out.println("There is a server on port " + i + ".");
}
}
}
}

import java.net.*;
import java.io.*;
public class URLConnectionReader
{
public static void main(String[] args) throws Exception
{
URL alamat = new URL("http://www.unisbank.ac.id");
URLConnection yc = alamat.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}


import java.net.*;
import java.io.*;
public class URLConnectionReader
{
public static void main(String[] args) throws Exception
{
URL alamat = new URL("http://www.unisbank.ac.id");
URLConnection yc = alamat.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}


import java.net.*;
public class urltest1 {
public static void main (String args[]) {
URL webURL, ftpURL;
try {
webURL = new URL("http://www.macfaq.com/vendor.html");
System.out.println(webURL);
ftpURL = new URL("ftq://ftp1.macfaq.com/pub/");
System.out.println(ftpURL);
}
catch (MalformedURLException e) {
System.err.println("URL Salah");
}
}
}



import java.net.*;
public class urltest2
{
public static void main (String args[])
{
URL webURL,ftpURL;
try
{
webURL = new URL("http://he:ri@www.macfaq.com:81/a/bc/def/vendor.html?s=a#AKHIR");
System.out.println(webURL);
String auth, file, host, path, protocol, query, ref, user;
auth = webURL.getAuthority();
System.out.println("Authority = " +auth);
file = webURL.getFile();
System.out.println("File = "+file);
host = webURL.getHost();
System.out.println("Host = "+host);
protocol = webURL.getProtocol();
System.out.println("Protokol = "+protocol);
query = webURL.getQuery();
System.out.println("Query = "+query);
ref = webURL.getRef();
System.out.println("Ref = "+ref);
int port,def_port;
port = webURL.getPort();
System.out.println("Port = "+port);
def_port = webURL.getDefaultPort();
System.out.println("Default Port = "+def_port);
path = webURL.getPath();
System.out.println("Path = "+path);
user = webURL.getUserInfo();
System.out.println("User Info = "+user);
}
catch (MalformedURLException e)
{
System.err.println("URL Salah");
}
}
}

No comments:

والله أعلم بالصواب

وَعَلَيْكُمْ السَّلاَمُ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ