In this section of Java Examples, we are going to illustrate various Java Get
examples like how to get the date and time, IP Address or memory size etc.. If
you are a Java beginner this is a best place for you to learn different methods,
functions and class used in Java Language.
Just go through the given examples to get the things fast and practice these
code at your end to learn java easily. After going through this section you will
be able to retrieve different values whether it is a database size or memory
size using Java programming language.
- Get host name in Java: This example is going to show you how to
retrieve the host name of a particular IP address. Just go through the example
code to see the use of get method in it.
- Retrieve Month from Date using Java:
Learn how to retrieve the
month from given particular date. Example code is given for better learning practice
- IP Address: This Java Get IP Address example, explains how to
retrieve the IP Address of the particular machine.
- Get Memory Size:
With the help of the given Java code you can
easily get the available memory size and can print it on command prompt.
- Total Memory Usage: While going through the example, you will learn
how to obtain the used memory from the total memory using Java program.
- Use of Get Method in Java: What is method and how to use the get
method in Java, this example is going to illustrate you the same thing. Just
check the example and run it at your end as well to learn it quickly.
- Mime Type: It is a technique to describing and attaching
files to internet mail. But in this example you will see how to get the Java
- Get the Month name: If you want to print the name of the month from
the current date, this example is exactly for you.. Go through the code it's
very simple and easy to understand.
- Time in Milliseconds: In this code, we have explained how to get
the time in milliseconds. Go through the syntax to understand how it works.
- Get Array Size
To calculate length of the given array we have used length property. It
returns the length of the given array.
Absolute value is the only value of a number regardless of a prefixed plus or
minus sign. In the example given below we have used abs() method of class
java.lang.Math that returns absolute value of a given number as argument.
- Date and
In the example given below we will see, how to display current date and time
in the user given format. To do all this we have first created instance of the calendar
class that returns object of the same class whose time fields have been
initialized with the current date and time.
- Java get
To print ascii value of a character this is the the simplest way to change
the type a character. Here in the example given below we will select character
from a given string and change their type to integer that will be their ascii
- Class Directory
In this section of example we are going to describe you
how to fetch the class directory's path by the class name. To get the class
directory's name and its path we have used two methods getClass() and getResource()
over an object instance.
- Java program to get class name without package
In this example we are making a simple example which
describes you that how you can get the class name without package.
- Program to get the color of pixel
In this java example program we have to write code for
getting the pixel color of an image. To get the pixel color we need to first
have an image and then we will be able to get the pixel color of any specific or
particular pixel in the RGB format.
- Get column names of a table
In this example of getting the columns names we need to
have connection with the database and then after we will get metadata of this
table and find the columns name within the metadata.
- Java get Blob
Blob is known as 'binary large object', is a collection of binary data stored
as a single entity in a database management system and can hold variable amount
- Get Byte Array from File
In this section, we are going to show the array of bytes from the
specified file. For this, a file 'Hello.txt' is passed into the constructor of
- Calling Class
In this example we will find the name of the class name.
- Calling Method
In this example we will find the name of the method. Provides programmatic access to the stack trace information printed by
printStackTrace(). It returns array of StackTraceElement objects.
- Java get character
In this example given below, we will learn how to read character from keyboard
and display on standard output device.
- Character from String
In this example we will see that how to convert string
to array of character and retrieve elements from that character array one by
- Classes In Package
In this section, you will learn how to retrieve all the classes from the
package by providing the path of the jar file and the package name.
- Get Class Name
In the example given below we will learn how to get name of the particular
class with package name. getName() method returns fully qualified name of the
particular class in string format.
- Java Get Class Location
In this section, you will learn how to get the class location. For this, we
have used the classes URL and ClassLoader.
- Show class path
In this section, you will learn how to get the class path. The method
System.getProperties() determines the current system properties.
- Get Time Stamp
In the example you will learn how to display current time. getTime()
method returns the number of milliseconds represented by Date object that will
be used as argument to create object of
- Java program to get the Command Line Arguments
In java we can get the command line arguments as
they are provided on the console. In this example program our program takes
arguments from the console and print it on the console.
- Get computer name in java
We can get the computer name by the java code program.
For getting computer name we have used java.net.InetAddress class.
- Java Example program to get the current working directory
This example java program illustrates to get the
current working directory (CWD). With the File class object we can get
two types of paths in java.
- Image Size Example
This Example shows you get the image size. Toolkit class is used to bind the different components to specific native toolkit implementations.
- How to get IP Example
This example shows you ip address of your network interface.
- Get Image
This Example shows you get the image.
This example shows you ip address of your network interface.
Print File List in Java
In this section, you will study how to retrieve all the files and folders
from the specified directory.
Code to get Free Space in Java
In this section, you will study how to obtain available free space in the
How to get File Name
In this section, you will study how to obtain the name of file.
GMT Time in Java
In this section, you will study how to obtain the GMT time. GMT stands for Greenwich Mean Time and IST stands for Indian Standard Time.
Java Get Clipboard
In this section, you will study how to use the method getClipboard().
Data type of column field
In this example java program we have to get the data
type of the database table fields.
Show current date
In this example program we have to get the current date
at present now. We have used Calendar class for getting the current date and
We can also get the decimal value in the specified
format as we wish by calling DecimalFormat class. It will format a long
value to the specified string pattern.
We can achieve the default charset
through the java program.
Locale object is a representation of
geographical, political, or cultural region. We can get and set our default
locale through the java programs.
Java program to get the desktop path
In this example program we have to get the desktop path
of the system. In the java environment we can get the desktop path also with the
Java program to get domain name by URL
We can also get the domain name by the java program.
Domain name are used to represent the symbolic representation of numerical
Java example to get Graphics
In this section you will learn how to use the method
Java example program to get IP address of own system
An IP (Internet Protocol) address is a numerical unique
identification number which is assigned to the devices participating in the
network for communication. To get IP address of our own system in a java program
we will be using InetAddress class.
Java example program to
get the operating system's version
You can check your current system's operating system
version by the java code also. For this purpose you have to use the System's
Java example program to get the operating system name
of the system
Many times we need to know the current operating system
name on which we are working. So in java we have "os.name" property
which provides us the information about the current operating system name.
Java example program to get Operating System type or
In java environment we can write java code which will make us enabled to get
the operating system type. We can get the operating system architecture or
system type by using the system property.
Java example program to get the object's ID
In java there is no any specific method that provides
us the object's ID. But each object has its own unique hash value which can be
treated as unique Id for that object.
Java example to get Object class name at runtime
In java there is a way that makes us enabled to get the
object class name at runtime. It can be done by calling the getClass()
method on the class object. Then by calling the method getName() we
can get the name of the object class.
Java example program to get extension
To get the file name and file extension separately we
can do the string manipulation on the file name. Suppose "filename.ext"
is some filename with extension is provided.
Java example to calculate the execution time
This example program will describe you the way that how
one can calculate or get the execution time of a method or program in java. This
can be done by subtracting the starting time of the program or method by the
ending time of the method.
Java example to get the execution path
We can get the execution path of the system in java by
using the system property. For getting execution path we have used "user.dir"
property of the system.
Java example program to get epoch time of windows
Epoch is used to compare dates with the some other
dates or dates with the other time format mathematically. That's why it is being
used through out the whole programming world.
Java example program to get the environment variable
The getenv() method of the java.lang.System
provide us the functionality to get the environment variable value. To get
the single environment variables value we have to call the getenv("environment
variable") method where environment variable is a value that we want to
Java get Next Day
In the given example, we have used the class DateFormatSymbols in
order to get the names of the days of the week. The method getWeekdays()
provide the string of days of week. To get the current day, we have used the
Java get yesterday's date
In the given example, we simply get the current date by using the method dateFormat.format(cal.getTime()).But
on subtracting one day from the calendar by using the method cal.add(Calendar.DATE,
-1), the method dateFormat.format(cal.getTime()) will displayed the
Java get number of days between dates
In order to get the number of days between two dates, the given example has
set two dates by using the Calendar.set(int year, int month, int date).
Java get Year
In this section, you will learn how to obtain the current year. The
Calendar class provides a getInstance() method that returns a Calendar
Java get year from date
In this section you will study how to retrieve the year from the date. You
can see in the given example that we have called SimpleDateFormat class showing the
format of year.
Java get number of Processors
To display the number of processors available to a current Java Virtual
Machine, we have used the method availableProcessors() of class Runtime and the
method getRuntime() returns the instance of Runtime class with the java
Java get Heap Size
In this section, we are going to illustrates you how to obtain the heap size.
The heap is the area in the memory used for memory storage during the runtime of
Java get Screen Dimensions
The Toolkit class has a static method called getDefaultToolkit() and can be
used to obtain the default Toolkit object for the user's system, which contains
information about the user's specific machine.
get number of Days in Month
This example sets the year as 2008, month as Calendar.FEBRUARY and the date
as 1 using the method calendar.set(year, month, date) provided by the class
Java get number of rows in resultset
In this section, you will learn how to retrieve the number of rows from the
database table. As you know that the data is stored in the database table in the
form of row and column.
Java get Http Headers
In this section, we are going to illustrate you how to get the Http Headers.
Here, we are using the URL class which points the resource. In order to make a
communication link between the application and a URL, we have used the class
Java get Filename without Extension
In this section, you will learn how to obtain the filename without extension.
For this, the file name or the directory name is being provided.
Java get available Font
In order to retrieve all the available fonts, we have used the AWT package.
GraphicsEnvironment describes the collection of all the available
GraphicsDevices and Font objects.
Java get Free Memory
In this section, we are going to obtain the free memory. In order to get the
memory left of being allocated, the method getruntime() returns the runtime
object associated with the Java application.
Java get Folder Size
In the given example, we are going to show you the size of specified folder
and also the number of files and folders that are presented in the specified