Abhishek Gupta

The Sun won’t set at NIT Durgapur !

Posts Tagged ‘java’

Viewing your server(Remote Desktop) with browser using VNC Java Applet

Posted by abhiitechie on May 18, 2009

VNC consists of two components. A server, which runs on the computer you want to remotely access, and a viewer, which runs on the computer you are sitting in front of. There are two important features of VNC:

  • The server and the viewer may be on different machines and on types of computer. The protocol which connects the server and viewer is simple, open, and platform independent.
  • No state is stored at the viewer. Breaking the viewer’s connection to the server and then reconnecting will not result in any loss of data. Because the connection can be remade from somewhere else, you have easy mobility.

So to get started with VNC you need to run a server, and then connect to it with a viewer. First of all, you have to download and install the software on the platforms you want to use.

VNC software requires a TCP/IP connection between the server and the viewer. This is the standard networking protocol on LANs, WANs, broadband and dialup ISP. Each computer has a unique IP address and may also have a name in the DNS. You will need to know the IP address or name of the server when you connect a viewer to it.

The VNC servers also contain a small web server. If you connect to this with a web browser, you can download the Java version of the viewer, and use this to view the server. You can then see your desktop from any Java-capable browser, unless you are using a proxy to connect to the web. The server listens for HTTP connections on port 5800+display number. So to view display 2 on machine ‘snoopy’, you would point your web browser at:


The applet will prompt you for your password, and should then display the desktop.

Posted in java, Personal | Tagged: , , , , , , , , , , , | 3 Comments »

Regular Expressions in Javascript

Posted by abhiitechie on May 17, 2009

Here are some examples of using regular expressions for input validations in javascript.

var input = “hello222”;
var ok = false;

var dob_regex = /^([0-9]){2}(\/){1}([0-9]){2}(\/)([0-9]){4}$/;   // DD/MM/YYYY
var email_regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;  // email address
var username_regex = /^[\w.-]+$/;  // allowed characters: any word . -, ( \w ) represents any word character (letters, digits, and the underscore _ ), equivalent to [a-zA-Z0-9_]
var num_regex = /^\d+$/; // numeric digits only
var search_regex = “/hello/”;
var password_regex = /^[A-Za-z\d]{6,8}$/;  // any upper/lowercase characters and digits, between 6 to 8 characters in total
var phone_regex = /^\(\d{3]\) \d{3}-\d{4}$/;  // (xxx) xxx-xxxx
var question_regex = /\?$/; // ends with a question mark

1. Check that there are at least 3 numeric characters in input
if ( input.match(/d/g) == null ) {
ok = false;
} else if ( input.match(/d/g).length < 3 )  {
ok = false;
} else {
ok = true;
2. Check that the input has a minimum of 8 characters
if ( input.length >= 8 ) {
ok = true;
3. Check that the input is in a correct date format (DD/MM/YYYY)
if ( dob_regex.test(input) ) {
ok = true;
4. Check that the input is in a correct email format (username@example.com)
if ( email_regex.test(input) ) {
ok = true;
5. Check that the input matches the specified username format
if ( username_regex.test(input) ) {
ok = true;
6. Check that the input contains only numeric characters
if ( input.match(num_regex) ) {
ok = true;
7. Search for a specific word in the input
if ( input.search(search_regex) != -1 ) {
ok = true;
8. Check that the input matches the specified password format
if ( input.match(password_regex) ) {
ok = true;
9. Check that the input matches the specified phone number format
if ( input.match(phone_regex) ) {
ok = true;
10. Check that the input is a question (ends with a question mark)
if ( question_regex.test(input) ) {
ok = true;

Posted in Personal, web | Tagged: , , , , | 6 Comments »

Programming Forums that will always help

Posted by abhiitechie on May 17, 2009

Java  Forums


imageSun forums Sun’s official Java forums

imageDZone Forums 

PHP Forums


image  PHP freaks 

image PHP Builder forums

image  Devshed php development forums

image Weber forums

MySQL Forum


RoR  Forums

image Rails forum

 image  Ruby forum

For all kind of programming Q and A.




Posted in java, mysql, Personal | Tagged: , , , , , , , , , , , | Leave a Comment »

Developing iphone apps using Java

Posted by abhiitechie on May 17, 2009

It’s a channel on google about Education and Tech talks and in this tech talks will be talked about object c, java, apps and cross compiling. You can see the Google tech talk here

Posted in Uncategorized | Tagged: , , , , , , , , | 4 Comments »

How to open a .war (web archive) or .jar (java archive) files

Posted by abhiitechie on April 27, 2009

With Java we generate .JAR files to bundle a set of resources. For J2EE web applications, we generate .WAR (Web Archive) files for deployments. Both of these are ways of archiving a set of files.

Both these .jar or .war archives are in zip format. So there are plenty of ways to open those files to read the content. One way would be to use any tool that you use to open/extract a .zip file. Next will be to use the Jar command itself.

JAR Command

JAR (command) utility in Java can be used to open/extract these files as follows. Run following command from the folder where you need the content to be extracted by providing the path to the archive.

jar xf


x – extract the files
f – file to extract

jar xf myWebApp.war
jar xf myProject.jar

Posted in Uncategorized | Tagged: , , , , , , , , , | 1 Comment »

Database connections using JDBC – MySQL and Netbeans

Posted by abhiitechie on April 27, 2009

I am fed up of people asking me how to make Database connections in Java . No one wants to go through the painfull part of studying themselves . All they want is the short-cut . So let me dedicate this particular posts to the topic of database connections in Java .

I have MySQL 5.0 installed on my Windows. In order to make a JDBC connection to MySQL database one needs to downlad the MySQL/J connector driver from here . I will also expect that you have Netbeans 6+ installed on your machine.

Extract the zip file to a folder, you’ll see file ‘mysql-connector-java-5.0.6-bin.jar’ which is the library file that we want. Just copy the file to the library folder, for example to “C:\Program Files\Java\jdk1.6.0_02\lib” also to the “C:\Program Files\Java\jdk1.6.0_02\jre\lib directory.

Next, create a new Java project on NetBeans named ‘TestMySQL’.

Now I’m going to write some code to connect to MySQL database. I have configured MySQL service on localhost.
I’m going to use Connection and DriverMapper Classes so I need to import libraries.
import java.sql.*;

Inorder to test my connections I build my project.

So everything seems to be fine till now.

To get some data, I need to execute query on the SQL Server and get the result back to me. First, I create stmt (Statement object) and execute query in SQL language. Then I store the result on ResultSet object and iterative show the result on the output window.

Insert some data to the created table using the code

Statement stmt = null;

stmt = con.createStatement();

String SQL = “INSERT INTO ZanduBaam (Name,Roll) VALUES (‘Abhishek’,40)”;

int rowsEffected = stmt.executeUpdate(SQL);

System.out.println(rowsEffected + ” rows effected”);

Inorder to retrieve data from database , I need to execute query on the SQL Server and get the result back to me. First, I created stmt (Statement object) and execute query in SQL language. Then I store the result on ResultSet object and iterative show the result on the output window.

ResultSet rs = null; // SQL query command String SQL = “SELECT * FROM ZanduBaam”; stmt = con.createStatement(); rs = stmt.executeQuery(SQL); while (rs.next()) {
System.out.println(rs.getString(“Name”) + ” : ” + rs.getString(“Roll”));

Similarly you can do the required for updation and deletion .

Lots of time and sweat devoted to this post considering the fact that I have a test on Monday I should stop here.

Posted in Uncategorized | Tagged: , , , , , , , , , , , , , , , , , , , , , | 3 Comments »

The Sun won’t set at NIT Durgapur … I promise !

Posted by abhiitechie on April 25, 2009

As we all might have heard, Oracle has entered into an agreement to acquire Sun. While it is natural to have questions following an announcement of this magnitude, its also important to acknowledge that this is an
industry transforming event. The following excerpt from the Oracle Press Release helps to highlight this point.

“This is a fantastic day for Sun’s customers, developers, partners and employees across the globe, joining forces with the global leader in enterprise software to drive innovation and value across every aspect of
the technology marketplace,” said Jonathan Schwartz, Sun’s CEO, “From the Java platform touching nearly every business system on earth, powering billions of consumers on mobile handsets and consumer electronics, to the convergence of storage, networking and computing driven by the Solaris operating system and Sun’s SPARC and x64 systems.”

Coming back to the question of what will be the future of MySQL under Oracle. I think that as long as there is a demand for a product and such a vibrant community of users and developers behind it the product will never die.

Since it is all business as usual, we should not create a huge fuss about Oracle acquiring Sun and the future of Sun Campus Ambassadorship and the Sun Academic Initiative (SAI). I think we all should focus on our respective efforts to evangelize Free Softwares and continue conducting Talks , Workshops and related Technical sessions and continue building the Talk culture in our college which has just started some times back. We should try building the best open source community in NIT Durgapur with our Sun Club and the GNU/Linux Users’ Group.

Posted in Uncategorized | Tagged: , , , , , , , , , , , , , , , , , | 6 Comments »

My First Session On Netbeans IDE and J2SE

Posted by abhiitechie on April 25, 2009

This was the debut session conducted by me as a CA . In the first part of my Demo I covered many topics related to Netbeans Intelligent Text Editor and showed them techniques like Code-Insertion , Code-Refactoring ,Using Javadoc , Live Code Parser and error checker , Local History , Code completion , Instant renaming , Compile on Save,and lots of other cool stuffs. I explained them how to use the Profiler and the Debugger. I explained them the use of Version Control and automated testing (Unit Testing) .

This was followed by a basic demonstration on the Swing Gui Builder and with functionalities like Automatic feedback , Quick Component Insertion , Anchoring , Alignment . After this I expained the basic features of event handling and demonstrated it with a small application built using the Swing Builder .

As people asked for more meat so I continued out of my plan to demonstrate them easy Data Binding using MySQL database , JTable and Java Persistence API showing them how to createa CRUD application in 5 mins! On audience demand I also showed them how to import an existing PHP-MySQL project in Netbeans and showed them advantage of using WEB 2.0 frameworks like JMaki and Dojo directly into the existing PHP project. I gave them an introduction to Visual Web Java Server Faces by demonstrating them how to populated a Woodstock Table from a MYSQL database using simple drag-drop.

Many obvious questions like why Netbeans over Eclipse which I think I answered satisfactorily. Many people came to me afterwards asking more details about multibooting Solaris and more about Web 2.0 and AJAX. I was on the top of the world when people actually clapped at the end of the talk. All in all a nice experience.

Here are some of the pictures from the Session






Posted in sun | Tagged: , , , , , , , , , , , , , , , , , , , , , | Leave a Comment »