Tuesday, November 20, 2012

JAVA SCRIPT TO VALIDATE TIME IN "dd-mm-yyyy hh:mm:ss" FORMAT


function validateStartTime() {
//This function will validte the datetimes of this format : dd-mm-yyyy hh:mm:ss
var date = document.getElementById("startTime").value.trim();
    var valid = true;
    var spaceIndex = date.indexOf(" ");
    var onlyDate = date.substring(0,spaceIndex);
    var dateData = onlyDate.split("-");
    var onlyTime = date.substring(spaceIndex);
    var timeData = onlyTime.split(":");
    var day = (dateData[0]);    
    var month = (dateData[1]);   
    var year   = (dateData[2]);   
    var hour   = (timeData[0]);   
    var min = (timeData[1]);   
    var sec = (timeData[2]);     
    var regForDate = new RegExp("\\d{1,2}-\\d{1,2}-\\d{4}$");
    var regForTime = new RegExp("\\d{1,2}:\\d{1,2}:\\d{1,2}$");
 
    if(!regForDate.test(onlyDate)) valid =false;
    else if(!regForTime.test(onlyTime)) valid =false;
    else if((month < 1) || (month > 12)) valid = false;
    else if((day < 1) || (day > 31)) valid = false;
    else if(((month == 4) || (month == 6) || (month == 9) || (month == 11)) && (day > 30)) valid = false;
    else if((month == 2) && (((year % 400) == 0) || ((year % 4) == 0)) && ((year % 100) != 0) && (day > 29)) valid = false;
    else if((month == 2) && ((year % 100) == 0) && (day > 29)) valid = false;
    else if((hour < 0) || (hour > 24)) valid = false;
    else if((min < 0) || (min > 59)) valid = false;
    else if((sec < 0) || (sec > 59)) valid = false;      

return valid;
}

Servlet’s class files are not getting generated by ECLIPSE


Go to project properties > Java Compiler 

Then change the “compiler compliance level” of JDK to the one which is not installed in your PC

Uncheck the “Use Default Compliance settings” 

Set the “Generated .class files compatibility” same as “compiler compliance level” 

 Set the “Source Compatibility” same as “compiler compliance level” 

 Then click on “Apply” button and click on “Ok” button 

 Then build your project even if you are getting error. 

 Now again follow the same steps with the “compiler compliance level” of JDK which is installed in your PC  

 Now build your project It will generate the class files now. 

Monday, August 13, 2012

JOptionPane - showInputDialog


import javax.swing.*;


class AdditionDemo{
public static void main(String rk[]){


try{
String num1 = JOptionPane.showInputDialog("Input fist Value") ;
String num2 = JOptionPane.showInputDialog("Input second Value") ;

int a = Integer.parseInt(num1);
int b = Integer.parseInt(num2);
int c = a+b;
JOptionPane.showMessageDialog(null," Total is : "+c);

}catch(Exception e ){
JOptionPane.showMessageDialog(null,"Oop !! Buddy, you gave wrong input. :-( ");
}
}
}

REGEX for number greater than zero

var nre= /^[1-9]+[0-9]*$/;
var regexp = new RegExp(nre);

if(regexp.test(val)){
alert(“Number is greater than zero.”)
}

STRUTS : logic:notEmpty

"<"logic:notEmpty name=”beanName” property=”beanPropertyName”">"

"<"bean:write name=”beanName” property=”beanPropertyName”/">"

"<"/logic:notEmpty">"



Note : if you have DataBean.java class with userName as its one property variable, and if you gave one object of DataBean class i.e “dataBean” in request scope , then you could use that object as given below into the destination .jsp page.



"<"logic:notEmpty name=”dataBean” property=”userName”">"

"<"bean:write name=”dataBean” property=”userName”/">"

"<"/logic:notEmpty">"

STRUTS – ITERATE MAP – logic:iterate

"<"logic:iterate id=”keyValuePair” name=”mapName”">"

"<"bean:write name=”keyValuePair” property=”key”/">"
"<"bean:write name=”keyValuePair” property=”value”/">"

"<"/logic:iterate">"

STRUTS- ITERATE LIST : logic:iterate

"<"logic:iterate id=”userName” name=”userNameList”">"

"<"bean:write name=”userName”/">"

"<"/logic:iterate">"

STRUTS- ITERATE LIST TO GET OBJECT : logic:iterate

"<"logic:iterate id=”studDataObj” name=”dataList” type=”com.student.Data” ">"

"<"bean:write name=”studDataObj” property=”rollNumber”/">"
"<"bean:write name=”studDataObj” property=”name”/">"

"<"/logic:iterate">"



Note : Here com.student.Data is the package name with actualy “Data.java” class

class Data {

String name;

int rollNumber;

/*

……………

setter getter method

…………….

*/

}

STRUTS : logic:equal , logic:notEqual

logic:equal

"<"logic:equal name=”studentDataObject” property=”rollNumber” value=”11″">"
"<"bean:write name=”studentDataObject” property=”rollNumber”/">"
"<"/logic:equal">"

——————————————————————————————————-

logic:notEqual

"<"logic:notEqual name=”studentDataObject” property=”rollNumber” value=”3″">"

"<"bean:write name=”studentDataObject” property=”rollNumber”/">"

"<"/logic:notEqual">"

JQUERY : GET SELECT-OPTION VALUE

$(document).ready(function() {   

    $('#selectElementId').change(function(){

                var value=$('#selectElementId').val();
                alert(value)

    });

});

Friday, December 23, 2011

VARIOUS WAYS TO ITERATE MAP OR HASHMAP IN JAVA

How to Iterate MAP or HASHMAP in JAVA

Map<Integer, Integer> map = new HashMap<Integer, Integer>();

for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}


Map<Integer, Integer> map = new HashMap<Integer, Integer>();

//iterating over keys only
for (Integer key : map.keySet()) {
    System.out.println("Key = " + key);
}
//iterating over values only
for (Integer value : map.values()) {
    System.out.println("Value = " + value);
}Map<Integer, Integer> map = new HashMap<Integer, Integer>();

Iterator<Map.Entry<Integer, Integer>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
    Map.Entry<Integer, Integer> entry = entries.next();
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}


Map map = new HashMap();

Iterator entries = map.entrySet().iterator();

while (entries.hasNext()) {
    Map.Entry entry = (Map.Entry) entries.next();
    Integer key = (Integer)entry.getKey();
    Integer value = (Integer)entry.getValue();
    System.out.println("Key = " + key + ", Value = " + value);
}


Map<Integer, Integer> map = new HashMap<Integer, Integer>();

for (Integer key : map.keySet()) {
    Integer value = map.get(key);
    System.out.println("Key = " + key + ", Value = " + value);
}

Monday, December 19, 2011

(AVD) Android Emulator not loading on netbeans







































Step 1 ) Open your AVD manager


Step 2 ) Click on new button on the right hand side top corner


Step 3 ) Now follow the Images given here





Step 4) Now restart yous Netbeans and Run your android application.


Step 5 ) Thank You.











Wednesday, December 7, 2011

HOW TO DEBUG JAVA CODE IN ECLIPSE

 1. Introduction
Debugging allows you to run the program interactively and to watch the source code and the variables during this execution.
A Java program can be started in "Debug mode". You can set breakpoints in your Java code in which the execution of the Java code will stop if the Java program is executed in "Debug mode".

2 .Set Breakpoints

To set breakpoints right click in the small left column in your source code editor and select "Toggle Breakpoint". Or you can double click on this position.


































3. Star Debugger

You can debug your application, select a Java file which contains a main method, right click it and select Run →Debug.















If you have not defined any breakpoints, this will run your program as normal. To debug the program you need to define breakpoints.
If you start the debugger the first time, Eclipse ask you if you want to switch to the debug perspective. Answer "yes". You should then see a perspective similar to the following.
















You can use F5 / F6, F7 and F8 to step through your coding. The meaning of these keys are explained in the following table.

CommandDescription
F5Goes to the next step in your program. If the next step is a method / function this command will jump into the associated code.
F6F6 will step over the call, e.g. it will call a method / function without entering the associated code.
F7F7 will go to the caller of the method/ function. So this will leave the current code and go to the calling code.
F8Use F8 to go to the next breakpoint. If no further breakpoint is encountered then the program will normally run.

















Thank You.


Tuesday, November 29, 2011

NETBEANS SHORTCUTS (Debugging)


Debugging
Ctrl-F5                        Start debugging main project

Ctrl-Shift-F5              Start debugging current file

Ctrl-Shift-F6              Start debugging test for file
(JUnit)
Shift-F5/F5                Stop/Continue debugging session

F4                               Run to cursor location in file

F7/F8                          Step into/over

Ctrl-F7                        Step out

Ctrl-Alt-Up                 Go to called method

Ctrl-Alt-Down            Go to calling method

Ctrl-F9                        Evaluate expression

Ctrl-F8                        Toggle breakpoint

Ctrl-Shift-F8              New breakpoint

Ctrl-Shift-F7              New watch

Enhanced by Zemanta

NETBEANS SHORTCUTS (JSP Editor Code Templates)


JSP Editor Code Templates
ag                    application.getAttribute("|")

ap                    application.putAttribute("|",)

ar                     application.removeAttribute("|")

cfgi                  config.getInitParameter("|")

jspf                 

jspg                 

jspi                  

jspp                 

jsps                 

jspu                 

oup                  out.print("|")

oupl                 out.println("|")


pcg                  pageContext.getAttribute("|")

pcgn                pageContext.getAttributeNamesInScope("|")

pcgs                pageContext.getAttributesScope("|")

pcr                   pageContext.removeAttribute("|")

pcs                  pageContext.setAttribute("|",)

pg                    <%@page |%>

pga                  <%@page autoFlush="false"%>

pgb                  <%@page buffer="|kb"%>

pgc                  <%@page contentType="|"%>

pgerr                <%@page errorPage="|"%>

pgex                <%@page extends="|"%>

pgie                 <%@page isErrorPage="true"%>

pgim                <%@page import="|"%>

pgin                 <%@page info="|"%>

pgit                  <%@page isThreadSafe="false"%>

pgl                   <%@page language="java"%>

pgs                  <%@page session="false"%>

rg                     request.getParameter("|")

sg                    session.getAttribute("|")

sp                    session.setAttribute("|", )

sr                     session.removeAttribute("|")

tglb                  <%@taglib uri="|"%>

Enhanced by Zemanta

NETBEANS SHORTCUTS (Coding in Java)


Coding in Java

Alt-Insert                    Generate code

Ctrl-Shift-I                  Fix all class imports

Alt-Shift-I                   Fix selected class's import

Alt-Shift-F                  Format selection

Alt-Shift Left/             Shift lines left/right/up/down
Right/Up/Down

Ctrl-Shift-Up/D          Copy lines up/down

Ctrl/Alt-F12                Inspect members/hierarchy

Ctrl-/                            Add/remove comment lines

Ctrl-E                          Delete current line


Ctrl-K/Ctrl-Shift K     Next/previous word match

Alt-Left/Alt-                Go backward/forward/to last

Right/Ctrl-Q               edit

Alt Up/Down              Next/previous marked occurrence

NETBEANS SHORTCUTS (Navigating through Source Code)


Navigating through Source Code

Ctrl-O/Alt-Shift-O       Go to type/file

Ctrl-Shift-T                  Go to JUnit test

Alt-O                           Go to source

Ctrl-B                          Go to declaration

Ctrl-G                          Go to line

Ctrl-Shift-M                 Toggle add/remove bookmark

Ctrl-Shift-Period/Comma    Next/previous bookmark

Ctrl-Period/Comma    Next/previous usage/compileerror

Ctrl-Shift-1/2/3           Select in Projects/Files/Favorites

Ctrl-[                          Move caret to matching bracket

Ctrl-K/Ctrl-Shift K     Next/previous word match

Alt-Left/Alt-                Go backward/forward/to last

Right/Ctrl-Q               edit

Alt Up/Down             Next/previous marked occurrence

NETBEANS SHORTCUTS (Finding, Searching, and Replacing)



Finding, Searching, and Replacing

Ctrl-F3                      Search word at insert point

F3/Shift-F3                Find next/previous in file

Ctrl-F/H                    Find/Replace in file

Alt-F7                       Find usages

Ctrl-Shift-F/H            Find/replace in projects

Alt-Shift-U                 Find usages results

Alt-Shift-H                 Turn off search result highlights

Ctrl-R                        Rename

Ctrl-U,                       then U Convert selection to uppercase

Ctrl-U,                       then L Convert selection to lowercase

Ctrl-U,                      then S Toggle case of selection

Ctrl-Shift-V               Paste formatted

Ctrl-I J                       ump to quick search field


Wednesday, November 16, 2011

WHAT IS UTF-8 ?



UTF-8 :   UCS Transformation Format — 8-bit
Unicode is a character set supported across many commonly used software applications and operating systems.
Operating systems that support Unicode include Solaris Operating Environment, Linux, Microsoft Windows 2000, and Apple’s Mac OS X.
Applications that support Unicode are often capable of displaying multiple languages and scripts within the same document.
In a multilingual office or business setting, Unicode’s importance as a universal character set cannot be overlooked.
Unicode is the only practical character set option for applications that support multilingual documents.
An encoding is the mapping of Unicode code points to a stream of storable code units or octets.

Enhanced by Zemanta

JAVA CODE FOR VARIOUS DIALOG BOXES



import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

public class TestDialogue extends JFrame implements ActionListener {
    JButton button1 =null;
    JButton button2 =null;
    JButton button3 =null;

  public TestDialogue() throws HeadlessException {
    setSize(200, 200);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    button1 = new JButton("Simple Message dialog");
    button2 = new JButton("Dialog with InputBox");
    button3 = new JButton("Yes/No dialog");

    setLayout(new FlowLayout(FlowLayout.CENTER));
    getContentPane().add(button1);
    getContentPane().add(button2);
    getContentPane().add(button3);

    button1.addActionListener(this);
    button2.addActionListener(this);
    button3.addActionListener(this);
  }

  public static void main(String[] rk) {
        try
 {
  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
 }catch(Exception e)
        {}
        new TestDialogue().setVisible(true);
  }

    @Override
    public void actionPerformed(ActionEvent e) {
    String Action;
    Action = e.getActionCommand ();

        if(Action.equals("Simple Message dialog")){
            JOptionPane.showMessageDialog((Component) e.getSource(), "Hello ! Thank you!");

        }else if(Action.equals("Dialog with InputBox")){
            String name = JOptionPane.showInputDialog((Component) e.getSource(), "Hello, please Input your name.");
            if (name != null && !name.equals("")) {
                JOptionPane.showMessageDialog((Component) e.getSource(), "Hi, " + name);
            }

        }else if(Action.equals("Yes/No dialog")){

            int result = JOptionPane.showConfirmDialog((Component) e.getSource(), "Close this application?");
            if (result == JOptionPane.YES_OPTION) {
            System.exit(0);
            } else if (result == JOptionPane.NO_OPTION) {
            System.out.println("No Action performed.");

        }
       }

    }
}

Enhanced by Zemanta