|
Hello guys!
I`m writing on a programming assignment and I`ve reached this question:
Describe the technique of layering I/O streams. Give some code for a client to show how this technique could be used to read doubles from files that arrive over a TCP/IP network in compressed form.
Even though I have some years of programming (not only Java), I'm not happy with my answer describing the layering.
As for the second part of the question, I don`t know how to read compressed data coming from Sockets...
Could you please help me with some insights and links?
Many thanks!
Shpid3r
|
|
|
|
|
|
Is there any automated way of doing indentation in my lengthy code?? i mean is there any option available in eclipse or either in Netbeans??
|
|
|
|
|
aesthetic.crazy wrote: i mean is there any option available in eclipse
In Eclipse there is an awesome feature that format your code properly automatically (indentation, position of brackets, spacing, ...). Without having anything selected in your editor, simply press ctrl + shift + F. If you have a piece of code selected, this will format only the selection.
|
|
|
|
|
Both NetBeans and Eclipse have this feature. It's not hard to find in either IDE, a few seconds browsing the menu options will reveal its location.
If you want to do this outside your IDE, Jalopy[^] is very good.
|
|
|
|
|
you can refactor your code in eclipse with a right click. There you can extract a interface or superclass, extract local variables and stuff like that.
But a good design is still most efficient...
regards
Torsten
I never finish anyth...
|
|
|
|
|
If in eclipse use the Format Code if u want to reformat the code writing , and if u only want to align the braces , simply select the piece u want to indent and select and press CTRL + I to indent the code.
|
|
|
|
|
How to convert ResultSet to Integer?
i do it this way however i encountered errors.
codes as follows:
rs = stmt.executeQuery("Select count(1) from INCIDENTDATA where INCIDENTID = 10");
Integer id = rs.getInt(1);
if( id == 0){
.
.
.
}
When i do a debug errors i encounted:
1. "id" is not a known variable in the current context.;
2. "rs" is not a known variable in the current context.;
http://img841.imageshack.us/img841/1965/exeerror.png[^]
needing help.
When i execute the SQL this is the screen shot : http://img502.imageshack.us/img502/8532/executey.png[^]
how do i get the value 0 so as to compare it if it is 0 then i will add the value 10 into the database?
modified on Sunday, January 16, 2011 11:25 PM
|
|
|
|
|
I have made changes to the codes. Right now i dont face any error but however i dont see the value that i have added, being added to the table.
public String add_btn_action() throws SQLException {
ResultSet rs = null;
Statement stmt = null;
Integer id;
String dbURL = "....";
String incidentId = (String) getIncidentidtxt().getValue();
Integer incidentIntId = Integer.parseInt(incidentId);
String incidentName = (String) getIncidentnametxt().getValue();
Connection con = DriverManager.getConnection(dbURL);
try{
stmt = con.createStatement();
rs = stmt.executeQuery("Select COUNT(1) from INCIDENTDATA where INCIDENTID = "+incidentIntId+"");
while(rs.next()){
id = rs.getInt(1);
if( id == 0){
getSessionBean1().updateIncident(incidentIntId, incidentName);
incidentdataDataProvider.refresh();
}
else{
Integer newIncidentID = incidentIntId + 1;
getSessionBean1().updateIncident(newIncidentID, incidentName);
instancedataDataProvider.refresh();
}
}
}
catch(Exception e){
e.getMessage();
}
return null;
}
Needing help..
|
|
|
|
|
|
I wish I had £1 for every time I suggested the OP spend some time studying this subject.
I must get a clever new signature for 2011.
|
|
|
|
|
pancakeleh wrote: Right now i dont face any error but however i dont see the value that i have added, being added to the table.
You would of course need to write code that does in fact do an update to the table.
|
|
|
|
|
I have written a method in sessionBean named updateIncident for adding the values to the database.
the codes as follows:
public void updateIncident(Integer incidentIDName, String incidentNameName){
incidentdataDataProvider.refresh();
RowKey rkUpdate = incidentedataDataProvider.appendRow();
incidentdataDataProvider.setCursorRow(rkUpdate);
incidentdataDataProvider.setValue("INCIDENTDATA.INCIDENTID", incidentIDName);
incidentdataDataProvider.setValue ("INCIDENTDATA.INCIDENTNAME", incidentNameName);
incidentdataDataProvider.refresh();
}
|
|
|
|
|
thanks but where should u put all this code(mean to put it inside the try and catch or where...)
|
|
|
|
|
Please tell me some details about static class/methode , i search for it on internet in forms etc but i didn't yet setisfied and still unable to explain it in confident and clear way
the most common questions about static class/methode in my mind are,
- why use static class
My Knowledge >>
They provide access to class static methode directly without creating its instance.
they have same instance in memory .. means every use/access to this methode can have changes effect for every one.
ANY OTHER BENEFIT AND PURPOSE !!
Also please tell me clearly the basic purpose of static class/method ... in interviews they always as to me about it and i always failed to answer clearly to him
|
|
|
|
|
Static can be used in various ways.
Anything that needs to be shared across all instances of a class can either be made static - easy - or passed around in another object - hard.
Certain design patterns - I'm thinking the singleton here - rely on static methods to encapsulate class functionality and control behaviour.
Any method that does not (or must not) use instance data should be static to prevent it accessing the instance data.
There is no need to instantiate an object to call a static method - say a helper class providing oft called methods - have a look at the static methods on String .
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
|
|
|
|
|
Thanks for your help .... Thanks a lot
|
|
|
|
|
Have a look at the Java Tutorials[^], they contain an excellent introduction to all aspects of the language.
I must get a clever new signature for 2011.
|
|
|
|
|
Static methods are frequently used in several design patterns (Singleton, DataFactory...) but, to give you something very simple and easy to understand, think about Math class. How do yo use it?
a = Math.abs(n);
a = Math.floor(n);
a = Math.sqrt(n);
...
So, as you can see, we don't have to create an instance of Math class, becouse we just use its static methods. In these cases, we say the Math class only offers services, and that is why all of its methods are static.
|
|
|
|
|
Thanks for your help .... Thanks a lot
|
|
|
|
|
static can be declared for variables and methods. When instance variables declared as static then its called class variables. Local variable can not be static.Each and every object share the same variables. In the sense when one object modify the variable the result will be reflected in all objects. With out creating object static variable methods can be accessed.Before object creation static variables initialized or instantiated.
|
|
|
|
|
How i campare two objects, such that if i have class(given below) and i want to compare there two different instances then how ??
class MyNode {
MyNode left;
MyNode right;
}
Is there any possiblity to do that --->
public boolean MyFunction(MyNode toSearch, MyNode parentNode) {
MyNode currentNode = parentNode;
while(currentNode != toSearch) {
return true;
}
else {
currentNode = currentNode.left;
}
}
return false;
|
|
|
|
|
You should implement your own Equals() method in your class and use that to test for equality. Using the == and != operators will not give the result that you are looking for.
I must get a clever new signature for 2011.
|
|
|
|
|
but can you please give some guide line to do this ... such that one way in my mind is like this that i put an Interger property in class that are then use to identify different instanceof class .. such that 1 for 1st instance/node then 2 for 2nd and so on and then compare some thing like this NodeA.IntegerIdentifier == NodeB.IntegerIdentifier but i doesn't satisfy with this idea as it is not apply in real senario as because in programming we should try to make solution in some thing like general awy.
So is there any idea aur suggestion for me that how i achieve this equality problem/isue what ever
|
|
|
|
|
See here[^] for lots of information on object equality.
I must get a clever new signature for 2011.
|
|
|
|