Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Get first day of week

                         

In this section, we will learn how to get the first day of  week in Java. As we know that GregorianCalendar provides the current date, month and year in a yearly calendar. Use the Calendar subclass for applying in the java program. This calendar is used in most of world. 

Description of program:

The following program helps us in getting the first day of the week. For getting first day we need an object of GragorianCalendar. With the help of this we calculate the first day of week using the getFirstDayOf Week() and getActualMaximum(Calendar.DAY_OF_WEEK) methods that matches the case. If any of these will match, it will display the actual day that displays like the following output.

Description of code:

getActualMaximum(int field):
This method return the maximum value according to its field. It takes one field like: DAY_OF_WEEK, DAY_OF_MONTH etc.

getFirstDayOfWeek():
This is the method that is used to get the first day of the week.

Here is the code of program:

import java.util.*;

public class FirstDayOfWeek{
  public static void main(String[] args) {
    GregorianCalendar gcal = new GregorianCalendar();
    int week = gcal.getActualMaximum(Calendar.DAY_OF_WEEK);
    System.out.println("Day of week: " + week);
    int first = gcal.getFirstDayOfWeek() ;
    switch(first){
      case 1:
        System.out.println("Sunday");
      break;
      case 2:
        System.out.println("Monday");
      case 3:
        System.out.println("Tuesday");
      case 4:
        System.out.println("Wednesday");
      case 5:
        System.out.println("Thrusday");
      case 6:
        System.out.println("Friday");
      case 7:
        System.out.println("Saturday");
    }
  }
}

Download this example.

Output of program:

C:\vinod\Math_package>javac FirstDayOfWeek.java

C:\vinod\Math_package>java FirstDayOfWeek
Day of week: 7
Sunday

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
netbeans jsp jdbc
Javascript Menus Image
Java listener
change color in JTabl
standered jar to downl
java.lang.ArrayIndexOu
AND Operator
Photoshop Drawing Cand
insert data to databas
JAVA RMI
create file folder
java converstion
slection model in jdbc
type Conversion in JSF
max chars 500 chars i
compare words from a t
java applets
send redirect
what is static inner c
how to get the checkbo
Heap Sort in C
Tracing in a multithre
MemoryImageSource(widt
retrieve data to text
source code for chat p
phone number validatio
display image from dat
Convert Integer to Flo
struts2 example
Combattons la programm
jspcode
Apache MyFaces
program with an except
array element in php
weblogic server
JComboBox
a sample example forh
radio button using tld
struts2 enum
remove rectangle
two dimensional array
manage
filereader
Session Tracking
builb.xml
unicode
ASP EXAMPLE' and 1=1 a
header footer menu bod
portlet spring
java system package
create txt file in spe
populate dropdown in j
Replace
java excel
Player Class in the Ja
printing jdbc batch qu
add one tree object co
rmi jdbc connection
myfaces tomahawk
how to pass same varia
Passing Parameters in
covert uppercase to lo
Java Swing Center a Di
java script to get par
token string
Jini's relevance emerg
treemap with comparabl
java set methods
java registration form
How to write JSP
java application code
insert fields blob
pst.setInt()
jboss
buffer reader class no
jdbc interview questio
jsp:forward
Dynamic Instantiation
key send
Photoshop Abstracts An
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.