Home Java Java-get-example Java Get Method

Related Tutorials


 
 

Share on Google+Share on Google+

Java Get Method

Advertisement
In this example you will learn how to use the get method in Java.

Java Get Method

     

In this example you will learn how to use the get method in Java.

Java provides various methods and functions that makes this language easy to learn and use. So just go through the below given example code to see when and how to use get method in Java. 

The example is going to show the date details.. including year, date and month etc.. with the use of get method.

 

 

Code for Java Get Method

import java.util.Calendar;
public class GetMethod  {
 public static void main(String[] av) {
 Calendar cal = Calendar.getInstance(); 
  System.out.println("Year: " + cal.get(Calendar.YEAR));
  System.out.println("Month: " + cal.get(Calendar.MONTH));
  System.out.println("Day: " + cal.get(Calendar.DAY_OF_MONTH));
  System.out.println("Day of week = " + cal.get(Calendar.DAY_OF_WEEK));
  System.out.println("Day of year = " + cal.get(Calendar.DAY_OF_YEAR));
  System.out.println("Week in Year: " + cal.get(Calendar.WEEK_OF_YEAR));
  System.out.println("Week in Month: " + cal.get(Calendar.WEEK_OF_MONTH));
  System.out.println("Day of Week in Month: "
  + cal.get(Calendar.DAY_OF_WEEK_IN_MONTH));
  System.out.println("Hour (24-hour clock): "
  + cal.get(Calendar.HOUR_OF_DAY));
  System.out.println("Minute: " + cal.get(Calendar.MINUTE));
  System.out.println("Second: " + cal.get(Calendar.SECOND));
  }
}

Output will be displayed as:

Download Source Code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 15, 2008

Related Tutorials

Discuss: Java Get Method   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
sagar
December 24, 2013
Adv JAVA

awsome website...
DMCA.com