ITTreats.com
Enter your Search term and Hit "Enter"

Thu, 11 Mar 2010 9:38:14 AM +00:00

Latest 'ITTreats'


Populating Check All Checkboxes Functionality using Javascript & JQuery

Populating Check All Checkboxes  Functionality using Javascript & JQuery

At time are you stuck with doing Check All functionality for your Application?

Here is How you can do it in quick manner. This Tutorial will guide you How to Achieve Check All Checkboxes by checking a single Check box.

Here is an Example Instance. In the following Page I want to check All the Check Boxes Once If Check the Top most Checkbox at the Header section.

More . . .

Displaying Images saved in Database of blob datatype in JSP

Displaying Images saved in Database of blob datatype in JSP

Most of the times,  we need to display images  from Database,  This Article will guide you  to display  images  saved in  database

When we are saving  images to the database,  its a better  option  to save  the image type also,  it will be  helpful  when we are retreiving  image from database,  it is  fine when we are handling or saving  only one type of  image format  i.e either  jpg or GIF  but  what if  we  are allowing users to upload  both  jpg, gif  or any other  image format.  So,   Better to have a another field  to save  the image type also by which  we can  straight away throw  the  required headers  to the page .. i.e

response.setContentType(“image/jpeg”);
or

response.setContentType(“image/gif”);

More . . .

Using Bean in JSP page

Using Bean in JSP page

This Article illustrates a method of using a Bean in a JSP page. To use a bean in a JSP page, three attributes must be supplied – an id, which provides a local name for the bean, the bean’s class name, which is used to instantiate the bean if it does not exit, and a scope, which specifies the lifetime of the bean.

There are four scopes available – page, request, session, and application. A page-scoped bean is available only within the JSP page and is destroyed when the page has finished generating its output for the request. A request-scoped bean is destroyed when the response is sent. A session-scoped bean is destroyed when the session is destroyed. An application-scoped bean is destroyed when the web application is destroyed.

This example retrieves a session-scoped bean and makes it available using the id myBean. The bean is automatically created if it does not exist:

1
2
 
<jsp:useBean id=“myBean” class=“com.mycompany.MyBean” scope=“session” />

If it is necessary to initialize the bean after it is created, the initialization code can be placed in the body of the jsp:useBean action. The body will not be executed if the bean already exists. Here is an example:

1
2
3
4
5
6
<jsp:useBean id=“myBean2″ class=“com.mycompany.MyBean” scope=“session”>
<%this body is executed only if the bean is created –%>
 
<%– intialize bean properties –%>
<jsp:setProperty name=“myBean2″ property=“prop1″ value=123/>
</jsp:useBean>

The value of a bean property can be included in the generated output using the jsp:getProperty action:

1
2
<jsp:getProperty name=“myBean” property=“prop1″ />
<jsp:getProperty name=“myBean” property=“prop2″ />

The jsp:useBean action also declares a local Java variable to hold the bean object. The name of the local variable is exactly the value of the id attribute. Here is an example that accesses the bean within a scriptlet:

1
2
3
4
5
6
7
<%
if (myBean.getProp1() % 2 == 0) {
out.println(<font color=\”red\”>+myBean.getProp1()+</font>);
} else {
out.println(<font color=\”green\”>+myBean.getProp1()+</font>);
}
%>

Here is the bean used in the example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.mycompany;
 
public class MyBean {
// Initialize with random values
int prop1 = (int)(Integer.MAX_VALUE*Math.random());
String prop2 = “”+Math.random();
 
public int getProp1() {
return prop1;
}
public void setProp1(int prop1) {
this.prop1 = prop1;
}
 
public String getProp2() {
return prop2;
}
public void setProp2(String prop2) {
this.prop2 = prop2;
}
}

obtain middle date in java for given start date and end date

obtain middle date in java for given start date and end date

Inorder to get  exact middle date of  given  start date and end date,  normal  conditions includes  a bit  complex programming,

But  Here is  simple solution  to get middle date of  given start date and end date  in java.

by using the below  small function you will be  returned with the  middle date  between  given start date and end date in java .

Here is the function :

 public Date middle(Date d1, Date d2) {
        long t1 = d1.getTime();
        long t2 = d2.getTime();
        return new Date(t1 + (t2 - t1)/2);

    }

Hmm, simple isn’t it, use the above function in retrieving middle date between given start date and end date in java

coding standards in JAVA

coding standards in JAVA

Introduction

Having worked as a software developer and consultant for many years, I have seen a large amount of code in a variety of programming languages. It has run the gamut from elegant to ugly, and unfortunately much of it has been ugly. I hope to persuade you, and my fellow developers, that we should give as much attention to the style of our code as we give to the user interface and other visible parts of an application. In this the first part of a two part series, I explain why we should care about how our code looks and illustrate some general elements of good Java style. More . . .

SCJP Practice questions – 1

SCJP Practice questions  – 1

Questions
________________________________________
Question 1)
What will happen when you attempt to compile and run this code?
abstract class Base{
abstract public void myfunc();
public void another(){
System.out.println(“Another method”);
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println(“My func”);
}
public void amethod(){
myfunc();

}
}
1) The code will compile and run, printing out the words “My Func”
2) The compiler will complain that the Base class has non abstract methods
3) The code will compile but complain at run time that the Base class has non abstract methods
4) The compiler will complain that the method myfunc in the base class has no body, nobody at all to looove it

________________________________________

More . . .

Best practices for JAVA Programmers

Best practices for JAVA Programmers

There are many standards and best practices for Java Developers out there. This article outlines ten most basic rules that every developer must adhere to and the disastrous outcomes that can follow if these rules are not followed.

1. Add comments to your code. –Everybody knows this, but somehow forgets to follow it. How many times have you “forgotten” to add comments? It is true that the comments do not literally contribute to the functionality of a program. But time and time again you return to the code that you wrote two weeks ago and, for the life of you, you cannot remember what it does! You are lucky if this uncommented code is actually yours. In those cases something may spark your memory. Unfortunately most of the time it is somebody else’s, and many times the person is no longer with the company! There is a saying that goes “one hand washes the other.” So let’s be considerate to one another (and ourselves) and add comments to your code. More . . .

Pagination using JSP

Pagination using JSP

Pagination in JSP

Custom JSP taglib for paging. This taglib takes some data and dynamically splits up this information into several pieces (pages)
as well as generates automatically an index for available pages. You have seen some like this many times in any search engine for example: a list of data plus some index
with links to next pages.

So body tag paging is a common wrapper. Body tag item describes a repeatable element (piece of data). Body tag index is a
wrapper for the generated index. For example, suppose you have to split file search.jsp :

<%@ taglib uri=”taglib.tld” prefix=”pg” %>

<pg:paging>

<%

for (int i=1; i<=100; i++) {

%>

<pg:item>

your data …

</pg:item>

<%

}

%>

<pg:index>

<pg:page><%=thisPage%></pg:page>

</pg:index>

</pg:paging> More . . .

SCJP 1.5 syllabus

SCJP 1.5 syllabus

How is the SCJP 1.5 exam different from the SCJP 1.4?
· Exam objectives: Several important new language features have been added, including enums, generics, static imports, and autoboxing/unboxing. API features added to the exam include java.lang.StringBuilder, java.util.Locale, java.util.Formater, java.util.Scanner. java.util.regex.Pattern, and java.util.regex.Matcher. Java IO features have been added, including File, BufferedReader, BufferedWriter, FileReader, FileWriter and PrintWriter. Concepts such as loose coupling and high cohesion have been added, as well as greater emphasis on encapsulation as it relates to JavaBean conventions. Bit manipulation (e.g., shifting) has been dropped.
· Number of questions: 72 (increased from 61)
· Time: 175 minutes (increased from 120 minutes)
· Passing score: 59% (increased from 52%)
· Level of difficulty: The concensus is that it is more difficult.
· Format of questions: As before, you will always be told how many options to choose. No credit is given for partial answers. Drag-and-drop questions were also introduced for this version of the exam.

Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0 (CX-310-055)
Exam Objectives More . . .