Monday, July 27, 2009

Core Java Doubts?

1. what is the impact of private constructor?


2. what r static initializers?


3. can we assign parent objects to child objects?


4. what r singleton classes?


5. can applets be embedded in any graphical java application?


6. in use of applets having main() ?


7. how is the template concept of C++ implemented in Java?


8. can main() have only void as its return type?





plz answer them with the ques nos.

Core Java Doubts?
1. Instances of the class with only private constructors can only be created from within that class itself.





2. Static initializer is a piece of code enclosed in static { } that is executed when the class is loaded (referenced) for the first time.





3. No, you can't assign parent objects to child objects. Parent objects are not compatible with child objects and may not have all required methods/variables.





4. Singleton class is the class that only allows existense of one and only instance of itself.





5. Applets can be embedded into web browser and viewed in applet viewer - yes. Any graphical Java application - no.





6. Didn't get this question. Applets don't normally have main() method - they have init() method which performs similar function.





7. Semantics of templates in Java are almost the same as as in C++. Templates are classes that know how to deal with other classes, without knowing their specifics. Templates in Java are mostly intended to avoid clumsiness of typecasts.





8. Yes, main() can only be void if you want it to be program's entry point. If you make it not void, Java just won't recognize it as entry point function.
Reply:adding to the above answer:





1. See this for explanation


http://www.javapractices.com/topic/Topic...





6. You can have a main() method in an applet. It would imply that you plan to run your program an application as well.





7. It is implemented via "generics" introduced with Java 5


http://java.sun.com/j2se/1.5/pdf/generic...

land survey

More Java help please.?

Account


-balance: double


+getBalance(): double


+charge(sale: double): void


+makePayment(payment: double) : void


+printStatement(): void


+Account()





a. Use the class above to write a few lines of code that will create a new


account, with a zero balance (this is what the default constructor will do).


b. Charge three sales to your account created in a) for $25.13, $43.98, and


$5.00.


c. Make a $50 payment to your account in a).


d. Print out a statement for your account in a) if the account has a balance of


over $1.

More Java help please.?
do it yourself. And shame on people who just post code for people who want someone else to do their homework. Show some honor.
Reply:OK, I'll do it for you because I don't have anything better to do, but I want you to read and understand the code:





class Account


{


double balance;


double getBalance()


{


return balance;


}


void charge (double sale)


{


balance=balance+sale;


}


void makePayment(double payment)


{


balance=balance-payment;


}


void printStatement()


{


System.out.println("STATEMENT:


\n*balance="+


balance+"\n---------------");


}


Account()


{


balance=0;


}


}





public class BalanceAccount


{


public static void main(String [] args)


{


Account Acc=new Account();


Acc.charge(25.13);


Acc.charge(43.98);


Acc.charge( 5.00);


Acc.makePayment(50);


if(Acc.getBalance()%26gt;1)


Acc.printStatement();


else


System.out.println("


balance%26lt;=1");


}


}
Reply:first one's free... all orders for homework help are $39.99 per answer...





Try reading through the book some, might help understand basics of Java like: void, constructor or even double. Then doing it yourself would be quick n easy.


Any pro java programmer i need your help?

why when i add private int yearpublished; my program has an error why it's, it has no error when i add a new String data type the problem is when i add a int data type








// to run this program: C%26gt;java libmainsys


//////////////////////////////////////...





/////////


class libary


{


private String booktitle;


private String bookauthor;


private String publisher;


private int yearpublished;


private int nofcop;





public libary(String title, String author, String





pub, int yrpub, int nfcp)


{ // constructor


booktitle = title;


bookauthor = author;


publisher = pub;


yearpublished = yrpub


nofcop = nfcp;


}





public void displaylibary()


{


System.out.print(" Book Title: " + booktitle);


System.out.print(", Book Author: " + bookauthor);


System.out.print(", Book Publisher: " + publisher);


System.out.print(", Year Published: " +





yearpublish);





System.out.println(",No Of Copies : " + nofcop);


}

Any pro java programmer i need your help?
Your problem is not on the "int" type but on the "insert" parameter to your array!


You gave there insert(String, String, String, String , int) but your class has constructor supports only (String, String, String, int, int)... So the last "String" argument on your insert should be without quotes (an "int" value).





Edit:





for example:


arr.insert("Web_Publishing", "Audrey_Cynthia", "Surg", "193", 2001);





should be





arr.insert("Web_Publishing", "Audrey_Cynthia", "Surg", 193, 2001);


this is according to the definition of your insert method. I hope you see the diference between the 2 examples.


Why am I getting this class error in Flash when including "NetServices.as"?

I am working on a Flash Remoting project (Flash 8, btw). When I check for script errors, the output panel, I get this response:





"**Error** C:\CFusionMX7\wwwroot\Configuration\NetS... Line 22: Classes may only be defined in external ActionScript 2.0 class scripts.


class mx.remoting.NetServices extends Object "





I thought this NetServices file WAS an external class constructor...but I'm newbie and obviously am missing something here. Probably better to post this on a Flash forum, which I think I'll do, but any help here would be appreciated.

Why am I getting this class error in Flash when including "NetServices.as"?
The code fragment:


"class mx.remoting.NetServices extends Object "


declares a new class which, as far as I can understand, is not what you want to do because NetServices already exists as a compiled object in the Flash library.





If you want to use this class what you need to do is import it by using the following code:





import mx.remoting.NetServices;





then you can create an instance of the class by typing something like:





var myServices:NetServices = new Netservices();





The variable myServices is then an "Instance" of the class Netservices and you can then use it whatever you want to do with this Class





Please be advised this is general advise and I do not know this particular Class. this is just the way classes and OOP works in Flash.





I hope this helps you
Reply:This might help:





Runtime Errors and others:


http://support.microsoft.com/default.asp...





Good Luck


Complicated java programming need help badly?

1. (5)Create a class called Grocery that has three private attributes price (double), quantity(int) and catcode (string).


2. (5)Create a constructor for the abovementioned class that initializes the data members to zero values, and catcode to “N”


3. (30)Create accessor and mutator methods for the class. Make sure that


a. price attribute can not be assigned a negative value. In case of such an error, the default value is 0.00


b. quantity attribute can not be assigned a negative value. In case of such an error, the default value is 0


c. catcode attribute can not be assigned a value other than “N”,”F”,”Z”. In case of such an error, the default value is “N”


4. (5)Create a method called inputprice() that receives no parameters and returns no value. Using JOptionPane class it asks the user to input a price and uses setprice() method to set the value for the data member price.





all i need help with is number 4





import javax.swing.JOptionPane;


public class grocery


{ private....

Complicated java programming need help badly?
public void inputprice()


{


double price;


string input;


input = JOptionPane.showInputDialog("Enter the price:");


price=Double.parseDouble(input);


setprice(price);


}





I think that should be it

survey software

1. Specify, design, and implement a class that can be used in a program that simulates a combination lock.?

The lock has a circular knob, with the numbers 0 through 39 marked on the edge, and it has a three-number combination, which we’ll call x , y, z. To open the lock, you must turn the knob clockwise at least one entire revolution, stopping with x at the top; then turn the knob counter-clockwise, stopping the second time that y appears on top; finally turn the knob clockwise again, stopping the next time that z appears at the top. At this point, you may open the lock.


Your Lock class should have a constructor that initializes the three-number combination. Also provide methods:


a. To alter the lock’s combination to a new three-number combination.


b. To turn the knob in a given direction until a specified number appears at the top.


c. To close the lock.


d. To attempt to open the lock.


e. To inquire the status of the lock (open or shut).


f. To tell what number is currently at the top.

1. Specify, design, and implement a class that can be used in a program that simulates a combination lock.?
Take a look here at wikipedia. So you can do your homework:








http://en.wikipedia.org/wiki/Combination...


1. Specify, design, and implement a class that can be used in a program that simulates a combination lock.?

The lock has a circular knob, with the numbers 0 through 39 marked on the edge, and it has a three-number combination, which we’ll call x , y, z. To open the lock, you must turn the knob clockwise at least one entire revolution, stopping with x at the top; then turn the knob counter-clockwise, stopping the second time that y appears on top; finally turn the knob clockwise again, stopping the next time that z appears at the top. At this point, you may open the lock.


Your Lock class should have a constructor that initializes the three-number combination. Also provide methods:


a. To alter the lock’s combination to a new three-number combination.


b. To turn the knob in a given direction until a specified number appears at the top.


c. To close the lock.


d. To attempt to open the lock.


e. To inquire the status of the lock (open or shut).


f. To tell what number is currently at the top.

1. Specify, design, and implement a class that can be used in a program that simulates a combination lock.?
Take a look here at wikipedia. So you can do your homework:








http://en.wikipedia.org/wiki/Combination...