- getAddress() : InetAddress 클래스가 가지고 있는 IP주소의 byte 배열 가져옴

- getHostAddress() : IP주소 문자열로 가져옴

- getHostName() : hostname을 문자열로 나타냄

- getByName(String host) : host의 IP 주소를 가져옴

- getLocalhost() : 사용자의 시스템 IP 주소를 가져옴


import java.net.InetAddress;


public class dailyCode {

public static void main(String[] args) {

try{

String google = "www.google.com";

String naver = "www.naver.com";

InetAddress googleAddr = InetAddress.getByName(google);

String googleName = googleAddr.getHostName();

String googleAddress = googleAddr.getHostAddress();

System.out.println("googleAddr = " + googleAddr);

System.out.println("googleName = " + googleName + ", googleAddress = " + googleAddress);

InetAddress local = InetAddress.getLocalHost();

byte[] localAddr = local.getAddress();

System.out.println("local = " + local);

for(int i=0; i<localAddr.length; i++){

System.out.print((localAddr[i]<0?(localAddr[i]+256):localAddr[i]));

if(i < localAddr.length-1){

System.out.print(".");

}

}

}catch(Exception e) {

e.printStackTrace();

}

}


'프로그래밍 > JAVA' 카테고리의 다른 글

LinkedList Implementation  (0) 2016.11.29
How to get google server time (URLConnection Example)  (0) 2016.11.27
URL class Example  (0) 2016.11.27
람다 표현식 (Lambda Expression)  (0) 2016.11.24
Arrays class Example  (0) 2016.11.23
Hashtable and HashMap Example  (0) 2016.11.21
Generics and Wildcard  (0) 2016.11.20



-Java8에서 지원하는 Lambda expression은 복잡한 메소드를 간결하게 형태의 함수 프로그래밍이 가능하도록 한다.


interface Anonymous{

public void printName();

}


public class dailyCode {

public static void main(String[] args) {

Anonymous test = new Anonymous() {

@Override

public void printName() {

System.out.println("anonymous class");

}

};

test.printName();

Anonymous lamdaTest = ()-> System.out.println("lambda expression");

lamdaTest.printName();

}


'프로그래밍 > JAVA' 카테고리의 다른 글

How to get google server time (URLConnection Example)  (0) 2016.11.27
URL class Example  (0) 2016.11.27
Find Google IP (InetAddress class Example)  (0) 2016.11.25
Arrays class Example  (0) 2016.11.23
Hashtable and HashMap Example  (0) 2016.11.21
Generics and Wildcard  (0) 2016.11.20
arraycopy Example  (0) 2016.11.19




Arrays.fill(int[] a, int fromIndex, int toIndex, int val) : fromIndex이상 toIndex미만의 index를 val로 채움


import java.util.Arrays;

import java.util.HashMap;

import java.util.Hashtable;

import java.util.Set;


public class dailyCode {

public static void main(String[] args) {

int[] arr = {1, 2, 3, 4, 5};

int[] order = {4, 1, 3, 5, 2};

Arrays.fill(arr, 0);

for(int num : arr) {

System.out.println("num : " + num);

}

System.out.println("-------");

Arrays.fill(arr, 1, 4, 8);

for(int num : arr) {

System.out.println("num : " + num);

}

System.out.println("-------");


Arrays.sort(order);

for(int num : order) {

System.out.println("num : " + num);

}

}


'프로그래밍 > JAVA' 카테고리의 다른 글

URL class Example  (0) 2016.11.27
Find Google IP (InetAddress class Example)  (0) 2016.11.25
람다 표현식 (Lambda Expression)  (0) 2016.11.24
Hashtable and HashMap Example  (0) 2016.11.21
Generics and Wildcard  (0) 2016.11.20
arraycopy Example  (0) 2016.11.19
scheduleAtFixedRate vs. scheduleWithFixedDelay  (0) 2016.11.18

+ Recent posts