JavaMix

it`s all about JavaPrograming

Archive for the ‘systemprograms’ Category

finding system information/environment using Java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package keyboardreader; // my package

/**
*
* @author vijay
* http://javamix.wordpress.com
*/
import java.util.*;
import javax.swing.*;
import java.awt.*;

public class SystemEnvironmentlook
{
private final static JTextArea output = new JTextArea();

public static void main( String args[] )
{
initGUI();

Map env = System.getenv();
Iterator iter = env.keySet().iterator();
while ( iter.hasNext() )
{
String key = iter.next();
output( String.format(“%s >>>> %s\n”, key, env.get(key)) );
}

System.out.println( “\n\n” );
}

public static void output( String str )
{
System.out.print( str );
output.append( str );
}

public static void initGUI()
{
output.setForeground( Color.WHITE );
output.setBackground( new Color(60,52,90) );

JFrame f = new JFrame( “System Environment -JavaMix” );
f.add( new JScrollPane(output), BorderLayout.CENTER );
f.setSize( 640, 700 );
f.setVisible( true );
}
}

OUTPUT:

USERPROFILE >>>> C:\Documents and Settings\vijay
PATHEXT >>>> .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
SystemDrive >>>> C:
TEMP >>>> C:\DOCUME~1\vijay\LOCALS~1\Temp
ProgramFiles >>>> C:\Program Files
Path >>>> C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Java\jdk1.6.0_03\bin;C:\Documents and Settings\vijay\Desktop\final Data\Remote compiler\RemoteCompiler\build\classes\remotecompiler
HOMEDRIVE >>>> C:
PROCESSOR_REVISION >>>> 0f02
CLIENTNAME >>>> Console
USERDOMAIN >>>> UTS-SYSTEM09
ALLUSERSPROFILE >>>> C:\Documents and Settings\All Users
PROCESSOR_IDENTIFIER >>>> x86 Family 6 Model 15 Stepping 2, GenuineIntel
SESSIONNAME >>>> Console
TMP >>>> C:\DOCUME~1\vijay\LOCALS~1\Temp
LOGONSERVER >>>> \\UTS-SYSTEM09
CommonProgramFiles >>>> C:\Program Files\Common Files
=:: >>>> ::\
PROCESSOR_ARCHITECTURE >>>> x86
OS >>>> Windows_NT
FP_NO_HOST_CHECK >>>> NO
HOMEPATH >>>> \Documents and Settings\vijay
PROCESSOR_LEVEL >>>> 6
COMPUTERNAME >>>> UTS-SYSTEM09
windir >>>> C:\WINDOWS
SystemRoot >>>> C:\WINDOWS
NUMBER_OF_PROCESSORS >>>> 2
USERNAME >>>> vijay
ComSpec >>>> C:\WINDOWS\system32\cmd.exe
APPDATA >>>> C:\Documents and Settings\vijay\Application Data

note: this is not my program, iam just copied and edited & i don`t have any rights on this program any one can copy,edit.
JavaMix Blog

Written by katta vijay

April 22, 2009 at 12:34 pm

converting system date to required format

package automatedsms; // my package name

/**
*
* @author vijay
*/
import java.util.Calendar;
import java.text.SimpleDateFormat;

public class DateUtils {

JavaMix Blog

JavaMix Blog

public static String now(String dateFormat) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
return sdf.format(cal.getTime());

}

public static void main(String arg[]) {

// different date formats
System.out.println(DateUtils.now(“dd MMMMM yyyy”));   // calling now method with my required format
System.out.println(DateUtils.now(“yyyyMMdd”));
System.out.println(DateUtils.now(“dd.MM.yy”));
System.out.println(DateUtils.now(“MM/dd/yy”));
System.out.println(DateUtils.now(“yyyy.MM.dd G ‘at’ hh:mm:ss z”));
System.out.println(DateUtils.now(“EEE, MMM d, ”yy”));
System.out.println(DateUtils.now(“h:mm a”));
System.out.println(DateUtils.now(“H:mm:ss:SSS”));
System.out.println(DateUtils.now(“K:mm a,z”));
System.out.println(DateUtils.now(“yyyy.MMMMM.dd GGG hh:mm aaa”));

}

}

output:

21 April 2009
20090421
21.04.09
04/21/09
2009.04.21 AD at 12:43:20 GMT+05:30
Tue, Apr 21, ’09
12:43 PM
12:43:20:687
0:43 PM,GMT+05:30
2009.April.21 AD 12:43 PM

Written by katta vijay

April 21, 2009 at 7:13 am

serialport communication using Java

before going to execute this program read how to install comport api for windows

In java there is no inbuilt support to access serial or parallel ports, to over come this we are taking support of  Java communication API.

after downloading the java communication api extract the folder then you can get the following…
in Commapi folder we require
comm.jar

javax.comm.properties

win32com.dll

after getting these files perform following operations….

  • Copy file comm.jar in <JAVA_HOME>\jre\lib\ext
  • Copy file javax.comm.properties in <JAVA_HOME>\jre\lib
  • Copy file win32com.dll in <JAVA_HOME>\lib

now you can able to access the commport by Java programm.

The following example displays the available ports(serial and parallel ports) and their type:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package keyboardreader;

/**
*
* @author vijay
*/

import javax.comm.*;
import java.util.Enumeration;

public class ListPorts {
public static void main(String args[]) {
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
while (ports.hasMoreElements()) {
CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
String type;
switch (port.getPortType()) {
case CommPortIdentifier.PORT_PARALLEL:
type = “Parallel”;
break;
case CommPortIdentifier.PORT_SERIAL:
type = “Serial”;
break;
default: /// Shouldn’t happen
type = “Unknown”;
break;
}
System.out.println(port.getName() + “: ” + type);
}
}
}

output is like this :

COM1: Serial
COM2: Serial
LPT1: Parallel
LPT2: Parallel

Written by katta vijay

March 25, 2009 at 7:30 pm

finding the local host ip

package sampleprograms;
import java.io.*;
import java.net.*;

/**
*
* @author katta vijay
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here

try{
String ip =  InetAddress.getLocalHost().getHostAddress();
System.out.println(ip);
}catch(Exception e){
}
}

}
—————————————————-output is————————
10.0.0.223

Written by katta vijay

February 4, 2009 at 6:06 am

Follow

Get every new post delivered to your Inbox.