~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Mentioning Emacs without mentioning Vim? Surely the world must be coming to an end. ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I don't think there is a clean way of doing this in RMI given RMI doesn't offer an appropriate level of "socket" abstraction for this sort of stuff. Your best bet would be to pass a "callback handler" when "registering" or "joining" the chat. When the server wants to kick a client, it will just use the callback handler for that client (maybe stored in a Map at the server, name -> callback handler pair) to invoke the "kick" method. This kick() method will then be called in the "client JVM". In that method, you can "NULL" out the reference for the chat server.

Your client now no longer has the reference to the server and will have to make another call to "join" the chat. Just make sure you also call System.gc() and System.runFinalization() to ensure that the distributed garbage collector (DGC) kicks in and performs the necessary cleanup.

Some sample code:

public interface CommandHandler extends Remote {

    void kick() throws RemoteException;

}

public class CommandHandlerImpl extends UnicastremoteObject implements CommandHandler {

    private final Client client;

    public CommandHandlerImpl(Client client) {
        this.client = client;
    }

    public void kick() throws RemoteException {
        this.client.chatService = null;
        System.gc();
        System.runFinalization();
        System.out.println("You were kicked from the server, please reconnect!");
        
        // update UI by clearing out all text boxes, list boxes etc. so that the user gets
        // the impression that he was "actually" kicked out.
    }

}

// Your main application class which has the chat server reference and …
Ezzaral commented: Nice solution. +16
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I'm not sure what's the confusion here:

// add same elements twice; should be added only once
set.add(i1); 
set.add(i1);

// add new element; size is now 2
set.add(i2);

// remove added element, size is now 1
set.remove(i2);

// remove a non-existent element, shouldn't affect set
// size is still 1

// this part performs auto-boxing i.e. i1 now points to a new Integer object 
// having value 47
i1 = 47; 
set.remove(i1);
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I posted a sample code. My point was that you just need to make sure you are passing a type parameter when creating JComboBox and you should be good to go. Something like:

JComboBox<String> comboCity = new JComboBox<>(temp);
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

my part of code give me message to recompile with -Xlint:unchecked
How to fix this code so the message gone

JComboBox was made a generic type in Java 7 so creating a new JComboBox without supplying the type parameters would result in the usual "unsafe" warning. The solution here would be to specify the type parameter when creating the combo box, something like:

import javax.swing.*;
public class Test {

    public static void main(final String[] args) {
        final String[] strs = { "a", "b", "c" };
        final JComboBox<String> cbox = new JComboBox<>(strs);
    }

}
mKorbel commented: Object not String +10
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Ok thanks and happy new year.
when i said "when i'll master them" i meant when i'll master the core language.
I wanna develop programs that can connect to the internet, ping, scan network, etc.
So which language is most used for these kind of stuff ??
thanks again

The general rule of the thumb is to have knowledge of:

  1. A language close to the metal and generates fast and native code. C or C++ are good contenders for this category.
  2. A language which can be used to execute quick n dirty tasks and prototyping. Python, Ruby or Perl fit nicely in this category
  3. A language which can be easily used to put up a web application without much fuss. Again, Python and Ruby are good contenders for this category.
  4. A language which has awesome commercial support, public following and guarantees job security. Java and C# along with their frameworks/libraries are good contenders for this category.
  5. Knowledge of the "shell" for the OS you work on. Shell scripting on *nix and Powershell for windows (or bat scripts if you are brave enough) fall in this category.

After that, feel free to learn any more languages which you learn to broaden the scope of your skills and knowledge.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I had a look at this thread and it seems that you don't need entire Access suite installed just for using MS Access. You might want to try the links mentioned in the thread.

BTW, any reason you are stuck with Access? Is there any reason you can't use a pure Java database like H2 or HSQLDB or Derby?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes, it's a scam/spam message. I have banned the member in consideration (even I was one of those members who received the PM) for trying to scam/spam via PM so it should be all good now.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I've just learned that Java's 'protected' access specifier has a different effect than that in C++. So is there a way to make a member of a base class visible to its inheritors but not globally?

Assuming by globally you mean "other classes in the same package", then no, there is no way to get around this behaviour. Is there any specific problem arising from this that you are trying to solve?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

That's a problem because when compiling for 1.4 target VM, the compiler doesn't know about var args. The solution is to change the compliance to at least 1.5 (1.6 would be recommended). I would suggest to change the workspace compliance level and make sure you don't override workspace specific compliance when creating a new project.

In Eclipse go to: Window -> Preferences -> Java -> Compiler -> JDK Compliance -> Change drop down to 1.6 and check the 'Use default compliance settings'.

For your project, right click -> properties -> Java Compiler -> uncheck enable project specific settings -> OK

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Is there anything wrong with this? Thanks.

No, looks good. Do you have multiple Java versions installed? If yes, can you check which one is used by Eclipse? Also, can you check that the compiler compliance level for your project in Redhat Eclipse is >= 1.5 by going to "right click project -> properties -> java compiler"? Also, can you try compiling the class mentioned in your first post using the command line "javac" rather than using Eclipse?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Variable arity (var-args) are a Java 5+ feature but is implemented under the hood as an array. If you have a Java 1.4 compiler trying to compile the code calling a var args method, there is a possibility of getting this error. Are you sure the setup on CentOS (both Eclipse and Java installation) is using Java 5+ ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

There is one more change which I missed out in my previous post. Also, make sure that you use a UTF-8 aware output stream for writing out the arabic text. E.g.

final PrintStream out = new PrintStream(System.out, true, "UTF-8");
out.printf("Welcome to the Grade Book Dr. Sherif!  for \n%s!\n", courseName);

Windows is bit quirky when it comes to encoding. These changes pretty much work on Ubuntu but I'm not sure if they would on Windows (which doesn't have an option for setting a global encoding).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> I don't know the types of the keys or values

I'm not sure I understand. For a newly created raw map using reflection, there is no way of "retrieving" the type information without querying the actual contents (unless using type tokens). Something like:

Map<Object, Object> m = (Map<Object, Object>) map;
for (Map.Entry<Object, Object> e : m.entrySet()) {
    Object k = e.getKey();
    Object v = e.getValue();
    System.out.println("Type of key: " + k.getClass().getName());
    System.out.println("Type of value: " + v.getClass().getName());
}

It would be easier to help you out if you can hack together a small compilable test program which demonstrates the problem you are facing.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

AFAICT, if an explicit charset is not provided, Scanner class uses the default Charset when parsing the input stream. Two things you can try out:

  1. Add a SOP to the start of your program to print the default charset being used by adding the line: ` System.out.println(Charset.defaultCharset().name()) ` at the start of your program
  2. Change Scanner constructor to take in a explicit character set i.e. ` new Scanner(System.in, "UTF-8") `

If it still doesn't work, post a screenshot of how the session looks like (after hiding personal information of course).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This problem can be easily solved if you are ready to pass around "type" tokens i.e. Class instances to methods. Let's say you want to create a generic "doSomething" method as mentioned in your first post. The generic version would look something along the lines of:

public <T> T doSomething(Object obj, Class<T> klass) {
    T someObject = klass.cast(map.get(obj));
    if(someObject == null) throw new SomeException();
    return someObject;
}

Also, when you instantiate any "generic" object using reflection, all the bets are off (given that you have used introspection and not regular constructs which are subject to compile time checks) and hence it might be a bit misleading to say that you created a "Map<String, String>" because under the hood, it's just a Map instance (given that generics are implemented using type erasure).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

How do strings work? In C we must declare the size of a char array to represent a "string".
But in java we do not allocate memory for the size of a string. So how does the string work?
Is there a pre deterimed size assigned to strings from the compiler or what?

When it comes to Java, String type is a bit special. Even though it is a "proper" reference type like other classes out there, compiler offers additional support when it comes to handling strings.

For e.g. Java doesn't have operator overloading but permits "+" operator for String object concatenation (which decomposes to StringBuilder operations under the hood but still). It's also possible to create String objects without explicitly calling any static method or constructor i.e. compiler has built-in support for "string literals".

// "String" instance creation without new at compiler level
final String first = "something";
// concatenation; important: strings are immutable and hence a new "copy" is
// created for the result string instead of modifying the parameters to +
final String newString = first + " to be proud of";

Regarding the question about capacity, almost all regular methods for creating strings (apart from the ones mentioned above) automatically account for capacity, which is inferred from the passed in arguments. Let's assume you want to create a UTF-8 String instance from a sequence of bytes read from a Socket. The code would look like:

final byte[] bytes = readBytesFromSocket();
final …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Which specific part do you have trouble understanding?

You just need to put the MySQL JDBC driver in your classpath, remove `Class.forName()` from your code and it should automatically work. Nothing more needed from your side.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

BTW, just FYI, you can run Java in any compatibility mode. So, if you have JDK 6 and want to run it as 1.4, you can do "java -version:1.4 -version" and it'll print 1.4. Similarly, when starting your server, if you have access to the .bat or .sh file which starts the server, you can add a "-version:1.4" to it and it'll start up in 1.4 compatibility mode. What is the command line you are using to start the server?

serdas commented: you are great thank you for not giving up on me +3
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I meant replace "yum install glibc.i586 glibc-devel.i586" with "yum install glibc.i686 glibc-devel.i686" and try again.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm...you seem to be using a pretty recent version of CentOS which might explain missing i586 packages. Can you try installing i686 packages for glibc and then run the installer?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

OK, bit of progres. It seems that you can only use 32 bit libraries on 64 bit OS if you have the required 32 bit dependent libraries installed. The details for that are pretty much specific to the distro (CentOS in your case) so you would be better off asking on the official CentOS forums. In case you don't mind an "experimental" solution, try out the command mentioned here?

yum install glibc.i586 glibc-devel.i586
yum install libX*
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

AFAIK, 32 bit executable should be perfectly fine for a 64 bit OS. Here is the output of my box:

(proj)sanjayts@VirtualBox:~/stuff$ ls -l j2sdk-1_4_2_19-linux-i586.bin 
-rwxr-xr-x 1 sanjayts sanjayts 36387084 2011-12-22 00:04 j2sdk-1_4_2_19-linux-i586.bin

Can you do a fresh download of 2_19 (instead of 2_18) and try again? If it doesn't work, do a `ls -l` and check if the size is same as the one I posted above.

If all the above still doesn't work, we might have bigger problems but let's try this out first...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I was able to properly download and install it so either it's a corrupt download (try downloading again) or maybe the given binary package is not compatible with your linux installation (unlikely). Can you do a 'ls -ltr' of the bin file and post the results here?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You can download the self-extracting .bin file for 1.4.2_19 from http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase14-419411.html#j2sdk-1.4.2_30-sol-JPR

After the download is done, just fire:

chmod +x j2sdk-1_4_2_19-linux-i586.bin
./j2sdk-1_4_2_19-linux-i586.bin

This will fire-off the installer and bring up a licence agreement screen which you will have to agree to. Once installation is done, you'll have a new folder called "j2sdk1.4.2_19" in the folder in which the installation was fired. This method also has the advantage of not clobbering your system wide Java installation. Just make sure that you properly set the $PATH to include this new java instead of using the system default 1.6.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You need to break up the regex you have posted and explain your reasoning behind putting the constructs which are there in your regex. Also, instead of posting "sample data" for the pattern you can looking for, it would be much for helpful for your own sake to frame the requirements in words. An e.g. the regex should accept any two alphabets followed by a colon and one or more digits.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> The sql looks something like this [...]

AFAICT, the problem isn't the semicolon but the JDBC driver which refuses to consider the two parts as a single statement hence the exception. Also, the query doesn't look like standards compliant SQL (the SET part).

You have two options: wrap the "custom" query in a stored procedure and call the same using JDBC (look into CallableStatement) or convert the query to something which is valid SQL statement as per the SQL standard.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A non-Java based obvious solution would be to grab mplayer and use its speeding up and scale tempo options; more here: http://tux4life.wordpress.com/2009/01/07/change-mplayer-playback-speed/ . If you want to do the same thing in Java, I'm not sure. Java based front ends (bindings) for mplayer etc. look terrible, are pretty much unusable and showcase the obvious disconnect between video processing tools/technologies and Java.

If you are looking for a free solution, just go with mplayer (or its frontends like SMPlayer).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

For everyone's reference, if using JDK 6 and a JDBC library built for Java 6 runtime, just having the JDBC JAR in the classpath is enough to load the driver, no more `Class.forName` required! This is because of the ServiceLoader facility publicly introduced in JDK 6 which allows "service providers" (in this case JDBC driver vendors) to provide an implementation class for a particular service (in this case java.sql.Driver interface).

The way this works is:

When your application code first refers to the DriverManager.getConnection() method, the static method loadInitialDrivers() queries the ServiceLoader API for any java.sql.Driver implementations present in the classpath in the form of META-INF/services entries and loads the class by name if present. If it finds it, a Class.forName method is invoked to load the service implementation.

To verify, open up the JDBC driver for MySQL and navigate to the META-INF/services directory. This directory should contain a UTF-8 encoded text file having the name 'java.sql.Driver'. The contents of the text file would be the name of the implementation class, in our case, com.mysql.jdbc.Driver. This is the class which is loaded and typically would contain the code to register with the DriverManager as we can see from the source.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> yes i found it and but it in jsk lib's but when i compile , that's error all imports of httpServlet does not existed

OK, you need to tell us:
* The location of the servlet api related JAR on your machine
* The command you are issuing on the shell to compile your servlet
* The exact error messages you are getting

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> i have a java class extend Httpservlet when i'm where i can but the servlet APIs to compile it

If you have a servlet container like Tomcat/Jetty, you should be able to find these dependent JAR files (i.e. jar files part of servlet specification) somewhere in the Tomcat/Jetty directory (e.g. lib directory). Search for the servlet-api.jar file.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

okay! let i have called o1.t.start(); and second statement is o2.t.start();(t is object of Thread class here and o1 and o2 are my objects of class implementing Runnable).now in this example i have seen is that both statement are executing give control to each other randomly.if in run(), i give counter then its value is randomly decided means that loop is iterating on none basis.both threads are giving control to each other without any reason.(both have same priorities). how ill u explain this ?

Your question isn't very clear, you need to present your question with a small self contained program which displays the behaviour you are observing. Plus, you can't invoke the start() method of the Thread multiple times which is what you seem to be doing in your query which implies that there is some explanation missing. Post code so that we are all on the same page.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Is that the same connection variable you are using for all of them? If yes, then you are effectively throwing away the connection retrieved. The way you should test is: retrieve the connection for a given database and fire some query specific to that database which will ensure that you are indeed connecting to the database in consideration.

JeffGrigg commented: Well said. +7
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Have a look at this topic which talks about something similar. AFAICT, ignore list is the closest you can get when it comes to "blacklist".

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I have a large file (11 GB), that I want to extract information from.

At the risk of posting some off-topic, is using Python an absolute requirement? If not, and assuming you are on *nix, you can easily extract the probability using a one-liner:

cat tab.txt | sed '1d' | awk 'BEGIN{FS="\t"} {split($7,arr1,";"); split(arr1[3], arr2, "="); print arr2[2] }'
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Tip: The answer is not "option B"

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

@niff

I agree namedtuple isn't the universal solution, but it's part of a standard module and works pretty well for most of the cases. Also, there is no limit to the number of members you can have.

>>> Person = namedtuple('Person', 'name age hobbies')
>>> p1 = Person('Tom', 20, ['sleeping', 'programming'])
>>> p2 = Person(name='Harry', age=40, hobbies=['hiking', 'cycling'])
>>> p1
Person(name='Tom', age=20, hobbies=['sleeping', 'programming'])
>>> p2
Person(name='Harry', age=40, hobbies=['hiking', 'cycling'])
>>> p2.hobbies.append('gaming')
>>> p2
Person(name='Harry', age=40, hobbies=['hiking', 'cycling', 'gaming'])
>>> p2.name = 'Dick'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't set attribute

As you can see, the only problem folks might have with namedtuple is that it's immutable i.e. fields can only be set once. But this doesn't pose a very severe restriction because you can still modify the objects pointed by the fields (i.e. mutate the list).

EDIT: Damn, Tony beat me to it

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

On the REPL, when you type a name which exists (can be a variable, class name, function etc.), the output shown is the str() representation of that name. For e.g.

>>> s = "Hello\nWorld"
>>> s
'Hello\nWorld'
>>> s.__str__()
'Hello\nWorld'
>>> str(s)
'Hello\nWorld'

If you want to view the output of the interpolated string (after taking into consideration the escape sequences etc.), use the print construct.

>>> s = "Hello\nWorld"
>>> s
'Hello\nWorld'
>>> print s
Hello
World
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Or if you have Python >= 2.6, just use namedtuple .

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Use a PreparedStatement which automatically takes care of escaping special characters and at the same time protecting you from SQL Injection attacks.

PreparedStatement pstmt = connection.prepareStatement("select dataid from tbldata where datastring=?");
pstmt.setString(1, level2[0]);
ResultSet rs = pstmt.executeQuery();
// use rs

Use the same trick for inserting data so that you don't have to worry about replacing stuff. This makes it easier for the programmer to write queries in Java (i.e. no concatenation and escaping) and has the possibility of improving performance if the database and the JDBC driver supports statement pooling.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You are already subscribed to the thread so just keep reading the new posts for updates on the same. Also, Daniweb uses vBulletin under the hood so it might take quite a bit of time to resolve this issue.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

if I make a code block and insert a *numeric* entity in the format ampersand-#-number-semicolon it comes out converted to html

Dani, I can confirm this is happening and even noparse tags can't resist the urge to parse the numeric entities.

I don't think *anybody* has even a clue what ICODE means

ICODE stands for inline code and I'm pretty sure a lot of regulars know what it stands for. Though I agree with the general sentiment that ICODE usage is difficult to get right for newcomers and first timers.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Unfortunately, I don't have a Ubuntu installation handy to help you out.

I'd suggest you to either ask your friend to help you out with the firewall configuration (assuming he had tweaked his own) or search around for "ubuntu firewall config" which brings up quite a few articles that might help you pin down the problem.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> If I bind the server socket, I would bind it to 127.0.0.1

That anyways wouldn't work because in that case it won't be accessible by external clients (given that this is a loopback address).

Your ServerSocket creation looks OK. The problem might be of unreachable host/port due to blocking of communication by your ISP. Go to http://canyouseeme.org/ which shows your IP address and asks you to input the port number of your running application. If after clicking the "check" button you can see an output of the form: "I can see your service on X.X.X.X on port (XXXX)", it means that your service is visible to others. If the test times out, then it is a problem with your firewall/ISP settings.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

When creating the ServerSocket, make sure you are binding to the same host and port which the client is trying to connect to. Look into the different types of constructors offered by ServerSocket class and use the one which also allows you to specify the IP to bind to.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You can't change it yourself. Please provide us an username which you would like to get it changed to (assuming it's not already taken).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> what do u mean on both server and client?

The client is a Java Swing application, no? Look at the stack trace you posted in your first post. The client invokes a webservice and hence needs to have access to all the runtime JARs required by a webservice client.

Also, don't mess around with environment variables when setting classpath. In case of a web application, use WEB-INF/lib directory. In case of a standalone client application, package the dependent JAR's in a separate directory and include in on the classpath using -cp switch.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

no i m sure bcs i uses many other jar files in java with different applications and every thing goes well.but in this code i can't find what is the problem??

You need to have 'streambuffer.jar' file in your runtime classpath. Check whether you have that JAR included at both client and server.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> shouldn't i just call in the main method something like this to create 100 thread?

Yes, except that you have a one-off error in your code; you are iterating 101 times, not 100 times. And make sure variables have logical name and not numbers tacked on to the end.

> and about the thread pool thing, she said that is how you create multi-threading....explain that please

Thread pools are the new abstraction offered by the standard library to replace the old Thread() construct for doing background activities and submitting tasks. But if your assignment specifically asks for 100 threads, creating a pool with 100 threads wouldn't be the same, because it is quite possible that when you submit the 50th task, it might be processed by the same thread that processed the first task. i.e. there is no guarantee that a new thread would be used. If this isn't a problem, go ahead and use the pooling approach. Otherwise, stick with the new Thread() stuff.

> so is this the ouput should be like?

That isn't something you should ask us. I would rather want you to test both sync and non-sync runs and draw the conclusion based on what you have learned.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Not exactly; all AtomicXXX classes use lock/wait free constructs whereas "synchronized", which is what the OP has to use, is inherently a lock based approach. Though I agree the article would be the next logical step i.e. going from synchronized to lock-free implementation.