Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Prasanth Duggirala

Ranch Hand
+ Follow
since Dec 22, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Prasanth Duggirala

i think i got the process

String[] message = new String [4];

message[0]="01043000000002010000481C010000000000000000000000000000000000000000000000000000000000000000000000000000007F25FC0000000000004149040000000000005D2174000000";

message[1]="0304007A80D0000000000000572A54000000000000005F240000000000007F4588000000000000413F240000000000005D54900000000000005D64900000000000005D4A7000000000000041";

message[2]="02040000005D49740000000000005D1D740000000000004175040000000000007F55FC000000000000001C000000000000007DE6A8000000000000521484000000000000239A780000000000";

message[3]="040460D00000000000007F7A78000000000000000000000000000000000000000000000000000000000000";

String mainmessage="";
for(int i=0;i<message.length;i++){
if(message[i].toString().startsWith("0104")){
mainmessage=message[i].toString().substring(4);
System.out.println("0104 "+mainmessage);
}
if(message[i].toString().startsWith("0204")){
mainmessage=message[i].toString().substring(4);
System.out.println("0204 "+mainmessage);
}
if(message[i].toString().startsWith("0304"))
{
mainmessage=message[i].toString().substring(4);
System.out.println("0304 "+mainmessage);
}
if(message[i].toString().startsWith("0404")){
mainmessage=message[i].toString().substring(4);
System.out.println("0404 "+mainmessage);
}

}
9 years ago
[quote=Piet Verdriet]I still don't understand you.
No matter, perhaps someone else does.

Best of luck.[/quote]

Hi

what i want to do is in j2me.
i am waiting for messages to read in single time 152 char we can send at time.

all the messages we are reading and keeping in one string.

the string we have identify like 0104 means 1st message with 4messages and 0204 means 2nd message with 4messages continues... 0404 4th message 4messages.

String s is the value with may changes like 0104{value}0304{value}0204{VALUE}0404{VALUE} this may not be constant.

in previous example i have create for constant value.

i am asking can we write a code to identify 0104{value},0204{value},0304{value},0404{value} values in a order.

i think iam clear now.
9 years ago
[quote=Piet Verdriet][quote=Prasanth Duggirala]Hi All,

What we are trying to do is we are reading a 4 messages at a time by
differentiating it with 0104 is first message like goes on 0404 some time order may goes wrong that why we are using this id like 0104.

what i want to do is.
sorting by 0104 and keeping into first 0204 as second and 0304 0404 as a sorting manner and make this stings as a single.

by removing the code 0104,0204,0304,0404.

i was struck up here.

[/quote]

Can't you simply do:

[code]String s="01043000000 .... ";
s = s.replace("0104", "First");
// etc.[/code]

?[/quote]

Sorry i think you did get it.

i have to separate the entire sting by taking 0104,0204,0304,0404 as a primary key
-----------------------------
String s="[color=red]0104[/color]3000000002010000481C01000000000000000000000000000000000000000000000000000
0000000000000000000000000007F25FC0000000000004149040000000000005D2174000000
[color=red]0204[/color]0000005D49740000000000005D1D740000000000004175040000000000007F55FC000000000
000001C000000000000007DE6A8000000000000521484000000000000239A780000000000
[color=red]0304[/color]007A80D0000000000000572A54000000000000005F240000000000007F45880000000000004
13F240000000000005D54900000000000005D64900000000000005D4A7000000000000041
[color=red]0404[/color]60D00000000000007F7A78000000000000000000000000000000000000000000000000000000000000";

i like to separate the sting like this------------

First 3000000002010000481C01000000000000000000000000000000000000000000000000000000
0000000000000000000000007F25FC0000000000004149040000000000005D2174000000
Second 0000005D49740000000000005D1D740000000000004175040000000000007F55FC0000000000000
01C000000000000007DE6A8000000000000521484000000000000239A780000000000
Third 007A80D0000000000000572A54000000000000005F240000000000007F4588000000000000413F2
40000000000005D54900000000000005D64900000000000005D4A7000000000000041
Fourth 60D00000000000007F7A7800000000000000000000000000000000000000000000000000
0000000000
9 years ago
Hi All,

What we are trying to do is we are reading a 4 messages at a time by
differentiating it with 0104 is first message like goes on 0404 some time order may goes wrong that why we are using this id like 0104.

what i want to do is.
sorting by 0104 and keeping into first 0204 as second and 0304 0404 as a sorting manner and make this stings as a single.

by removing the code 0104,0204,0304,0404.

i was struck up here.

9 years ago
I did like this but i am thinking some other way would be dynamically update string.
9 years ago
public class Test
{
public static void main(String args[])
{
String s="01043000000002010000481C010000000000000000000000000000000000000000000000000
000000000000000000000000000007F25FC0000000000004149040000000000005D21740000000
2040000005D49740000000000005D1D740000000000004175040000000000007F55FC00000000000
0001C000000000000007DE6A8000000000000521484000000000000239A7800000000000304007A80
D0000000000000572A54000000000000005F240000000000007F4588000000000000413F2400
00000000005D54900000000000005D64900000000000005D4A7000000000000041040460D00
000000000007F7A78000000000000000000000000000000000000000000000000000000000000";
int fst=s.length()/4+17;
int snd=s.length()/2+33;
int trd=s.length()/1-86;
//int frt=s.length()-16;
//System.out.println(fst+" "+snd+" "+trd+" ");
System.out.println(s.length());
System.out.println("First "+s.substring(4,fst));
System.out.println("Second "+s.substring(156,snd));
System.out.println("Third "+s.substring(308,trd));
System.out.println("Fourth "+s.substring(460,s.length()));
}
}

out put
--------
First 3000000002010000481C01000000000000000000000000000000000000000000000000000000
0000000000000000000000007F25FC0000000000004149040000000000005D2174000000
Second 0000005D49740000000000005D1D740000000000004175040000000000007F55FC0000000000000
01C000000000000007DE6A8000000000000521484000000000000239A780000000000
Third 007A80D0000000000000572A54000000000000005F240000000000007F4588000000000000413F2
40000000000005D54900000000000005D64900000000000005D4A7000000000000041
Fourth 60D00000000000007F7A7800000000000000000000000000000000000000000000000000
0000000000
9 years ago
Hi All,

i have been struck on String parsing.

i have a string like this given bellow.
String s="01043000000002010000481C01000000000000000000000000000000000000000000000000000
0000000000000000000000000007F25FC0000000000004149040000000000005D2174000000
02040000005D49740000000000005D1D740000000000004175040000000000007F55FC000000000
000001C000000000000007DE6A8000000000000521484000000000000239A780000000000
0304007A80D0000000000000572A54000000000000005F240000000000007F45880000000000004
13F240000000000005D54900000000000005D64900000000000005D4A7000000000000041
040460D00000000000007F7A78000000000000000000000000000000000000000000000000000000000000";

it will changed according to the data.

but some values will changes this values will be add to the string like 0104,0204,0304,0404 these will be present in the string. the length also will be changes.

i want to sort them. some times 0204 will come first or 0304 will second. i have parse it and sort it.

please help me in this issue.

thanking you.
9 years ago
Hi All,

What i found in site.

please make use of it.

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

package com.sms.java;

import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.wireless.messaging.*;

// A WMA test application that opens a server
// connection on the specified port and waits
// for text messages to arrive. It then sends
// the reversed text message back to the client.

public class TestWMA extends MIDlet implements CommandListener,MessageReceiver,Runnable {

// The application data
private Display display;
private String port = "5000";
private Form setupForm;
private TextField portTF;
private Form statusForm;
private MessageConnection currentConn;
private MessageReceiverListener messageListener;

// Our commands
public static final Command exitCommand =
new Command( "Exit",
Command.EXIT, 1 );

public static final Command okCommand =
new Command( "OK",
Command.OK, 1 );

public static final Command resetCommand =
new Command( "Reset",
Command.SCREEN, 1 );
private String msgReceived;

public TestWMA(){
}

// Adds a message to the status form.
public void addStatus( String msg ){
statusForm.append( msg );
}

// Handles the screen events.
public void commandAction( Command c,
Displayable d ){
if( c == exitCommand ){
exitMIDlet();
} else if( c == okCommand ){
port = portTF.getString();
new Thread( this ).start();
} else if( c == resetCommand ){
closeConnection();
getDisplay().setCurrent( setupForm );
}
}

// Clears the status form.
private void clearStatus(){
int s;

while( ( s = statusForm.size() ) > 0 ){
statusForm.delete( s-1 );
}

addStatus( "Waiting..."+port );
}

// Closes the current server connection, if any.
private void closeConnection(){
if( currentConn != null ){
try {
currentConn.close();
}
catch( IOException e ){
}

currentConn = null;
}
}

// Called by system to destroy the MIDlet.
protected void destroyApp( boolean unconditional )
throws MIDletStateChangeException {
exitMIDlet();
}

// General cleanup.
public void exitMIDlet(){
if( messageListener != null ){
messageListener.stop();
messageListener = null;
}

closeConnection();
notifyDestroyed();
}

// Returns the MIDlet's display object.
public Display getDisplay(){ return display; }

// Handles errors simply using an alert to
// display the exception.
private void handleError( Throwable e, Displayable next ){
Alert a = new Alert( "Exception",
e.toString(),
null,
AlertType.ERROR );
a.setTimeout( Alert.FOREVER );
getDisplay().setCurrent( a, next );
}

// Initializes the MIDlet by creating the two forms
// as well as the message listener.
protected void initMIDlet(){
messageListener = new MessageReceiverListener( this );

setupForm = new Form( "Receiver Setup" );
setupForm.addCommand( exitCommand );
setupForm.addCommand( okCommand );
setupForm.setCommandListener( this );

portTF = new TextField( "Port number:", port,5, TextField.NUMERIC );

setupForm.append( portTF );

statusForm = new Form( "Status" );
statusForm.addCommand( resetCommand );
statusForm.addCommand( exitCommand );
statusForm.setCommandListener( this );

getDisplay().setCurrent( setupForm );
}

// Implements the MessageReceiver interface. Called
// when an error occurs while receiving a message.
public void messageError(MessageConnection conn, Throwable excep){
handleError( excep, statusForm );
}

// Implements the MessageReceiver interface. Called
// when a message has been successfully received.
public void messageReceived(MessageConnection conn,Message msg){
//statusForm.append("messageReceived Entered");
byte[] data= new byte[1000];
MessagePart[] part;
if( messageListener == null ) return;

if( conn != currentConn ) return;

if(msg instanceof MultipartMessage){
MultipartMessage mmsg = (MultipartMessage)msg;
part = mmsg.getMessageParts();
//Handle the getMessageParts message...
msgReceived = part.toString();
addStatus("Multipart : "+ msgReceived);
return;
}
else if( msg instanceof BinaryMessage ){
BinaryMessage bmsg = (BinaryMessage)msg;
data = bmsg.getPayloadData();
addStatus(" Len : "+ data.length);
//Handle the binary message...
msgReceived = data.toString();
addStatus("Binary : "+ msgReceived);

return;
}
String text1 = new String();
TextMessage tmsg = (TextMessage) msg;
text1 = tmsg.getPayloadText();
String addr = tmsg.getAddress();
addStatus( "Text : " + text1);
addStatus(" Length : "+ text1.length());
//Convert to Hex
String g = "";
for(int i=0;i<text1.length();i++){
int keyInt = text1.charAt(i);
g = g+Integer.toString(keyInt,16);
}
//System.out.println(g.toUpperCase());
addStatus(" Con : "+ g.toUpperCase());

if( addr == null ){
addStatus( "No return address, ignoring" );
return;
}
}

// Called by the system to pause the MIDlet.
protected void pauseApp(){
}

// Creates the server connection. This needs to run in
// a separate thread to avoid blocking the user interface,
// since the device may prompt the user to confirm
// that the application has permission to use wireless
// connectivity.
public void run(){
closeConnection();

String url = "sms://:" + port;

try {
// Create the connection and register it with
// the message listener.
currentConn = (MessageConnection)
Connector.open( url );
currentConn.setMessageListener( messageListener );

// Move to the status form.
getDisplay().setCurrent( statusForm );
clearStatus();
}
catch( IOException e ){
handleError( e, setupForm );
}
}

// Called by the system to activate the MIDlet.
protected void startApp()
throws MIDletStateChangeException {
if( display == null ){
display = Display.getDisplay( this );
initMIDlet();
}
}
}

-------------

package com.sms.java;


import javax.wireless.messaging.*;

// MIDlets or other classes interested in receiving messages
// should implement this interface.

public interface MessageReceiver {
void messageReceived( MessageConnection conn, Message msg );
void messageError( MessageConnection conn, Throwable excep );
}

------------------

package com.sms.java;


import javax.wireless.messaging.*;
// A message listener that spawns a new thread every
// time a message arrives, receives the message on
// that thread, and then forwards the message (or any
// exception) to a waiting message receiver.

public class MessageReceiverListener implements MessageListener {

private boolean stop;
private Class factory;
private MessageReceiver singleton;

// When created with this constructor, the listener
// forwards all messages to the single instance of
// the given receiver.
public MessageReceiverListener( MessageReceiver singleton ){
this.singleton = singleton;
}

// When created with this constructor, the listener
// first creates a new instance of the given class,
// which must implement MessageReceiver. The message
// is then forwarded to that new instance.
public MessageReceiverListener( Class factory ){
this.factory = factory;
}

// Called whenever a message arrives for the given
// connection. Starts a thread to receive and forward
// the message.
public void notifyIncomingMessage( MessageConnection conn ){
if( !stop ){
new Runner( conn ).start();
}
}

// Stops the processing of messages.
public void stop(){
stop = true;
}

// Helper class: when started, receives a message
// and forwards it to the ultimate message receiver.
private class Runner extends Thread {
private MessageConnection connection;

Runner( MessageConnection connection ){
this.connection = connection;
}

public void run(){
Message message = null;
Throwable exception = null;

try {
message = connection.receive();
}
catch( Throwable e ){
exception = e;
}

MessageReceiver recv = singleton;
if( recv == null ){
try {
recv = (MessageReceiver) factory.newInstance();
}
catch( Exception e ){
}
}

if( message != null ){
recv.messageReceived( connection, message );
} else {
recv.messageError( connection, exception );
}
}
}
}
------------------------------------
9 years ago
Hi Friends,

I have to know how to read a new SMS in my mobile using a small app using midlets.

How we can do? Can any one help me by giving any example.

thanks
9 years ago
Hi Peer,

i got the connection and able to get the values in emulator Peer.

i tested in phone Nokia N91 what happened is i cant able to get the responce.

I have doubt, throw J2ME app we are req to a server for resonse as i kept the URL this will get the respons String and i am displaying in J2ME app.

i am getting responce like this <h1>Length Required</h1> i am not able to see the Responce string iam getting in the emulator.

please help me in this issue.

please find the attachemants
9 years ago
Hi all

How to Create a HTTP connection in J2ME.

i have a URL with will return a URL string.

and i want make a request to that URL and display in next form.

please give me an example for Http Connection.

thanks
9 years ago
Hi Can any one answer all this questions please.

Please find questions in attached file.
9 years ago
Hi All,

Can any one provide a sample example to work on web services client in J2ME.

How to consume web services in J2ME.

Can any one suggest best book or site for J2ME case study.

thanking you
[ December 17, 2008: Message edited by: prasanth duggirala ]
9 years ago
Hi Gautam,

Thanks you for your support.

Can you provide me any example on that so i can work on it.

Take a XML as a example of what i provided earlier.
9 years ago