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.
Java Get Examples..
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 evaluate.
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 Calendar class.
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 yesterday's date.
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 object.
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 application.
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 the program.
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 Calendar.
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 URLConnection.
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. The class 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 folder.
Liked it! Share this Tutorial