site-wide search

SomaliNet Forums: Archives

This section is online for reference only. No new content will be added. no deletion either...

Go to Current Forums ...with millions of posts

Any Java professional to help me with a few question, Urgent please !

SomaliNet Forum (Archive): General Discusions: Archive (Before Mar. 13, 2001): Any Java professional to help me with a few question, Urgent please !
Top of pagePrevious messageNext messageBottom of pageLink to this message  

XAMDI

Saturday, March 03, 2001 - 07:53 pm
Hi bro/sisters
Well i am sort of having few regarding java programming and would like if there is any brother or sister out here who is a java expert to help me.
Well to be precise, i am an amatuer new to java and , but having lately appreciated some of the intrinsic java programming, i encountered few blocks of trouble.
I even tried java sun website but was unable to find a FAQ regarding my problems.

well here is my problem,In my Applet , doubleThreat runs in a my defined thread, overrides stop() to do nothing, and has a delay parameter that can be set to delay its rough effects. when the applet is initialized and the thread starts, it paints to the screen and then sleeps for a specific length of time. Unfortunately, when this applet restarts, it gets up on the wrong side of screen. It immediately starts , and it continuously calls the class doubleFrame to open big windows, piling them one atop another. it also pretends and initialises another Applet and continously appends the largest integer to a Stringbuffer.

The results are what I havent expected - the applet quickly uses my resources. Because it keeps creating windows, it creates so many mouse events that my mouse becomes useless and i cannot toggle the windows from the keyboard. The applet effectively excludes me from my workstation. At this point i can always reboot (not without risks), or on a network you can go elsewhere, login, and kill the offending processes. Until i do, on a Sun Sparcstation for example, Netscape, OpenWindows, and the windows manager are left to battle it out for my resources, and i am forced to look at the graphics of the open window.
i cant risk to shut down my workstation everytime as i am sometimes in a network doing important things.
Anyone who can help, please post your message, i will follow this
thx in advance to those who post their valuable response

Top of pagePrevious messageNext messageBottom of pageLink to this message  

DuH

Sunday, March 04, 2001 - 04:04 am
Take your Java Applet doublethread black stinking a$$ out of our faces you dum sh$t!heheheheheheeh DuH?

Top of pagePrevious messageNext messageBottom of pageLink to this message  

devils_love

Sunday, March 04, 2001 - 09:55 am
I am not quite sure if I understood the description of your problem entirely...and it would be better if you post the specifications of your program..i.e..what your program is supposed to do. Anyways I will be more than happy and try to code your program if you provide me with complete specifications.You can post here. As it is I have no clue as to what your program is supposed to Accomplish.

Having said that I am going to try to help you with these problems but my answers are based on the assumptions that I made from what you have scribbled here.

First I am not sure if the stop() method you refering to is that of the applet class or that of the thread class..as both classes have it...but assuming it is the applet class's start() and stop() methods..you need to code both start() and stop() method of the applet..so that the init() method calls start() to run and create thread object..whenever the applet is run.and stop() method stops the thread from executing...i.e..sets the thread to null..so that..it is not using any resources....after the applet is stopped or the applet page is minimized...consider this simple applet+thread example :

import java.applet.Applet;
import java.awt.Graphics;

public class DevilsLove extends Applet implements Runnable {
private Thread xamdi = null;
public void start() {
if ( xamdi== null) {
xamdi = new Thread(this, "Xamdi" );
xamdi.start();//this calls..the thread object's start() method
}
}
//Runnable interface's run method implemented
public void run() {
Thread curThread = Thread.currentThread();
while (xamdi == myThread) {
repaint(); //calls the paint method
try {
Thread.sleep(2000);
} catch (InterruptedException e){
// the VM doesn't want us to sleep anymore,
// so get back to work
}
}
}
public void paint(Graphics g) {
g.drawString("Xamdi is ineed of help", 5, 10);
}


// overrides Applet's stop method, not Thread's
public void stop() {
xamdi = null;
}
}


This class uses inerface...runnable instead of inheriting thread class ...but the point is...all this class does is create a thread and when the applet is loaded the browser calls the ...init()method...and in this case the the init() method is the defualt one in the applet class since we did not code it....secondly init() method calls start() which creates the thread "xamdi" and calls the thread class's start() method which in turn invokes the run() mehtod of the interface runnable...then obtains the current thread and compares it to the thread that invoked the start() method of the thread...and calls repaint() which invokes..paint method which writes the string..."Xamdi is in need of help" to the given pixel's cordinate constantly

Well the whole point is that...what happens when the user minimizes the screen..well the browser calls the stop() method of the applet which sets the thread reference to null...in this way it will not use any resource while the page or the site is minimized.


You also mentioned couple of other problems...one being a multiple windows generated when the thread exits from the sleep face to run again...well I can only assume that you either creating a multible instance of class doubleFrame within your run method...or...you coded some kind of mouse event....namely mouseDragged,
mouseClicked or mouseMoved...again one needs to see your code to make the right corrections as to what is causing the cascaded frames to be created....my understanding is...the class doubleFrame...is within an applet...i.e being an applet run as an application.

Top of pagePrevious messageNext messageBottom of pageLink to this message  

Alipapa

Sunday, March 04, 2001 - 10:00 am
hi hamdi,

I am not java expert but as i can see you having some kind of "infinite loop". The reason can be you overided the stop() method. I duno.

However, i can give you the URL of the java news groups. What you need to do though is post your code and tell the news group the version of the compiler you are using and the platform. I mean be specefic as much as you can. Even try to post the error message if you got one.
Here are the URLs.

JDC(Java Develpoer Connection)

http://developer.java.sun.com/developer/jdchome.html . This site is great one from Sun Microsystem.

Java lobby.

http://www.javalobby.org


Good luck hamdi.

Alipapa

Top of pagePrevious messageNext messageBottom of pageLink to this message  

LogicS

Sunday, March 04, 2001 - 10:14 am
Guys


Please can any one help me? I can,t Log on My Pc...which I have installed the NT4 OS....when I tried to log on.....it Gives me this Strange Noise....Then when press, Ctrl+Alt+delete....come up My screen.....I can,t Log on.....I did tried but Nothing happenning....Please can any one tell me what should I do? thanks all

Top of pagePrevious messageNext messageBottom of pageLink to this message  

Alipapa

Sunday, March 04, 2001 - 10:15 am
Hey devil,

That was great. but do you think that you have bug here?


Thread curThread = Thread.currentThread();
while (xamdi == myThread) {


Where and when did you declared "MyThread"?
while (xamdi==myThread).

I guess it should read:

while (xamdi==curThread) instead of while (xamdi==myThread).

I didn't run the code and i am not java guru but my two prgamming cents led me to ask that.

Alipapa

Top of pagePrevious messageNext messageBottom of pageLink to this message  

Alipapa

Sunday, March 04, 2001 - 10:20 am
logics,

don't listen to this login phony dialog. After you pressed ALT+CRTL+DELETE and this login dialog comes up just try to click "CANCEL" or "OK".

Alipapa

Top of pagePrevious messageNext messageBottom of pageLink to this message  

LogicS

Sunday, March 04, 2001 - 10:53 am
Alipapa

I can,t Cancel...infact I can,t do nothing........The PC would not let me do nothing..........when I tried to Log in the Win98 Os same PC.............it is working OK.......I can do everything whit Win98.........but I can,t enter whit WintNT4 OS.... and I really need that Section......cuz of MY exams...I guess I have to call PC supporter...........which will cost a lot....but any way thanks a lot....

Top of pagePrevious messageNext messageBottom of pageLink to this message  

Anonymous

Sunday, March 04, 2001 - 11:37 am
Alipapa ye are right bro, there is a bug in Devils code, i run his code and it cant compile, well then i changed to yours and viola it did work,

Top of pagePrevious messageNext messageBottom of pageLink to this message  

devils_love

Sunday, March 04, 2001 - 12:05 pm
Alipapa :

Yes it is supposed to be "xamdi==curThread". Thanks for catching the bug...look this is an example...it was supposed to serve as purely illustrational...but I am not impeccable..as the saying goes to...TO ERR IS HUMAN...and I as a "hard-core" programmer..make tons of both...logical and syntax errors on daily basis....you should have seen my last c++ programs...they contained a number of logical flaws which I just found months later...but I am glad to have been caught by you rather than the Java compiler..JDK.....thx again.....


WARNING ...the above example is written in jave 1.1.routine..and do not contain swing routines....though you could convert it in a jiffy...note also the javax.swing.JApplet class in the swing version is derived from...java.applet.Applet....

Top of pagePrevious messageNext messageBottom of pageLink to this message  

Anonymous

Sunday, March 04, 2001 - 01:43 pm
LogicS the same thing happened to me before. what I did was to reinstall windows4 over the old one and that seemed to jix it.

Top of pagePrevious messageNext messageBottom of pageLink to this message  

netizen

Monday, March 05, 2001 - 06:44 am
Xamdi, devils_love gave you a perfect answer.

Logics, unlike 95/98, NT needs a valid username/password before you can get access to the computer. I don't remember the old versions but the current one 2000 server or 2000 professional creates a default user "administrator" and prompts you a password field for future use. Try to log on as administrator with your favorite passwords. Maybe you created one but forgot about it.

You can also try username/pw combination guest/guest.

Top of pagePrevious messageNext messageBottom of pageLink to this message  

Nour

Monday, March 05, 2001 - 08:00 am
Xamdi, I think your question is not genuine. The reason I'm saying that is , it looks like you created the problem deliberately by overriding the stop() method(of the applet) to do "nothing". You are supposed to override it to stop the thread. for example, if you leave the page, applet's stop() method will be called(by the browser's VM) but the thread will continue(assuming run() method is executing in a loop) because you did not stop it. Later on when applet's restart() method is called(by revisiting the page,for example) it will launch new thread on top of the first one and you will have #of threads==#of restart calls and eventually exhausting all you recourses. my advise to you is that; NEVER ever launch a thread from applet without overriding applet's stop method to stop the thread when applet's stop method is called.

Top of pagePrevious messageNext messageBottom of pageLink to this message  

devils_love

Monday, March 05, 2001 - 01:57 pm
One more correction...this is one is relatively trivial...it is the comment where I mention the repaint() method of the applet...see below

"repaint(); //calls the paint method"


Well the repaint() method does call the paint(Graphics g) method..but it calls it indirectly..and this is how it does...repaint() method first calls update() method of the applet then the update() mainly clears the client area of the window..i.e portion of the window where text is written or graphics are drawn...and then the update() method calls paint(Graphics g) method...therefore repaint() does it indirectly through update() method.

I suppose you have seen techniques where programmers override the update() method to do nothing...usually when you want the user of your program to draw or sketch a figure on the client area..so that each time the applet redraws itself the image of the previous sketch is not lost...and if a programmer forgets to code the update() method he/she will have it's screen cleared each time..because that is what update() does by default if not overriden....update() is aslo overriden for animations..i.e...double-buffering to avoid flickering...

Top of pagePrevious messageNext messageBottom of pageLink to this message  

Nour

Tuesday, March 06, 2001 - 06:46 am
Java Applets is for rookies and web guys. If you want see the beauty of java, go into other heavy duty java technologies such as RMI(for Distributed Computing), Beans for enterprice environments(i.e. component integration), JNDI(built on top of LDAP) for directory resourse services, JDBC for Database access, Servlets(server side web component).
For ease of application development/deployment, all the above and more are integrated into the powerfull sun's J2EE which sweeping the industry of app develepment.

Top of pagePrevious messageNext messageBottom of pageLink to this message  

devils_love.

Tuesday, March 06, 2001 - 09:00 am
Nour

RMI (Remote Method Invocation)..is not that heavy of a duty...for it only gives the mechanism of two java programs running in two separate JVM(Java Virtual Machine) to communicate..so that you can invoke methods on an object running in an other JVM. If you really did program in C..you will realise that this technique has been used long before JAVA came out...it is called RPC(Remote Procedure Call)..it has also been used for many different procedural languages...if you also do program in Visual C++ you will notice it also uses the same technique for distributed programming..it uses DCOM(Distributed Component Object Model)...though DCOM is platform(Windows) dependent..RMI is platform(Unix, Windows, OS/2, AS/400..and many more ) independent but it is language(Java only) dependent...In my view RMI is an enhancement or a variation of JAVA's Client/Server programming.

CORBA(Common Object Request Broker Architecture ) is the cutting edge technology, if I may say, for distributed programming today..for it is both language and platform independent...thus you can write a C++ program and invoke it's functions on a java program..through this mechanism..you will have to code IDL(Interface Definition Language) for mapping...now you have the luxury of not worrying about..what OS(Operating System) you are using nor do you have to worry about what language.


JDBC..a very interesting feature...I do agree on this one..java.sql package is pretty much enough to access remote database....all you have to do is load the driver classes for any database(oracle, sybase, db2..) and then establish connection and then excute SQL statements...all the classes you need are in java.sgl...which means quick lookups while coding....

Servlets...is the feature I love most about jave..it is good way to replace those cryptic code of PERL for CGI(Common Gateway Interface) programming..though you will need some sort of jave enabled-server like "servletrunner" which comes with JSDK for learing purpose...but I prefer and I use JRUN engine which is a complete servlet engine...I would recommend this...it also comes with full support of JSP(Java Server Pages)..and more server-side includes extentions...you can one get it from this site..www.jrun.com....


Nour..you sound like the type of guy I was looking for..one who is into this stuff..I am looking forward to discusing the advanced features of JAVA..but don't forget APPLETS are not for rookies only....we seem to be dealing with someone who might just be learning jave as is the case with XAMDI..and therefore we have to be able to explain in very applet with degree of simplicity..but You can have an applet(signed applet..that is an applet that can by pass the java security mechanism) communicate servlet which uses pool of connections through RMI which then through JDBC routines excutes SQL statements on a number of different remote databases that are running different OS(Opertaing systems)...and then return the result back to the browser..see how complex an applet can get...not to mention on-line games which are mostly written in applets...I don't know about you..but when I was in school the most difficulty assignment I had to code in applet was a GAME..GAME-PROGRAMMIG requires an effecient programmer which we are not at that level. Applets are not trivial...many C++ programmers call java.."C++ OF THE WEB"...the only reason is because of features like applets...

Top of pagePrevious messageNext messageBottom of pageLink to this message  

devils_love.

Tuesday, March 06, 2001 - 09:12 am
Nour :

One more question..have you ever used JTAPI( Java Telephony API )...any familiarity on this feature will be appreciated...I might get a project in this particular feature...

Top of pagePrevious messageNext messageBottom of pageLink to this message  

Nour

Tuesday, March 06, 2001 - 11:32 am
DL

It looks like we are in the same boat for living:). I agree some of what you said. I used both RMI and other RPCs in C/C++. RPC are very crude. What I mean by crude is that the programmer has to implement basicaly everything including the protocol for communication on top of well-known protocols(such as TCP/UDB). In RMI you don't have to worry all that(except some small configurations with interfaces).RMI is very flexible in terms of designing and optimizing your program. Imagine in you code, you don't have to worry about process and machine boundaries. As a result of that you can create heavy duty objects in multiple machines and you just write a client code as though all those objects are in your local machine. Of course RMI has it's perfomance drawback which is inherited from java(Intepreted Byte Code) compared to other Distributed Protocals whick are implemeted in C/C++( such as COM and COBRA). RMI supports what is know as Activatable Objects. what this means is that you can have a group of RMI object that are installed in the same machine but each one is activated/deactivated as needed( but the registeration and configuration is more complex). You can also launch a different VM for different objects in the same machine and clients will not know this is happening. You can do lot of other cool stuff with RMI. Mainly the underlying protocal for RMI is TCP/IP( I mean sockets). But if you want integrate with COPRA, you can use RMI-IIOP(IIOP is protocol used by COPRA) then you have the best of both worlds. If you have a Q's about RMI, we can talk about it some other time. I have some time this week. We just had code freeze this week. So we just flexing our muscles for next one.

I actualy like applets just because they are good in animations. As for your question about CTI(Computer Telephony Integration). I realy don't know if there is TAPI available for Java. What I know is that most PBX manufacturers such as Nortel, Lucent, implement their TAPI or TSAPI in C/C++. but there must be some for java.

Top of pagePrevious messageNext messageBottom of pageLink to this message  

NeedAdvice

Tuesday, March 06, 2001 - 11:49 am
WAw guys


I need some Advice, I am really intresting about Programming but I think it is difficult specially C++..can any one who have no experience about Programming start from C++? do you think guys one can teach Himself? I bought other day Selfstudy C++ Book whit CD, But my Computer does not seem to work. which softwere will I install my PC in order to work whit C++? I really like Java 2.......but what u guys think can I study at Home or u should have to go to School 4 it? how long it takes to became a progarammer? i really need help. thanks

Top of pagePrevious messageNext messageBottom of pageLink to this message  

java expert

Tuesday, March 06, 2001 - 12:25 pm
nour and devils stop the prefarication and the moification of java articles, out of respect, that is if you are wise guys.
As to Hamdi, all i can say is, you are smart enough, to mislead these guys with the famous java buzzle, i asssume that you have taken that exam, cause none who isnt a java expert can know the threatening applet,lol.
to this guy who wants to learn c++.
try to download one of these c++ compilers, you can download one at www.Borland.com, though i would suggest that you familiarise your self with the language before undertaking the download,
Devils i dont mean no offence bro, but indeed, you arent a java expert so is nour.
i would suggest that you too might need a little bit of experience in dat regard.
the question hamdi asked is known as the famous threatenning applet and is only known by those who studied java and have taken java exams( proffessional_)
Anyway, the code you have written above is a laughable one indeed, cause that isnt a code at all.
is that how ye are a java expert?
walaalo, please walaahi i loved at it when i saw it,,,,even the last article you posed is familiar too, cause website ayuu ku qoran yahay, well done ye can change the style but ye cant hide the font,,lol

Top of pagePrevious messageNext messageBottom of pageLink to this message  

java expert

Tuesday, March 06, 2001 - 12:32 pm
need advice
Bro i would uggest trhat ye try to laern C language, there is one nice C compiler that ye can download for free, it is called C Miracle.
that is a good start point bro if you wanna learn C++ and java,
By the way, before you go deeper in these areas, are ye able to understand javascriting and Dhtml, cause if you arent, then i would suggest that ye do these too.
Try to learn javascripting, it doesnt need anything except a Notebook editor like the one that comes with your windows if you are using windows ,,play with them by just writing funny scripts, it will give u the feel for programming,,,though it isnt a programming language that ius well-fledged as java or c++.

Top of pagePrevious messageNext messageBottom of pageLink to this message  

NeedAdvice

Tuesday, March 06, 2001 - 12:51 pm
JAva expert


Thanks a lot...but as I said I have no experience any programming....althought I know Networking.. thanks for the suggestion....I will tray to down laod and install my PC.....so which one do u think is more difficult to Learn Networking or Progaramming......ppl keep telling me Progaramming is taugh and Boring.....any way can any one suggest for me how long it will take me to learn?

Top of pagePrevious messageNext messageBottom of pageLink to this message  

java expert

Tuesday, March 06, 2001 - 02:07 pm
Need Advice
networking isnt a profession bro, if u really do wanna learn some sort of profession tyen i would suggest that ye learn c++, java but all these cant be learned in any one way.
since programming depends on the number of languages ye know, i would suggest that ye start with C/C++, that is the groundwork.
Java is complicated language that needs some sort of previous programming language.
But if you are serious really then start with C/c++..
and besides there are a lot of free software that ye can get to learn programming.

networking is like windows bro, it isnot a proffesion really. once ye get your certificate in networking no one will hire ye really.

Top of pagePrevious messageNext messageBottom of pageLink to this message  

devils_love.

Wednesday, March 07, 2001 - 05:52 am
Nour :

Thanks...there is an API for telephony in java...it is called JTAPI but I have never programmed in it...so I was thinking you might have come across it...but anyway I am very delighted to have someone with that depth of knowledge in this exciting field of programming. I am looking forward to learing from each other...


NeedAdvice:

Programming may be tough..but it is never boring..that is for certain..you always have something to challenge you...I find myself thinking how I would implement or solve a problem while in the washroom or in my car driving...you will find yourself consumed by it...

Well If I come back to your question...can someone without prior experience/knowledge in programming teach himself/herself C++ ?. The simple answer is no..you at least need to know some other language...like C, Pascal, Fortran, Cobol, smalltalk or another language for that matter. C++ is Object Oreinted, which means you will have to learn OOD(Object Oreinted Design) which by itself is another course, so before you go into it you will have to possess a basic programming knowledge..i.e..Data Types(int, double, Long, char, user-defined(objects) ), Aggregate data types( mainly Arrays) ),control structures(if/else..) ,Loops(while, for, do/while..), Functions, pointers(the most challenging of all), File I.O(Input/Output..i.e how to read from or write to a file ), Structures, Unions..and many more...and to acquire all thess I would suggest you start with "C"...and the reason is C++ is nothing else but a better and refined "C". C is procedural language unlike C++ though if you master in "C" the transition from "C" to C++ will be smooth and quick. For a good starting book I would recommend "C How to Program" by Deitel & Deitel and the ISBN is 0130895725.


Having said that I would also like to point out that you will experience a times where you will be confused and you will do lot of head scratching...but in the end it will pay off...see it is true when people say...NO PAIN NO GAIN..every thing that is of any use needs an effort on your part...and programming is no exception...in the end you will get a satisfaction when you see people using a software you designed and coded...that is more gratifying than the hefty salary you will probably make...a little encouragement there.

One final tip..when "Bjarne Stroustrup", inventor of C++, was asked what is the best way to master in programming he said :

1-Practice, Practice...practice
2-Imitate Good programmers
3-Read, Read

You will probably realise that one of the most important things to do in order to become a programmer is to write as much code as you can...you will see your programming skills improve...just like sports....you need to exercise..you will also need to follow the foot steps of time-proven programmer's style...and the reason is they spent so much time building good style and testing logics...so do not re-invent the wheel...you can use a sorting technique that is alread existing instead of coming up with one which is at times time consuming and error-prone..this is also known as "Software Re-usage"...and you need to read to keep yourself updated of what is going on in the programming world.


JaveExpert :

Well I suppose I can only learn something from the expert...I am sure NOUR will be in agreement with me...that when the expert comes in we all have to take our hats off..and learn as much as we have room for...unless he(the expert) hops in with empty brain which regrettably might be the case now.

with regards to your advice to "NeedAdvice"..I am sorry to say this...but it appeared for once as though we had a case of...THE BLIND LEADING THE BLIND...no offence...but it is how I felt after I did full assessment of your advice..

Top of pagePrevious messageNext messageBottom of pageLink to this message  

Ali

Wednesday, March 07, 2001 - 06:18 am
Guys i need help with a function of my C assignment. our teacher want us to write a string-compare function like the one in string.h header file.please help i need it badly

Top of pagePrevious messageNext messageBottom of pageLink to this message  

NeedAdvice

Wednesday, March 07, 2001 - 06:33 am
Devil's

That was intresting, thank reallt your time and the Explanation. I will tray that Book aswell...but what I want know br...can I teach myself C programming?like Networking...becouse I am about to Finish my MCSE selfsudy...and I find it easy...so do you think you can Teach yourself any Programming? and Can you tel me how long it takes to Complate..e.g that Boog you sugges for me?I mean average...thanks again.

Top of pagePrevious messageNext messageBottom of pageLink to this message  

devils_love

Wednesday, March 07, 2001 - 08:10 am
The one that comes with the header file <string.h>....and the syntex of it is:

int strcmp(const char *s1, char *s2)

it takes two pointers to char or strings and returns these values :

0 ( Zero if the two strings are equal..like.."ali" & "ali":O

> 0 ( greater than zero if the first string is greater than the second one..like.."nour" & "ali":O

< 0 ( less than zero if the first one is less than the second one..like.."ali"


Now knowing what the string compare function does...all we need to do is code one...and test it..I have writen one for you..it is called ali_strcmp(char *str1, char *str2) here it is with the main function to test it.


#include <stdio.h>

int ali_strcmp(char *str1, char *str2)
{
int i=0;
int j=0;

while( (str1[i] & str2[j]) & !(str1[i] - str2[j]) )

{
i++;
j++;

}

return str1[i] - str2[j];

}


int main(void)
{
char *s1 = "devil";
char *s2 = "ali" ;

if ( ! ali_strcmp(s1, s2) )

printf ("%s == %s : Two strings are equal\n" , s1, s2);

else if (ali_strcmp(s1, s2) > 0 )
printf ("%s > %s : First string is greater than the second one\n" , s1, s2);

else
printf ("%s < %s : First string is less than the second one\n" , s1, s2);


return 0 ;
}


Now you need to know what the "ali_strcmp" function is doing...the function is passed two strings to compare..str1 & str2...the function declares two "ints" to iterate through the two strings..0..being the first character 1..being the second character...now let us come to the while loop...well the loop keeps going until such time that either of the two strings is null(null character '\0'..terminating letter for C strings) or the difference of the two characters is none zero value....so (str1[i] & str2[j] ) will resolve to "true" if both characters of the index at "i & j" are not "null"..and !(str1[i] - str2[j] ) means if the difference between the two characters is ZERO ..this will resolve to be true..if not it will be false an the loop will end...

Let me explain the difference...as you might now each character corresponds to an "ASCII" value...for example small "a" is equal to "97"..small "b" == "98..and so on...so say you have strings "devil" and "ali"...the difference of str1[0] - str2[0] will be translated to ..100 - 97 ..which is equal to "3" a number that is greater than zero...which means "devil" is greater than ali since it starts with "d" and "ali" starts with "a". and this will fail the loop thus exiting the loop...and the return value will be....3...if for example the the first string is..."ali" and the second one is "devil"...the function will return -3...which is less than zero...which means..."ali" is less than "devil"...and if you were using this for sorting it means...."ali" will come before "devil" like number "1"..will come before two."2"..consider

ali
devil
...
..

1
2

that is what less than means in this case....but what happens if the two strings are equal.like ..."ali" and "ali"..the loop will first compare the first characters in this case "a" and "a"...and the difference will obviously be zero..and then "i" and "j" are gonna be incremented...now the loop will compare "l" and "l"..still the difference is zero...and ultimately..they will be null..and the loop will fail..the return value will be the difference of the last two characters compared..which is in this case..."i" and "i"...

Note also I did not declare the function..because I defined and decalered the function over the main at the same time...so when the compiler comes..it already knows..the function...we also need <stdio.h> header file...to use printf(..) function

The main functions sends two strings to ali_strcmp functions and tests the return value and prints if the strings are equal or one is greater than the other..and so on..

Top of pagePrevious messageNext messageBottom of pageLink to this message  

devils_love.

Wednesday, March 07, 2001 - 08:22 am
NeedAdvice :

I do not want to under-estimate your ability of learning "C" by yourself...but you will need all the help you can get...if you are determined though...who knows...you might even invent a new language...hope the best for ya....


with regards to the faces in the previous comment..I did not intend them to appear..but it looks like the CGI that does this posting..translates the sequence of these two characters( '"' and ')' ) as a winking face...so you know...

Top of pagePrevious messageNext messageBottom of pageLink to this message  

Nour

Wednesday, March 07, 2001 - 08:23 am
Ali
it's good idea to go through all the difficulties to do the assignment on your own. that is the only way, you can learn. I will try to help you a bit.
When you want to compare to things(a,b), there is three possiblities
1)a=b
2)a>b
3)a<b
I will write a function which tests for (1).
and I will let you do a function which tests for all three cases and depending which one it's, it will return a value(e.g. if case1 return 0, if case2 return 1 if case3 return -1)

I will call my function "islamid".
"islamid" will return zero if the two strings are same, otherwise it return -1

here it's

int islamid(char*s1,char*s2)
{
int d1,d2; // d waxay u taagantahay dherer/dhirir
d1 = strlen(s1); // functionakaan wuxuu ku jiraa string.h
d2= strlen(s2);

if (d1!=d2) return -1 // waxba ha is daalin haddii aykala dheeryihiin

for(int i=0; i<d1; i++)
if(s1[i]!=s2[i]) return -1;


/*haddiba aan halkaa soo gaarno, labada xarig waa isla egyihiin*/

return 0;
}

Top of pagePrevious messageNext messageBottom of pageLink to this message  

java expert

Wednesday, March 07, 2001 - 08:26 am
needadvice
practice maks ne perfect, however practice by readinga book or playing around certain codes from the book as my friend suggest wont help ye.
when you want to practice , ye practice with the real stuff bro by compiling simple proven examples and fiddling with them,
Dont be discouraged, you can learn by your awn on your own with no need for a teacher bro, really i mean it if you are a smart enough.


ali
is dat an honest question, i am asking..lol
well it depends on what ye are comparing for example,,
public: static int Compare(
String* strX,
String* strY
);
well, this code simply compares the str X and Y..and doesnt do much really but on the other hand ye can modify it and do more than the simple function of comparison,

Top of pagePrevious messageNext messageBottom of pageLink to this message  

java expert

Wednesday, March 07, 2001 - 08:35 am
devils
what is this some sort of doom?
what do you mean by these bro?
you have a roblem here so try to correct them ,,

'( (str1[i] & str2[j]) & !(str1[i] - str2[j]) ) { i++'
at least that is how your arguments are formulated,,this really isnt a code that will run well, better correct it bro before you confuse ppl with this wrong example

Top of pagePrevious messageNext messageBottom of pageLink to this message  

devils_love

Wednesday, March 07, 2001 - 10:45 am
Ali

Just wanna make a tiny change ...I am used to using bitwise "AND" and I wrote down ( "&" ) instead of the logical AND( "&&" ) so I made quick fix to the function...PLEASE USE THIS VERSION.I did not change much except the bitwise "&" into logical "&&" ...though to my surprise the bitwise "&" was just fine working to some extent....



int ali_strcmp(char *str1, char *str2)
{
int i=0;
int j=0;

while( (str1[i] && str2[j]) && !(str1[i] - str2[j]) )

{
i++;
j++;

}

return str1[i] - str2[j];

}


This function will do all the three scenarios that nour talked about....perhaps I should have left you code it..but then we are here to help each other....

Top of pagePrevious messageNext messageBottom of pageLink to this message  

Nour

Wednesday, March 07, 2001 - 11:37 am
DL

I did not see your code when i was writing mine!!

Don't forget to decrement the counters(i,j) after the while loop. Otherwise, you will get the infamous "core dump" of C. by the time you finish your while loop you already pointing beyond the last character of (one or both) strings. If the the strings are equal, then str1[i]==str2[j]="\0"
in this case it will work but don't get deceived. It will not work if the two strings are not the same length.
all you have to do is just put
j--
i--
right after the while loop.

Boy!!. I was going to let Ali do some work

Top of pagePrevious messageNext messageBottom of pageLink to this message  

java expert

Wednesday, March 07, 2001 - 11:49 am
and what will this code accomplish?
for god's sake stop the nonsense, this is just education,,no one is pretending to outsmart ye but on the other hand the function ye are trying to cal doesnt exist as it is not defined, besides the braces are too numerous to use, what ever,anyway, the variables is ,,maxaan idhaahdaa,,
anyone well familiar with c++,please correct this guy, i dont want him to misunderstand me.

Top of pagePrevious messageNext messageBottom of pageLink to this message  

java expert

Wednesday, March 07, 2001 - 12:03 pm
http://www.cs.waikato.ac.nz/~nkanji/programming/examples/stringcompare.html

try to go to the above for further illustration of String-Compare,,there are many ways u can do depending on what u r trying to compare,,if u are comparing two values or two files or two characters according to their alphapetical precedence etc,
But all i can say is, Devils and Nour ye are really nuts walaahi. Walaalayaal serious ah ma tihiin,
besides i dont care Devils waxaad raadineyso but i am dead serious i dont like what you are posting here bro it makes no sense at all,
tell me
How do you define a simple strings for comparison,,?
i want to compare A and B, and i want my program to tell me which one is the first in the alphapetical precedence, while we know that A comes before B, write a simple program that does tht simple job..otherwise please rest your case and relax,and stop the unthinkable impossible totally undefined codes you are writing in this forums...

Top of pagePrevious messageNext messageBottom of pageLink to this message  

java expert

Wednesday, March 07, 2001 - 12:12 pm
well here is the problem

{

int ali_strcmp(char *str1, char *str2)
{
int i=0;
int j=0;

while( (str1[i] && str2[j]) && !(str1[i] - str2[j]) )

{
i++;
j++;

}

return str1[i] - str2[j];

}

that is your code Devils..
we all know that the while function is simple to understand and i am doimng all these for Ali to understand and to those programming hardcores,,
here Devils declared {{{while}}}function which is so confusing and is nothing more than a word in a plian space..
i am saying this because,,the{{while function }}goes something like this,,
{{while}} something is happening [[do}}this after the while function,,but here we have while ......

these comnfusing strings [[
while( (str1[i] && str2[j]) && !(str1[i] - str2[j]) )


then return,,this,,lol what a tragedy,,,indeed the whole thing is a mess...

while function is always followed by the logcal operators that define the result that is to follow the while function,,...
waryaada dee, maad qabataandee inankan yara qafiifey,,,walaal dee yara qabooji waa adiga dee devil and nour,,same individual inaad tihiin dee waa cadahay,,..

Top of pagePrevious messageNext messageBottom of pageLink to this message  

Alipapa

Wednesday, March 07, 2001 - 12:37 pm
java expert,

I really duno what you are trying to accomplish here. Deveil's love might not be talented or sort of guru programmer but truely he did answer what you are asking. I mean he already told you that in ASCII code A comes first an B comes second.He already told you that "a" lower case is 97 and "b" is 98. And all you have to do is compare them with "if statement" and return true or false.

And in case you are asking "A" and "B" upper cases, i am not sure but i guess their ASCII values are 64 and 65 respectively.

So now tell us why you are making all this fuse out of nothing. If i am missing info or misunderstand you let me know . Otherwise keep the peace and those guys hell alone. And i case you don't know Devil's Love is here to prove something. He wants to show off his two cents to his newly cyber girl friend--Hibo. How little you man understand!!!. Let this poor guy play his game . Will you? ahhahhaa


Alipapa

Top of pagePrevious messageNext messageBottom of pageLink to this message  

Nour

Wednesday, March 07, 2001 - 01:00 pm
Can somebody, please, help me understand what Javaexpert is talking about?.
wow! what an expert we have!!
I bet he can not even answer a grade eight question.
Hey javaExpert can you, please tell me how many different characters can be reprensented in ASCII?. How about Unicode?
if you give number, tell me how you get it

when you answer those grade eight questions. I will talk to you about "some programming for dummies"
thank you

Top of pagePrevious messageNext messageBottom of pageLink to this message  

java expert

Wednesday, March 07, 2001 - 01:37 pm
Alipapa,,lol i rest my case. Thx Alipapa for making me understand the behind scenes, lol..i rest my case 4 good...

Top of pagePrevious messageNext messageBottom of pageLink to this message  

java expert

Saturday, March 10, 2001 - 09:31 pm
hey where are ma ppl what happened?
devil please dont rest your case it is good bro, ye will learn the art, just keep doing what ye are doing, in otrher words lol, i wil train ye well really, wanna learn java?

Feel like posting? Pleaase click here for the list of current forums.