1. Java Program to Find IP Address

In this program we will find IP address by using InetAddress class present in java.net package. Method getLocalHost() prints the IP of your local machine while method getByName() prints the IP of a particular URL.

Also Read: Java Program to Find Union of two Arrays

Program:-

import java.net.*;

class FindIP
{
public static void main(String...s)throws Exception
{
System.out.println(InetAddress.getLocalHost());
System.out.println(InetAddress.getByName("www.google.com"));
}
}

Java Program to Find IP Address

2. Java Program to Take Screenshots


There might be a situation where you guys want to take screen shots programmatically. So I am sharing a program that help you to take screen capture of your screen and save it in PNG (Portable network graphic) picture format.

Java Program to Take Screenshots

The below program uses Java.awt.Robot class to capture the screen pixels and uses Imageio to save it as PNG image format. Just copy and paste the program in Notepad, save it and run the program to take screen shot.

Note: The Screen shot image will be stored at the location where your program is stored.
01import java.awt.Rectangle;
02import java.awt.Robot;
03import java.awt.Toolkit;
04import java.awt.image.BufferedImage;
05import java.io.*;
06import javax.imageio.*;
07
08class Snap
09{
10 public static void main(String args[]) throws Exception
11 {
12  Robot awt_robot = new Robot();
13  BufferedImage Entire_Screen = awt_robot.createScreenCapture(newRectangle(Toolkit.getDefaultToolkit().getScreenSize()));
14  ImageIO.write(Entire_Screen, "PNG"new File("Entire_Screen.png"));
15 }
16}

If you liked the article please do share!!


Source: http://viralpatel.net/blogs/how-to-take-screen-shots-in-java-taking-screenshots-java/

0 comments :

Please Enter best of your Comments