Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Get Length of Array 
 

In this Tutorial we make a simple example to understand Get Length of Array in Java Script.

 

Get Length of Array

                         

In this Tutorial we make a simple example to understand Get Length of Array in Java Script. In this code we import a  package java.util and java. text.

Packages used in code  - 

1)Java.util.  -  This includes  the collections framework, legacy collection classes, event model, date and time facilities and internationalization..

2)Java.text  -  This includes  the classes and interfaces used  for handling text, dates, numbers, and messages.

Methods used in code  -

1)Format formatter  = new SimpleDateFormat("MMMM")  - This method return you a SimpleDateFormat, this allows for formatting (i.e., date -> text), parsing (text -> date), and normalization. The date is represented as a Date object or the milliseconds since January 1, 1970, 00:00:00 GMT.

2)Calendar.get Instance( ) - This method return you the default time zone and current locale.

We declare a variable string array name month, that is used to instantiate an string object with initial size to hold 12 element. The for loop execute and run the script till the length i is less than length of string element.

3)Calendar.set(calendar.Month,i) - This method set you the calendar month.

4)calendar.gettime( )  -This method get you the calendar current time.

5)monthname.length ( )-This method return you the length of the month.

The var  month instantiate an array object that hold the size of month. The for loop run and execute the script till the length of i is less than  month. The document. write print the list of month in a year.

 

Array Elements.jsp

<html>
    <head>
        <title>Array Elements</title>
        
        <%page import="java.util.*" %>
        <%page import="java.text.*" %>
        <%
            Format formatter = new SimpleDateFormat("MMMM");
            Calendar calendar = Calendar.getInstance();
            String[] monthName = new String[12];

            for (int i = 0; i < 12; i++) {
                calendar.set(Calendar.MONTH, i);
                monthName[i= formatter.format(calendar.getTime());
            }

            int month = monthName.length;
        %>
    </head>
    
    <body>
        <script>  
            var month = new Array(<%=month%>);

            <%for (int i = 0; i < month; i++) {%>
                month[<%=i%>"<%=monthName[i]%>";

            <%}%>
                    document.write("<h2>Elements of the array</h2>");
                    fori = 0; i < month.length; i++){
                        document.write("<b>"+month[i]+"</b><br>");
                    }
        </script> 
    </body>
</html>

Output

Download code

                         

» View all related tutorials
Related Tags: java javascript c array ant script io display ip value number name ole instance this nsis element create elements if

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 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

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 | Flex 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.