Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!

Shyam Prasad Murarka

Ranch Hand
+ Follow
since May 02, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
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 Shyam Prasad Murarka

Dear Rancher,
Thank you very much for the links. You guessed it right, I was looking for MP3 tags itself. But I did not want third-party API's. Instead I wanted to develop my own library. Luckily I followed a link to www.id3.org where I can learn about the tagging in detail.

I am guessing I will have to use the Java Sound API for this. Isn't it?
10 years ago
Dear Ranchers,
I want to make a Media Organizer which allows a user to edit his music file details as one of the features.
For that I need to know how to access those details (like Title, Artist, Genre).
I went through Java Media Framework and seriously all I understood was that it provides a player for playing media files.
Is JMF the package that will provide me with classes and methods to access those details?
If not, then which is it?
10 years ago
Hey Joanne Neal, thanks for the link. God, I never knew that such a racket was in motion. But, I guess our website would be too small to be noticed. It will be mostly only for the college people and that too it will be hosted for a short time period. Hopefully no problems crop up or I shall see my photo in BBC News (which would be awesome)


Originally posted by Ulf Dittmer
3) PHP is not a client-side technology - it's server-side. Did he mean that you should program the client in HTML/JavaScript (possibly generated by PHP) instead of an applet? That's certainly a possibility. In that case, the communication to the server would probably be through AJAX, in particular the JavaScript XmlHttpRequest object.



Yes, I had meant using HTML/Javascript for client-side whereas PHP as the server-side processor.
But, will it be feasible to store information received from client in a text file using PHP and having Java to regularly scan that file for updated status of the game? Is there any other workaround? Like somehow letting Java know each time new information comes in through PHP?

Thanks for the information.
10 years ago
Hi Ranchers,
My seniors have assigned me the task of making a Scrabble game for our cultural fest website. They want it as a Java applet.
I am thinking of making it using Sockets. I have previously made a Chat application based on Sockets. I also tested it on LAN and it seems to give no problems. I have never tested it across a Net connection.
I have very recently come to know that Sockets will NOT work across Net because of some direct connection or something. I am not too sure on that concept. Do you guys have any idea what that was supposed to mean?
Also, my seniors told me that all ports except 8080 in our college were blocked for communication.
So imagine a scenario where I have made the game and (just for now) its working on Sockets. Can I make the Java Scrabble Server listen on port 8080 provided our normal college Net traffic also goes through that port? Or is only application (in this case the Net connection) allowed to sit on a particular port?

ALternatively, I was thinking of using RMI. Will that be possible? I am kind of rusty on RMI right now, but do we have to provide IP Address and port number when working through RMI also?

Lastly, my senior suggested that I use PHP for client side and transfer the data into the server database. And the Java Scrabble Server will have to perform routine checks on the database for further processing. Will that not result in a time-lag? Is it a good idea?

I may not have been clear on my Socket problem, so if anyone requires further explanation, do let me know.
10 years ago
Dear VenkataGuru Mitta,
Please do refer to this topic: multiple interface.
It discusses on the same topic.
11 years ago
Dear kirba devi,
Do you mean you want to obtain the path ("D:/Images/sd.jpg") for the file and then manipulate that file path? You can make use of tons of methods available in File class. Check out the Java API for more details.
11 years ago
Dear Bianchi Francesco,

But doesn't the default scope (i.e. friendly) provide the same visibility (i.e. visible in same package and subclasses)?

Edited Later: I realized later that "protected" offers you visibility outside package IF the subclass exists outside package, something that the default scope wouldn't allow.
[ July 11, 2007: Message edited by: Shyam Prasad Murarka ]
11 years ago
Dear vijaychandran rajagopalan,

You expect the no-arg T() method to automatically execute when you create a new object. But that will NOT happen! This is because the different methods that you have declared are NOT constructors! A constructor does NOT have any return type. NOT EVEN VOID!
So it should be this way:


Notice that I have also removed the "void" from each method signature.

Whereas, in the second case, you are simply calling the method.
[ July 11, 2007: Message edited by: Shyam Prasad Murarka ]
11 years ago
Dear Ganesh Kumar,
Let's say you created an abstract class called Shape.

AND, among many other methods that you have in this Shape class is a method called intersects() which returns a boolean.
This method checks whether a Shape object touches another Shape object.

Now, you could do it this way:


Basically, you would be overloading the intersects method to perform operations for different shapes.

You create subclasses such as Rectangle, Circle, etc.

You now publish your very own Shape API into this world.

Now, a person from Brazil wants to extend your Shape class and create HIS own arbitrary shape. He also wants to use your intersects() method to check whether HIS shape object touches a Rectangle, Circle, etc.

But, unfortunately, he can't! Because you haven't specified any overloaded method in the abstract class to support HIS shape. And that person is obviously NOT allowed to change your Shape class.

So, how do you work around this?
Simple, by generalizing the parameter accepted by intersects() method to Shape type.



So, now any person from anywhere in this world could use HIS own shape and use your intersects() method simply by extending your Shape class.

So, that's the power you get by doing Shape rect = new Rectangle();
Or, as in your case, ganesh gan = new shyam();


By Ganesh Kumar,
If ganesh is super class and shyam is sub class.Can it access methods of shyam?



In the above case, ganesh gan = new shyam(), you CAN access methods of shyam only if you explicitly downcast "gan" variable.

So, in case of
ganesh gan = new shyam()
and
ganesh gan = new ganesh(),
the difference lies in how you use those variables.
Upcasting (ganesh gan = new shyam()) can provide you a lot of power as shown above.

Regarding your last doubt, tell me, what do you mean by int i?
The same meaning holds true for ganesh gan!
It means "i" is of type int and "gan" is of type ganesh.
11 years ago
Dear Ganesh,


Compiler says f() cannot be resolved.



That's because "h" is a variable of type "go" and the compiler checks for the f() method in class "go" and then it proceeds to the super classes. It DOES not check in the subclasses of "go".
To access the methods of class "come", you need to explicitly downcast "h" object into type "come" and then use the f()method, like done below:


But, you HAVE to be sure that "h" was originally created either with:
  • class "come" or
  • any subclass of "come"


  • Otherwise you will get ClassCastException.
    11 years ago
    Dear Ganesh Kumar,

    Taking your code from this point:


  • The first line creates an object of type "go" and THAT object is referenced by the variable "g".
  • Another object is created of type "come" and THIS object is referenced by the variable "c".
  • Now, remember in first step, the variable "g" was pointing to an object of type "go", BUT in this step we "tell" "g" to stop referring to that object and start referring to the object that "c" is referring to.So, after this step, both the variables, "g" and "c", refer to the SAME object.
  • In the last line, we create another object of type "come", and this object is referred to a variable called "h", BUT this variable "h" is of type "go", WHICH is allowed, since a "come" object IS-A "go" object.

  • Here, you also see "upcasting" taking place, where a more generalized type refers to a more specific type (down the inheritance tree).
    What's the use of upcasting? Read on...



    I think you are trying to understand the power of inheritance. If you are, then it would be much better if you tried doing it with day-to-day examples such as inheritance in the case of Animals and Shapes. It becomes really confusing with weird examples such as "go" and "come"!
    Now, consider you have a class called Person that has a method called talk().


    Now, we make classes called "IndianPerson" and "AfricanPerson" extend Person.



    Now, lets create a program that can show our inheritance at work:


    Have a look at the output.

    You will notice that even though the array is of type Person, the compiler knows(you'll understand later as to how it knows) which type it actually belongs to! That is a small power of inheritance.
    Explore this mechanism to create a hierarchy of Shapes (such as Circle, Rectangle, Triangle), which will have a calculateArea() method.

    Now, you can use "upcasting" to store more generalized types.

    Ok, I agree this post may be a lot confusing and off topic, but you should first try understanding inheritance with proper examples.
    11 years ago
    Dear Ganesh Kumar,
    11 years ago
    Dear Reader,
    Can you post what you have written till now? We can guide you from there on.
    In general, to navigate a two-dimensional array, you need two nested loops, such as this:


    For 'n' depth multi-dimensional array, you need 'n' nested loops.
    Will it be better to use recursion?
    11 years ago
    Dear Ganesh Kumar,
    Taking your code from this point:


    Now class A has these variables: i, j, k
    class B has this variable: k

    Lets break down the program into simple steps:
  • When you call sub.i=82, the compiler checks for a variable i in class B, it does not find any! So it travels one step higher in inheritance tree to class A and finds the variable i, so it assigns the value 82 to that variable.
  • Same process takes place as above for the statement sub.j=32
  • Now when it encounters sub.k =10, the compiler finds k in class B itself so value of k is assigned there. REMEMBER THIS STEP!!!
  • When it reached sub.showij(), the compiler checks for this method, does not find any, so it proceeds to class A. It finds the method there.

  • Now pay close attention, this is the important part. The showij() method USES variables found in class A, and does NOT refer to variables found in the subclass!
    Now, if you see the third step again, you will notice that the compiler assigned the value of 10 to variable k of class B and NOT class A. So, by default, the value of k in class A is initialized to 0 and that is what you get in your output.
  • But, if you call sub.showk() method, then the compiler uses the k variable of class B.


  • [ July 09, 2007: Message edited by: Shyam Prasad Murarka ]
    11 years ago
    Dear Readers,
    What I had meant was that if in my implementation of the Sunali class I had changed the return type to void then the compiler would complain that I had not satisfied the Programmer interface.
    Anyway methods are not differentiated by their return type, which I had overlooked.
    11 years ago