Wednesday, June 10, 2009

Batch File To Create Restore Point








runas /user:local\administrator
@
echo off
title Test Utility
:prompt
color 4f
cls
echo Pick a Category
echo.
echo Type 1 to System Utilities
echo Type 2 to ""
echo Type 3 to ""

set /p answer=
if ‘%answer%’ == ‘1’ system

:system
cls
Echo Type 1 to System Restore
Echo Type 2 to ""
Echo Type 15 to Main Menu

set /p answer=
if '%answer%' == '1' goto system restore

:system restore
cls
IF EXIST %systemroot%\system32\restore\rstrui.exe= %systemroot%\system32\restore\rstrui.exe else
IF EXIST C:\Windows\System32\rstrui.exe = C:\Windows\System32\rstrui.exe
echo.
echo Pres Any Key to goto Menu
pause >nul
goto prompt

Create .VBS file To Create Restore Point

Step-1 Open Notepad
Step-2 Copy below code to Noteoad

set SRP = getobject("winmgmts:\\.\root\default:Systemrestore")
CSRP = SRP.createrestorepoint ("Restore Point Created By-Chintan Patel", 0, 100)

Step3 Save as RestorePoint.vbs
Step-4 Double click on RestorePoint.vbs to Take Restore Point


Note:
If you want to Take Restore Point when system start,
then drag that file in to STARTUP

How to Start the System Restore Tool from a Command Prompt



To start the System Restore tool when you cannot start your Windows Me-based computer normally or in Safe mode, you can temporarily change the Windows shell from Explorer.exe to Progman.exe:
  1. Start your computer by using the Windows Me Startup disk.
  2. At the Startup menu, choose Minimum Boot.
  3. At the command prompt, type edit c:\windows\system.ini, and then press ENTER.
  4. Edit the shell= line so that it looks like this:
    shell=progman.exe
  5. Press ALT+F, and then press S to save the changes to the System.ini file.
  6. Press ALT+F, and then press X.
  7. Remove your Windows Me Startup disk, and then restart your computer. When your computer restarts, Program Manager should start. If Program Manager does not start, repeat steps 1 through 7, being careful to follow these steps exactly, and then continue to the next step.
  8. On the File menu, click Run, type msconfig in the Command Line box, and then press ENTER.
  9. Click Launch System Restore to begin restoring your computer to a previous, functional state.


Notes

  • After you configure your computer to start Program Manager (Progman.exe), you can also start the System Restore tool by typing c:\windows\system\restore\rstrui.exe at a command prompt, and then pressing ENTER.
  • If you still cannot use System Restore, repeat steps 1 through 6. In step 4, change the shell= line so that it reads:
    shell=explorer.exe
    This sets the Windows shell back to Explorer.exe so that you can continue troubleshooting.

Tuesday, June 9, 2009

Have You Visit eHow ?

Have You Visit eHow ?


Print (Silent Print) From Java Applet

import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.net.*;

import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.swing.*;

public class CopyOfPrinterApplet extends JApplet {

private PrintRequestAttributeSet aset;
DocFlavor DocFlavor;
public Doc doc;
DocPrintJob printerJob;
JTextPane pane;


/**
* DOCUMENT ME!
*/
public void init() {
getContentPane().setLayout(new BorderLayout());

pane = new JTextPane();
pane.setSize(150, 100);
pane.setContentType("text/html");
pane.setText(

"<center><b><big>Applet Test</big></b>

"

+ "</center>");

getContentPane().add(pane, "Center");

JPanel buttons = new JPanel();
buttons.setBackground(Color.white);

JButton print = new JButton("Print");

buttons.add(print);

getContentPane().add(buttons, "South");

print.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
print();
}
});
}

/**
* DOCUMENT ME!
*/
void prep() {

URL url = null;
aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.ISO_A4);
aset.add(new Copies(1));

try {
url =
new URL("http://www.emanuelblagonic.com/wp-content/uploads/2007/06/google-homepage.jpg");
} catch (MalformedURLException e) {
e.printStackTrace();
}
PrintService pservices =
PrintServiceLookup.lookupDefaultPrintService();
System.out.println(pservices.getName());

DocFlavor flavor = javax.print.DocFlavor.INPUT_STREAM.JPEG;
PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet();
attr_set.add(new Copies(1));
PrintService[] service = PrintServiceLookup.lookupPrintServices(flavor, attr_set);

doc = new SimpleDoc(url, javax.print.DocFlavor.URL.PDF, null);

try {
System.out.println("DOC : \n " + doc.getPrintData());
} catch (IOException e) {
e.printStackTrace();
}
/* Create a Print Job */
printerJob = pservices.createPrintJob();
}

/**
* DOCUMENT ME!
*/
void print() {
prep();
System.out.println("Printer Name : " +
printerJob.getPrintService());
try {
printerJob.print(doc, aset);

} catch (PrintException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Done Printing.");
}

}

Wednesday, May 27, 2009

What does rt.jar stand for in Java/JDK/JRE?

The most likely answer is, rt stands for RunTime. Some tend to think it stands for RooT, since this jar contains all java build-in classes. But I have yet to find any official Sun documents regarding this acronym.
Whether it stands for RunTime, RooT, or anything else is not important. The question I have is, why would the java creator chose to use such a undescriptive name. Maybe it can make your classpath shorter? But we rarely put rt.jar in system classpath.
Here are 2 reasons I don't like the name rt.jar:
* While experienced developers take it for granted, java beginners don't know what it is other than it's a jar. So it's one more questions in beginners' mind.
* The shorter the name, the easier it is to cause naming conflicts, at least visually. While rt.jar will always reside under $JAVA_HOME/jre/lib, it is possible your applications may have another jar also named rt.jar.
I know rt.jar will be with us as long as java is, but just for the sake of discussion, how would you name it differently? Maybe java.jar, or java-core.jar?
PS: What does jar stand for? Jar stands for Java Archive. A jar file usually has file name extension .jar. It contains mainly java class files but any types of files can be included, e.g., XML files, HTML files, properties files, gif/jpg image files, text files, PDF files, and binary files, and so on.
PS: What is the difference between a jar file and a zip file? Basically, a jar file is the same as a zip file, except that the jar file contains a META-INF directory to store metadata or attributes. The most well-known file is META-INF/MANIFEST.MF. You can customize the content of a MANIFEST.MF when creating a jar file, and if you don't, a default one is generated and included. For example:
Manifest-Version: 1.0
Created-By: 1.5.0_06 (Sun Microsystems Inc.)
It's perfectly fine to have other configuration files and directories under META-INF.

Java Jar File Naming Conventions and Examples.

util.jar is the worst jar file name I can think of. All I know is it contains some utility/helper classes. But it is unclear if they belong to an application server, or a framework, or any application sub-systems. You will need to ask someone or some docs to know what it is. It's part of the DataDirect JDBC Driver distribution.
On the other hand, good jar file names are always self-explanatory, for example: struts.jar, jboss-system.jar, commons-pool-1.1.jar
Some thoughts on jar file naming conventions:
1. Always use extension ".jar", not ".zip"
Theoretically, jar files can have any extension or no extension at all. If you specify it in the system classpath, it should be loadable. The problem is with automatic library detection and loading by containers and frameworks. It's expensive to scan all files so some sort of extension restriction is needed. For this reason, J2EE/JavaEE platform spec requires all library jar files use ".jar" extension, such as WEB-INF/lib/mybeans.jar.
2. Use hyphen (-) instead of underscore (_) as word separator
First, it's easier to type - than _; secondly, when the file name is underlined (e.g., in a hyperlink), the _ is invisible. Hyphen has been shunned in file names partly because it is an illegal character in java identifier. But this concern is unwarranted.
3. Append version number if distributed standalone
because they can be dropped into any applications, which may need specific versions. We don't want users to have to compare file size or extract some META-INF files to know its version. Some examples: hibernate3.jar, commons-logging-1.0.3.jar, and
log4j-1.2.8.jar.
4. Don't append version number if bundled inside other larger deliverables
because the enclosing deliverables, such as an application server (e.g., JBoss 4.0.4, jakarta-tomcat-5), a tool(e.g., apache-ant-1.6.5), aleady have the version numbers, thus no version number for jboss.jar, catalina.jar, and ant.jar.

The Worst Java Job Interview Questions.

Why are you looking for a job?
Strictly speaking, this is not a java question, but it shows up in almost every job interview I've been to. The interviewer is testing the candidate's motivation for a job change. Invariably, the answer will be something like, advancing career and professional development. Of course, the candidate won't tell you he/she is looking for a 15% salary increase to cover the gas price increase, or he doesn't get along with his co-workers, or he didn't get the promotion or bonus, or he was rated Under-Perform in last year's performance review.
Which OS do you use in your development work, Linux, Windows, or Solaris?
Java is cross-platform, and I couldn't care less about OS while I'm writing java code. Unless the job is specifically about porting applications to other OS and deploying/distributing applications, I don't see how this is relevant. J2EE, JavaEE and Web applications are all made up of components that are managed by the application server, and thus shielded from the underlying OS.
Are you familiar with Oracle Database, or DB2?
Java persistence can now be easily achieved with ORM frameworks such as Hibernate, TopLink. The latest release of EJB 3 and Java Persistence API has standardize the way persistence is done in Java, J2EE, and JavaEE. The goal of these industry efforts is to let Java developers forget database stuff, which should be left to DBA. Even if Java developers in this project need to deal with database directly, I suppose they need to know about database design concepts and SQL, not some Oracle or DB2 stored procedures.

A New Option in Jar Command in JDK 6

DK 6 adds a new feature to the jar command: e. Other options of the jar command are still the same. This is the partial usage from JDK 6 beta 2:
C:\tools\jdk6\bin>jar
Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
Options:
...
-e specify application entry point for stand-alone application
bundled into an executable jar file
...
For example, I run jar command to package a self-contained application in a jar file:
C:\ws\nb\scrap\build\classes>C:\tools\jdk6\bin\jar cvfe ..\..\dist\hello-world.jar com.javahowto.test.HelloWorld com
added manifest
adding: com/(in = 0) (out= 0)(stored 0%)
adding: com/javahowto/(in = 0) (out= 0)(stored 0%)
adding: com/javahowto/test/(in = 0) (out= 0)(stored 0%)
adding: com/javahowto/test/HelloWorld.class(in = 572) (out= 348)(deflated 39%)
Then I can distribute hello-world.jar to users, who can run hello-world app like this:
C:\download\hello>java -jar hello-world.jar
Hello world!
Users can run it with any version of java; it doesn't have to be JDK 6. What the extra e option does is simply adding a Main-Class entry in the jar's META-INF\MANIFEST.MF:
Manifest-Version: 1.0
Created-By: 1.6.0-beta2 (Sun Microsystems Inc.)
Main-Class: com.javahowto.test.HelloWorld
This new feature is helpful when packaging simple self-contained apps, and application client modules in J2EE/JavaEE, both of them require a Main-Class entry in MANIFEST.MF. So I don't have to create one beforehand, or have Apache Ant generate one.

How to run Tomcat manager web application

1. Add the security role manager to $CATALINA_HOME/conf/tomcat-users.xml, and assign this role to a username, say tomcat:


2. Start Tomcat:
$CATALINA_HOME/bin/startup.sh
(%CATALINA_HOME%\bin\startup.bat on windows)
3. Browser the URL http://localhost:8080, and click the Tomcat Manager link on the upper-left corner. In the basic login page, enter username tomcat and password tomcat, as specified in conf/tomcat-users.xml. Tomcat Manager web application allows you to view Tomcat server info, deploy and undeploy webapps, and other simple management tasks.