No. It's a simple discussion of personal opinions/views of the pros and cons of varying approachs.
If your question is solved, go ahead and mark it as solved, that won't stop people from being able to post in it.
No. It's a simple discussion of personal opinions/views of the pros and cons of varying approachs.
If your question is solved, go ahead and mark it as solved, that won't stop people from being able to post in it.
That is not what I was suggesting. I never said (or even hinted) that you should attempt to use ssh tunneling. If you can't connect to the port with one protocol, you probably can't connect to it with another either, as you probably have the port completely blocked, and tunneling is not going to help with that. I suggested SSH if your firewall is on the router, not the local machine, and it provides an SSH access for configuring the firewall and you still insisted on your application configuring the firewall.
You have no idea what you are doing do you? Well, in order to anything about this you need to learn about firewalls in General, so go do a little studying and then come back to this question and you will, hopefully, realise how wrong this question is.
So then don't switch anything off, as I said. Configure the firewall properly to allow traffic on the concerned port. It is not that hard to understand. If you insist on doing it from Java then see my first reply and choose the applicable method. If you don't know which method that is, then research your firewall software a bit and find it out.
No, it's not sync at all. You just as well remove the sync blocks as they are doing nothing. I have said time and again, do not sync on the thread, that makes no sense, and if you want the print statements mixed than sync only around the print statement and not around the entire while loop. And create an instance variable of type Object and instantiate it and sync on that.
The concept is not that hard, but, seeing as how you haven't been able to follow directions, yet, even when explicitly stated:
public class TestThread implements Runnable {
final Object lock = new Object();
TestThread() {
System.out.println("Hello World! ");
new Thread(this,"Test 1").start();
new Thread(this,"Test 22").start();
}
void Check() {
for (int i = 0; i < 20; i++) {
synchronized(lock) {
System.out.println(i + " .... Sync block: " + Thread.currentThread().getName());
}
}
}
public void run() {
System.out.println("Run : " + Thread.currentThread().getName());
Check();
}
public static void main(String[] args) throws InterruptedException {
new TestThread();
}
}
IOW, your application should not be worried about the firewall. That is a security issue. Configuring the firewall to open that port is the job of the administrators not your application. The only time a Java application should attempt to do anything with a firewall is when the application is meant to be the management software for that firewall.
IOW, don't turn off the firewall on your machine, configure it to open that port for outgoing/incoming traffic as applicable. If you do not know how to configure your firewall, then ask at a site related to the firewall in use as that is not a Java question.
No the "object t1" is not synced. The object in the sync call block is what threads will attempt to lock in order to execute the block, the object itself is irrelevant as long as all threads attempt to sync on the same object. I don't know what you were really trying to say in that post, but how much is "synced" depends purely on what the block encompasses, and how "parallel" something is depends largely on how many different synced blocks lock on the same object. I.E. two blocks that both sync on object "a" will block each other, whereas if one of them syncs on "b" they do not block each other.
They both work. Depends on how granular you want the syncronisation to be.
:sigh: Is this suppossed to be some kind of crack program? In any case, there is no blanket answer to that anyway. It depends.
If it is a firewall on the machine, then it depends on the software. Are there CLI command that you can use? Then ProcessBuilder/Runtime.exec(). Is there an API? Then is there a Java library? If yes, then use that, if no, then is there a defined JNI Interface? If yes, use that. If no, write a JNI Interface.
Is the firewall on the router? If yes, is there an HTML access? If yes, use HttpURLConnection. If no, is there an SSH access? If yes, use JSch from JCraft. If no, is there a telnet access? If yes use Apache commons, if no, you will need to figure out how it is accessed otherwise.
In otherwords, you are, almost definately, in far over your head.
Okay, I see you've marked this one solved and have started a second thread on the "list" topic. I'll go ahead and lock this one now then.
Use LinkedList (see the API docs), or create a Custom Object that contains reference to the previous and next "edge" as instance variables as well as defining the current "edge" itself.
As far as Output is concerned,
Whichever runs first, it finishes it round upto 20.Then left the other to start & complete its 20.
Well, seeing as how you've synced around the entire while statement, so that only one thread at a time can access the entire loop, what did you expect? If what you really want is to have the print statement mixed, then sync only around the println statement.
Like I said, do not sync on the thread. It makes no sense. Create an instance variable of type Object and sync on that.
The nextInt call does not retreive the rest of that line, so call nextLine right after that to read the rest of that first line.
If you want an array linked lists then declare an array of linked lists and not an array strings. A better explanation of what you want and the code for that second array might help to help you.
Sure looks like it, which means that that is where he forgot the closing }
P.S. @OP use a switch that huge if/else if klotz hurts the eyes.
I told you why I am being hard on you. I told you also that I don't really mean to be, I did not say I didn't know why.
I gave you a link to the API docs. Every programmers best friend. I was not telling you to "copy stuff you found off the internet". I was suggesting you look at the API docs for the classes and methods concerned in that code and try to figure out what it is doing.
Edit: P.S. Attempting to crete your own look and feel far from a "simple" task. It tasks even the best of Java Programmers (to get it right, anyway).
The exception tells you exactly where the error occured. Somewhere directly before that point you have forgotten a ; or a closing } or are performing an action that must be contained within a method or constructor.
What do you mean "no idea" by 10-11? Did you suddenly forget what the "import" keyword does? It's the same as those above it, obviously. But do you know what an "import" does? It does not import any code into the class. It simply allows the developer to type Color instead of java.awt.Color everywhere the developer wishes to use a Color.
I'm sorry, but how long have you been in this class?
Judging by the name "paintComponent" alone, what do you think the purpose of that method is?
As far as 14 - 18 are concerned, do you know what variables are? instance, in this case.
And nothing is defining any "typeface".
Take a look here http://java.sun.com/javase/6/docs/api/index.html and try again, with a bit of research this time.
I don't mean to be hard on you, but you will learn it best if you struggle with it a bit yourself, first.
Nope all four are there, but the first one is an empty string.
And that exception comes from the second array where, I can only assume, you are trying to set the elements of a String array with LinkedLists.
the whole concept of synchronization comes when we know that the data is going to be shared by multiple users .
synchronization of block is different from synchronization of function because a sync. block can come under a function ....means one should use sync block when he wants to sync some part of the function and not the whole function.....
as in your code u sync the object with a limited code and not the whole code......
sync. of whole object or a func slows the execution speed of program
You'll notice, he has the entire body of the method synced (except the declaration of the variable, whoopee!). So what determines whether that is better or not depends on what is being synced on. Syncing on "this" is, effectively, the same as simply syncing the method. Now, if each synced block syncs on different objects, then time can be saved, but be very careful or deadlocks are a very real possibility, more like a probability, if not an ensurity.
Well, now, that's what I said, isn't it? Is there something wrong with allowing the OP have a feeling of accomplishment by solving it himself? Do you feel the OP is too dense to figure it out alone given the information provided?
It depends on what you're synchronising on. I can say now, however, that synchronising on the thread, is just plain wrong.
The first index of an array is 0, which means the last index of an array is one less than its length. So, knowing that, take a look at the condition in your for loop and see if can find and fix the problem.
For number 7, add a toString() method.
In the equals method you should probably check that the parameter is not null. You may also think about properly overriding Object's equals method and just use that.
The other part of number 9 is to implement Comparable.
For number ten override the clone() method and for the other part of add a Clock instance variable and a getter/setter method for that.
For clone and equals (and hashcode since you're doing equals) see http://java.sun.com/docs/books/tutorial/java/IandI/objectclass.html
For some info on getters and setter see http://en.wikipedia.org/wiki/JavaBean (although that is also covering something else).
For more info on Comparable see http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html
IOW we should do your work for you?
Why don't we start out this way, you write out, here, what you have and we will help you refine it. How about that?
Do you want to "set the element to 0" or do you want to remove it. The sample code will actually remove it. If all you want to do is set it to 0, then there is no reason to "record" the index when you find it, simply set it to zero then and there (or, more probably null, or setName to null or "", since the array contains objects, seemingly).
And what, exactly, is the problem? You might want to try using trim on the first nextLine call to remove extraneous whitespace (to include any possible newline, but I believe the nextLine call strips that, check the API docs about that though, as I am, currently, too lazy to do it for you).
Then I'm impressed, they've gotten better.
And of course you use JSP/Servlet, That, of course, does not invalidate the argument. And you completely missed the point about methods. And building a GUI by hand, when done properly, as I said, does not produce rigid and repetitive code, unless you code in the same way as the GUI Builders. And, as I said, I have never seen a GUI builder that lets you choose what layout you wish to use. That would cause too many variations in the way the GUI builder must react, and, as I said, I have never seen one that uses GridBagLayout, so a complex GUI will winf up using about 5 times as much heap space as necessary. It is not something that is fatal, usually, and not someting that you always, or even usually need to be concerned with, but sometimes you do.
I have no problem with people using them. Exactly the opposite. But, especially for the beginner it is very important to start building them manually. It is important to know how to do it yourself, or you will never be able to diagnose problems that even just might be caused by that. And you will be completely lost if you need to make even just a minor change to it and do not have your builder to use, or, in the framework of the project, are not allowed to use it, which happens more often than you may think.
I also see no argument in support …
I must disagree here: For example with NetBeans you can subclass a JPanel and make it whatever you want, like an interface for whatever you have (like a database record, a file...). Then you can write "custom creation code", create your component directly or through a factory which also links it to the data it has to generate values from, and still drag it around in your visual builder, and set properties like size, colour... And then you can even make that JPanel to require a ComboBox or whatever else palaced into it, so it'll use that as a prototype to create the custom ones!
Back a while with Delphi I used to think like you, but that GUI builder was crap, and all of them is.
Good for you, to each his own.
It's also a good thing to be able to start Java without knowing how to create JFrames, and learn it on the way. But it's best to learn how to create JFrame, learn how your GUI handles it, and learn how each one is intended be customized, since the point of every OO framework is to be customized.
Maybe, but I still find it best to learn it manually first so you know what it is the code those GUI Builders make does.
When you have to put a lot of simple components onto a form, it's inevitable to produce rigid and repetitive code, just because it's data hardcoded into program code, and GUI editors …
I hope the OP comes to work with you whether or not it ever passes the course so you can continue to do its work. Not that either of you would have job long, in that case.
Timer and TimerTask (java.util and not javax.swing)
Because the browser history (on the client) has nothing to do with the session on the server. For each and every page you return set the "no-cache" pragma and set an expires meta-data of -1. At least then the browser does not cache the pages at all and hitting back would require the page to be newly loaded from the server which would fail.
As noted above, you can only directly erase the clients history on the client, ie through javascript or the like. Nothing to do with Java or JSP.
So what do you have? According to the terms and conditions of this site (which you agreed to when you signed up here), and on general principla, we will not do your homework for you. We are more than glad to help you correct your work, but you do need to do it.
I was just wondering if someone can provide an algorithm to the following question.
Yes, I am quite sure someone can. Unfortunately for you, though, that's your job in this case.
What do the Pattern and Matcher API docs say about "capturing groups" and what does the Java regex tutorial show about it?
Write a small test program with that String hard-coded in and try out varying patterns and varying ways of using Pattern and Matcher. Once you have done that, and it is still working as you think it should post that code here and I will help you get it right, but I have pointed you to exactly what you need (which at this point is the second and third links) you just need try it out.
See the second and third links above. The first is general regex, not just Java.
^.*\\]\\s+Attack Of Opportunity\\s+:\\s+(.+)\\s+attacks\\s+(.+)\\s+\\[.*\\*([\\w]+)\\*.*\\+\\s+(\\d+)\\s+=.*$
so the ^.*\\] takes all of the text to the left of the last bracket and states that as part of a regex. after that, the \\s defines a space, and then the phrase Attack Of Opportunity is checked for. then, it checks for another space with \\s, then a colon, then another space, then the name with (.+), then another space, then the phrase attacks, and then another space. after that, it checks for a second name, then a space, and then after that i *believe* that it checks for an "*" then a word, and then another "*" followed by a space, then a series of digits followed by an "=" and a string of length 0 or more. then the strign terminates. I think this is what you were asking for, and i think i could reproduce the beginning but the end would be extremely confusing for me to create.
TJ
The bold part is wrong. followed by "anything" then a space, a plus, a space, numbers, a space, "=", and "rest of string". The four groups of parens are save blocks, so there is your saved name1, name2, "miss", and "113".
^.*\\]\\s+Attack Of Opportunity\\s+:\\s+(.+)\\s+attacks\\s+(.+)\\s+\\[.*\\*([\\w]+)\\*.*\\+\\s+(\\d+)\\s+=.*$
See the tutorials, and then you tell me how you think it works. And this is a simple "brute force" method.
"extends" is inheritance. Composition is using the base classes rather than extending them. Doing it this way does not "lock" you into a specific "framework". It makes is much easier to provide different GUI's (I.E. a Swing Gui, a web Interface, a CLI) without large changes to the "interaction" between the application itself and it's GUI (these are separate things in your program, right? The app is not completely mixed in with the GUI, is it?). You also can only extend one class, and since you usually only need about 5 things from whatever GUI component you think about extending it makes little sense extending it and inheriting the hundreds of other things along with them (which are, of course, also exposed to the rest of the app which is probably a recipe for disaster, or at least misuse). Also, if you must (or would like) to extend a different class because you need it's functionality, then you're stuck because you've already extended a component class. There are all sorts of reasons not to, and the only reason to do it is the ease of use of, max, 5 methods?
i find the 2nd option best almost in every scenario.
public class MyFrame extends JFrame{ public MyFrame() { // either create or design the JFrame here or call the some other function like makeMyFrame() to design the JFrame } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable(){ public void run(){ new MyFrame(); } }); } } }
doesnt it look easy and clean way to make Frames
Most "beginners" do. That is wrong however. Prefer, as a rule of thumb, composition over inheritance.
Yes, you have to have some class that implements ActionListener. It is, however, perfectly acceptable in some cases to be the same class that defines the frame, or an anonymous class, or some other inner class, or some other class that also performs other Listener responsibilities such as WindowListener or ItemListener. IOW it all depends.
Well, unless you have a specific reason to extend JFrame, don't extend that either. Google "composition".
Implement Runnable unless you have some specific reason for extending Thread.
That is the instance that all threads must obtain a lock on in order to access the block.
We'll be glad to help, we will not, however, do it for you.
For starters, check out HttpURLConnection.