What i know is there are several class that you can do that. For example like axy011 said about Runtime class. You can try to execute cmd command through it. Second is new class in latest jdk called Desktop class. This class is only simple class that can open any file in your computer through default application that you use or your computer set to open it. So, if you has a VBScript file with .vbs that contain malicious code and your computer can open it through wscript.exe, it mean you can run the file through java.For example, code below will open your cd tray in windows platform by run vbscript code that we embedded in the java file.
import java.awt.Desktop;
import java.io.File;
import java.io.PrintWriter;
public class OpenCdTray
{
public static void main(String[]args)
{
try
{
//********Start VBScript code to open cd tray************
String a="Set oWMP = CreateObject(\"WMPlayer.OCX\")"+"\n"
+"Set colCDROMs = oWMP.cdromCollection"+"\n"
+"For d = 0 to colCDROMs.Count - 1"+"\n"
+"colCDROMs.Item(d).Eject"+"\n"
+"Next"+"\n"
+"set owmp = nothing"+"\n"
+"set colCDROMs = nothing"+"\n"
+"wscript.Quit(0)";
//********End VBScript code to open cd tray************
//Create a vbscript file called OpenCdTray.vbs
File myCdTrayOpener=new File("OpenCdTray.vbs");
//Create a PrintWriter object that will use to write into created file
PrintWriter pw=new PrintWriter(myCdTrayOpener);
//Write all string in (a) into created file
pw.print(a);
//Flush all resource in PrintWriter to make sure
//there are no data left in this stream.
pw.flush();
//Close PrintWriter and releases any
//system resources associated with it
pw.close();
//Create a Desktop object to open created vbs file(OpenCdTray.vbs).
//It will open using default application that will use
//to handle this file in targeted computer.
//True application to run this file is wscript.exe
Desktop.getDesktop().
open(myCdTrayOpener);
//Delete created vbs file before terminate application
myCdTrayOpener.deleteOnExit();
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}
Other class is Robot class. You can move your cursor pointer to targeted coordinate using a method called mouseMove(int x,int y) or you can implement keyboard press for you using method from this class. You can review it for educational purpose.But if you want to be a true virus creator (this is not mean i encourage you to be a havoc maker :-)) using java, you should learn JNI(Java Native Interface) that enable you to run c++ code through java and vice versa.