Friday, December 10, 2010

Accessing Services in Windows.


There are two ways to view Services on your computer. The first is to use the MS Configuration Utility by typing msconfig.exe in the Run box accessed via the Start Menu, followed by clicking the Services tab. If you want a quick visual of which items are running or stopped.

The preferred way to make changes to services is to launch services.msc from the Run option on the Start Menu. The Services window shown below will open. From here you can stop , start or restart a service. This can be useful if you are using a MySQL, Tomcat or other services which you may want to start or stop or restart. You can just create a shortcut to the Desktop which is a easy way to access services.

Tuesday, September 14, 2010

How to make a Build.xml in Eclipse ?

Making a Build.xml in eclipse is very easy and it can be done in just a few button clicks.

After you have made the project and kept all the source files in the src folder do the following steps to make a build.xml .

  • Right click on the Project folder and click on Export.
  • Click on General which has a option Ant Buildfiles.
  • Click next and select the project for which you have to make a Build.xml .
  • This will create the Build.xml.
Now if you want to clean or build the project do the following steps:
  • Right Click on the the Build.xml file and click on Run As.
  • Click the Ant Build.. option which will take you to Edit configuration and launch.
  • You can select target to execute.
Video Reference : https://eclipse-tutorial.dev.java.net/visual-tutorials/generatingantbuildfile.html

Thursday, September 2, 2010

Windows cannot find '-Dsun.io.useCanonCahes=false'

Windows cannot find '-Dsun.io.useCanonCahes=false'. Make sure you typed the name correctly, and then try again. To search for a file , click the Start button, and then click search.

If you have the following error while you are trying to start the Apache Tomcat server ( My case it was Apache-Tomcat-4.1.37 ). Then you don't have the JAVA_HOME correctly added to the environment variable.

  • Right click on My Computer and click on properties.
  • Go to the Advanced tab and click Environment Variables.
  • Add a new entry to the system variables if the JAVA_HOME does not exists.
  • Set the variable value pointing to the place where it is installed.




To compile any of the .java file you can open the command prompt and type

javac classname.java

This will create the classname.class file .

But if the path to the javac compiler is not set the nit will give the following error message although the JAVA_HOME is set:

"'javac' is not recognized as an internal or external command, operable program or batch file."

To rectify the problem add the path of the javac to the path in the Environment variables.

C:\j2sdk1.4.2_18\bin

The other work around to this problem is each time specify the path like:

C:\j2sdk1.4.2_01\bin\javac classname.java

But setting the environment variables is better option.

Tuesday, June 29, 2010

Creating dependencies between the Projects.

  • Right click on the project you are working on.
  • Go to Properties which will open a Properties window.
  • Go to the Java Build Path.
  • Do Add Folder to add new folders to which have dependiencies.
  • You can add the Libraries also.

Taking the Snapshot of the frontmost window in Windows

Pressing Alt-PrintScreen (Alt-PrtScrn) places an image of the frontmost window on the clipboard. Pressing PrintScreen by itself places an image of the entire desktop on the clipboard.

Friday, June 18, 2010

Unit Testing

Using JUnit tests in Eclipse...

A unit test is a piece of code written by a developer that tests a specific functionality in the code which is tested. Unit tests can ensure that functionality is working and can be used to validate that this functionality still works after code changes.

Installation of JUnit Test

To make JUnit available in your Java project you have to add the JUnit library file to your JavaClasspath.

To do that

  • right click on the Project folder and go to Properties.
  • Under Properties go to the Java Build Path tab under which go to Libraries.
  • Now Do Add Linrary and then select JUnit then Next.
  • Now add JUnit tests version 3 or 4 as you want.
Prepration:

Create a new project . We want to create the unit tests in a separate folder. Create therefore a new source folder "test" via right mouse click on your project, select properties and choose the "Java Build Path". Select the tab source code.

Saturday, May 22, 2010

A Quick Guide for installing Tomcat on Windows


  • After unzipping the file, navigate to the "bin" directory and start Tomcat by running the startup.bat file.

  • You must have the JDK installed before you can start Tomcat. The JDK contains the Java runtime engine.


  • Another point to consider is that JSP pages must be compiled the very first time someone accesses the JSP page. This compilation process converts the JSP page into a Servlet. This requires access to the Java compiler. Tomcat will not be able to call the Java compiler if the directory path to the Java compiler includes spaces. To avoid the problem, install the JDK in a directory with a name that contains no spaces, such as JDK1.3.

  • After starting Tomcat, open your browser and type the following URL: http://localhost:8080. Tomcat uses port 8080 by default, so make sure that port is not being used by another server, such as Internet Information Server (IIS). If there is a port conflict, you can change Tomcat's default port by modifying the file server.xml in the conf directory. Search for the number 8080 in the file and change it to an unused port number. When Tomcat starts successfully, you will see an introduction page for Apache Tomcat.
REFERENCES:

Setting the CLASSPATH of JAVA in Windows Vista

To setup the CLASSPATH of JAVA in Windows Vista
Right Click on My Computer > Properties >Advanced System setting > Environment Variables > System Variables

Add a new System Variable

Variable Name : JAVA_HOME
Variable value : C:\Program Files\Java\jdk1.6.0_16

The value will be wherever you have your JDK installation.

There is a simple test to see if the installation you have done is correct or not.
Go to the command line prompt and type
C:\> java -version
the output will be
java version"1.6.0_17"
Java SE Runtime Environment
Java HotSpot Client VM

The version will be which ever version you have installed. This simple test shows that you have installed the JDK or JRE correctly and have set the class path also correctly.

Java Command Line Arguments in Eclipse

To execute a class having the main method with arguments follow the steps below.

  1. Click from menu bar.
  2. “ Run ” - > “ Run ” and now select “ Arguments tab ”. Text area against “ Program Arguments ” is available to enter arguments. You can add any number of arguments but each parameter should be separated by a space. Space is the delimiter here.


Many people think that comma (,) or semi colon (;) is delimiter but it just a misconception. Delimiter is “ space ”.

Reference:

http://www.eclipse-blog.org/java-se/java-command-line-arguments-in-eclipse-ide.html

Javadoc Basic Tutorial

1. Use following comment style to generate a Javadoc.

/**  
 * Returns .............  
 * 
 * @param  url  an absolute URL   
 * @param  name the location of the  
 * @return      the image   
 * @see         Image  
 */
The first line contains the begin-comment delimiter (/**).
The last line contains the end-comment delimiter (*/) Note that unlike the begin-comment delimiter, the end-comment contains only a single asterisk.

Order of Tags
Include tags in the following order:

* @author      (classes and interfaces only, required) 
* @version     (classes and interfaces only, required. See footnote 1) 
* @param       (methods and constructors only) 
* @return      (methods only)
* @exception   (@throws is a synonym added in Javadoc 1.2) 
* @see          
* @since       
* @serial      (or @serialField or @serialData)
2.Click on projects link and choose ” Generate Javadoc ” option.

3.Now a window will be opened where you can select Java Projects or their underlying resources for which JavaDoc needs to be generated. Several other options are also there where user can select any of them as per the need.Here user can select whether to generate JavaDoc for public/private API’s etc.

To Generate the Javadoc you need to have JDK installed. The JRE won't work since it's a compact version so they do not provide the Javadoc functionality.
The Javadoc command will be the Javadoc.exe which is located in the bin folder of the JDK installation.

4.Now IDE asks for other features as well for the generation of Javadoc.

5.You can also save settings as ant script so that you can use the script to generate javadoc in future.

6.Click “Finish” Javadoc will be generated. If you select option of opening index file in browser then after generation of Javadoc you will find ” index.htm ” of Javadoc in your default Web Browser. On console you can see progress of JavaDoc Generation.

Wednesday, May 19, 2010

Changing the JRE being used in Eclipse

To change the JRE you are currently working on
  • Window > Preferences > Java >Installed JREs
  • Add the new installed JRE. Check the one you want to use.
  • Now go to Window > Preferences > Java > Compiler
  • change the "Compiler compliance level" to the one you are using
To fix the JRE not compatible with workspace .class file compatibility: 1.6 error
  • Window > Preferences > Java > Compiler and change the "Compiler compliance level" to 5.0

Adding External Library (.jar) in Eclipse

Adding external library (.jar) to the java classpath
  • From the menu select File -> Import -> File system. Select your jar and select the folder lib as target.
  • You can either create complete folder structure or selected folder structure only.Select the selected folder structure only option.
  • Select your project, right mouse click and select properties. Under libraries select "Add JARs".
  • If you find some errors in the import then find the jar in eclipse/plugin folder for the missing jar files.

Difference Between JRE and JDK

JRE and JDK
JRE
(Java Runtime environment)
JDK
(Java Development Toolkit)
It is an implementation of the Java Virtual Machine* which actually executes Java programs.It is a bundle of software that you can use to develop Java based applications.
Java Run Time Environment is a plug-in needed for running java programs.Java Development Kit is needed for developing java applications.
JRE is smaller than JDK so it needs less Disk space.JDK needs more Disk space as it contains JRE along with various development tools.
JRE can be downloaded/supported freely from
java.com
JDK can be downloaded/supported freely from
java.sun.com
It includes JVM , Core libraries and other additional components to run applications and applets written in Java.It includes JRE, set of API classes, Java compiler, Webstart and additional files needed to write Java applets and applications.
Reference :

Opening a Existing Project in Eclispe

Opening a Existing Project in Eclipse
  • New> Java Project
  • Project name should be the same as the folder name of the existing project
  • Content == Create project from the existing source
  • Projects located in the workspace folder must be direct sub folders of the workspace folder
  • Select the working set as the folder name as the name of the project folder.

Useful Shorts for Eclipse

Shortcuts for Eclipse
To comment Multiple lines :
  • Select all the lines to be commented
  • Press Ctrl + /
  • To uncomment do the same thing
To see the Declaration or corresponding code for a function :
  • Select the function you want to see the code for.
  • Press F3 or right click and do Open Deceleration
To Automatically indent the code use the following keys
  • Select the Code to be indented properly
  • Press Ctrl + i
To Search a function and declaration within a code
  • Press Ctrl + o


Tuesday, May 11, 2010

JUnit to test Java Programs

JUnit is a framework for developing unit tests for Java classes. JUnit provides a base class called TestCase that can be extended to create a series of tests for the class you are creating, an assertion library used for evaluating the results of individual tests, and several applications that run the tests you create.

You need to create a new separate class XText if our original programs class name is X.

There are three things you must do as you set up this class in order to run your tests:

  1. Import junit.framework.*.
  2. Extend TestCase.
  3. Provide a constructor with a single String parameter. This constructor should call the TestCase constructor with the parameter.

Here is a minimal class that demonstrates the structure of classes derived from TestCase:

import junit.framework.*;  
public class XTest extends TestCase {  
 public XTest(String name)  { 
    super(name); 
  }    
 public void Y()  {   .........  } 
} 

Monday, May 10, 2010

Eclipse Basic Help

To add a package to the project in eclipse

Create a new Java project
  • File>New>Java Project
After the Java project is created
  • Right click on the new created folder by the Java
  • New>Package
  • Now add the new Java Package name.
  • You can use dots (.) to specify multiple folders.
  • After the package is added you will see a Tree Hierarchy of the folders which you can see when you go to the folder or when you add the class file inside it.
To add the class file
  • Right click on the last folder and click NEW> Class
  • This will create the new class for the project.
Running you Java program outside Eclipse(create a jar File)
  • To run your Java program outside of Eclipse you need to export it as a jar file. Select your project, right click on it and select "Export".
  • Select JAR file, select next. Select your project and maintain the export destination and a name for the jar file. I named it "myprogram.jar".
Adding external library (.jar) to the java classpath
  • From the menu select File > Import > File system. Select your jar and select the folder lib as target.
  • Select your project, right mouse click and select properties. Under libraries select "Add JARs".
  • If you find some errors in the import then find the jar in eclipse/plugin folder for the missing jar files.
To change the JRE you are currently working on
  • Window > Preferences > Java >Installed JREs
  • Add the new installed JRE. Check the one you want to use.
  • Now go to
  • Window > Preferences > Java > Compiler
  • change the "Compiler compliance level" to the one you are using
To fix the JRE not compatible with workspace .class file compatibility: 1.6 error
  • Window > Preferences > Java > Compiler and change the "Compiler compliance level" to 5.0
REFERENCE:

Saturday, April 17, 2010

Difference Between New & malloc / Delete & free

One should be careful while combining the C and C++ code together. There are some mistakes that the developers do and it's really hard to find the point of mistake. One such mistake could be to use malloc and delete function in the C++ code. This a lot of difference in malloc and new as well as delete and free which is very important for a coder to know.

Some Difference:
1. Operator new automatically calculates the size of the object that it constructs. Conversely, with malloc(), the programmer has to specify explicitly the number of bytes that have to be allocated.

2. In addition, malloc() returns void *, which has to be explicitly cast to the desired type. This is both tedious and dangerous. Operator new returns a pointer to the desired type, so no explicit typecast is required.

3. When new has an object, space for the object is not only allocated but the object's constructor is called. And similarly when delete as an object, the object's destructor is called before the memory is released. If malloc and free are used, the destructor and constructor do not get called respectively and obviously, this simply won't do in C++ except in certain very rare situations where classes are present without any specific destructor/constructors.

new and delete automatically construct and destroy objects. malloc() and free(), on the other hand, merely allocate and deallocate raw memory from the heap.

delete can be overloaded, free cannot. delete invokes the destructor of the object to be deallocated, free does not do this.

The difference could be qouted as -

1. Operator new constructs an object (calls constructor of object), malloc does not.

2. Operator new is an operator, malloc is a function.

3. Operator new can be overloaded, malloc cannot be overloaded.

4. Operator new throws an exception if there is not enough memory, malloc returns a NULL.

5. Operator new[] requires to specify the number of objects to allocate, malloc requires to specify the total number of bytes to allocate.

6. malloc() returns void *, which has to be explicitly cast to the desired type but new returns the proper type.

7. Operator new/new[] must be matched with operator delete/delete[] to deallocate memory, malloc() must be matched with free() to deallocate memory.

8. The new/delete couple does not have a realloc alternative that is available when malloc/free pair is used. realloc is used to resize the length of an array or a memory block dynamically.


Reference:

Friday, April 16, 2010

XHTML

What is XHTML?

XHTML is a combination of HTML and XML (EXtensible Markup Language).

XHTML consists of all the elements in HTML 4.01, combined with the strict syntax of XML.

XML is designed to describe data, and HTML is designed to display data.

Difference between HTML & XHTML

The Most Important Differences:

  • XHTML elements must be properly nested
  • XHTML elements must always be closed
  • XHTML elements must be in lowercase
  • XHTML documents must have one root element

Wednesday, April 7, 2010

GDB Tutorial


How to run the gdb ?
> gdb executable_name
(then u will see (gdb) )

How to set break points ?
(gdb)b file_name: line_number
or
(gdb)break file_name:line_number
( You can either use break or b)

Executing next line in the program
(gdb)next
or
(gdb)n
How to run the executable?
(gdb)run

How to display value of particular variable?
(gdb) p variable_name
or
(gdb)print variable_name
or
(gdb)display variable_name
or
(gdb)d variable_name

How to Quit Gdb?
(gdb)quit
or
(gdb)q

Reference :