The learning never stops. I've been doing it for a long time and still stumble upon new things everyday.
Start from the basics and you'll realize there is no end to this. Also, a must read.
The learning never stops. I've been doing it for a long time and still stumble upon new things everyday.
Start from the basics and you'll realize there is no end to this. Also, a must read.
There are a lot of things going wrong here.
First, you should never ever mess around with your Java installation. Never. Setting class-path when compiling your files should be the way to go. Also, don't mess around with the "ROOT" application which comes pre-installed with your Tomcat.
I'll outline the steps in brief as to how you can get your first servlet up and running.
echo %TOMCAT_HOME%
and it should display the directory of your Tomcat installation. If not, go back to the previous step and try to understand what went wrong.Vector class *has* become obsolete. If you need a synchronized List, just wrap the plain old ArrayList class inside the Collections.synchronizedList call. In short, don't use Vectors unless you are tied to an API which forces you to use it.
Also, don't rely on synchronized collections when it comes to handling race conditions; they synchronize individual calls and not logical calls which you actually should have synchronized.
I always felt one more in the list is required. Like if user who started thread was last to reply on that thread and that thread is still unsolved. It means that user is expecting someone to answer
...or has already got an answer and is thanking the ones who helped him solve the issue. :-)
But really, IMO for those who help out, monitoring the forum once a while (every 3 hours or so) for new replies is pretty much a trivial.
You've got things mixed up; re-read my post and try out the example. Kashyap provided a way for "explicitly" initializing a class whereas I talk about implicit initialization in my first post. The entire process is mentioned in the specification.
A class or interface type T will be initialized immediately before the first occurrence of any one of the following:
T is a class and an instance of T is created.
T is a class and a static method declared by T is invoked.
A static field declared by T is assigned.
A static field declared by T is used and the field is not a constant variable (§4.12.4).
T is a top-level class, and an assert statement (§14.10) lexically nested within T is executed.
So basically, whenever you try accessing a static field (except for constant variables), the class would be initialized.
AFAIK, this is expected. The IP address assigned to you by your ISP is the external IP address whereas the unique IP addresses of each of your network machines are "internal" addresses which aren't viewable to the outside world. This is one of the reasons why browsers don't just rely on IP addresses for client identification but use a token mechanism like passing token (session id) using cookies or by appending it to the URL (another one is client using proxy servers).
So to answer your query, this isn't just about "different" computers but about public IP addresses. A solution around this would be to use a token mechanism i.e. generating hashes and assigning them to clients which connect to your server and "destroy" or "invalidate" the hash when the client logs off or a certain period of inactivity is observed.
I'm assuming that the aim here is to make Java developers aware of the JVM port of Python programming language and the goodies which it brings with it. However, those thinking of making a transition from CPython to Jython in hope of a better GC and threading, please make sure you read the "differences between CPython and Jython" page (not sure how updated that page is, but worth a read).
As a side note, "Grinder", the load testing framework uses Jython as its scripting language. :-)
Daniweb members who are interviewed for the Daniweb monthly digest/newsletter get the title "featured poster". These members are typically picked up by site administrators based on factors like contributions, frequency of visiting Daniweb etc.
Admins typically have a list of 'to be interviewed' folks but if you feel that someone fits the role for an interview (including yourself :>), you can always PM Davey (aka happygeek) and that name would be added to the 'to be' list.
The problem with this approach is that the welcome would seem kind of forced. And not to mention the possibility of the answer being forced as well. It might go something like this:
OP: Hello, can anyone help me with xxx? Thanks.
New-Member: You are almost there, just change yyy by zzz and you should be good to go.
I-Just-Saw-Sunshine-Member: Yeah OP, you should totally follow what 'New Member' has written down. That being said, New Member, welcome to Daniweb. Hope you enjoy your stay here. Looking forward to working with you.
Just to be clear here, as long as your posts are 'on-topic' in the forum you post, it isn't against the rules but if your posts start becoming more of a welcoming committee speech and less of a valid answer, it's annoying for everyone.
That being said, you "can" do it without violating the rules but with that long speech, it would be considered annoying. A simple "Oh and BTW, welcome to Daniweb" added at the end of your post or a simple reputation comment "Welcome to Daniweb" would be much more desirable.
A member gains a 'banned' status if he ends up gathering 10 infraction points. When a member is infracted for breaking the rules (http://www.daniweb.com/forums/faq.php?faq=daniweb_policies), he is "infracted" and "awareded" infraction points based on the severity of the rule broken.
Bans can expire, typically in 6 months or so, unless it's a perma ban, which is normally given to persistent drug/porn spammers and those members who create new accounts for the purpose of avoiding/getting around a ban.
Wow, I don't know whether you made that up, or if it is a normal way of handling this, but it's brilliant
Thank you for your help in this thread
You are of course welcome. :-)
Just one last thing: is there away to determine whether an exception has been thrown by in or out?
Yup, there is; I ignored it for examples' sake but good job noticing it. You can print out the toString() representation of the "closeable" and it should print out whether it's an 'in' or 'out'.
public class Utils {
public static void closeAll(final boolean ignoreExceptions, Closeable...closeables) {
for(final Closeable closeable : closeables) {
try {
if(closeable != null) {
closeable.close();
}
} catch(final Throwable t) {
if(!ignoreExceptions) {
// OR LOG.error("Exception closing stream " + closeable, e); in case you are using a logging library
System.out.println("Error closing stream " + closeable);
t.printStackTrace();
}
}
}
}
}
This would print out something like java.io.FileInputStream@19821f
for a FileInputStream and so on.
Simply put, a hash code is ideally a best effort numeric (integer) representation of a Java object. Each Java object which lives in the JVM has a default hashCode() which is mapped to the integer representation of the address of that object (which as you can see is a good enough representation, since objects have unique addresses. This breaks in cases where the underlying address space is more than the range of an integer but don't worry about that for now).
But why allow the hashCode() to be overridden? The short answer is: because it can be used in a clever way to implement hash tables in Java. The logic used in the hashCode() method can be thought of as a hash function used to generate hash codes for the given object.
As an example, let's suppose you decide to put the hashCode() method to good use for the String object. The objective here would be to make sure that we almost always get the same hashCode() for equal strings. The most logical way here would to consider the characters of the string to generate the hash code since if a string has same characters and same length, it has to be same. But, we have to make sure that the order of the characters are also taken into consideration when generating the hash code (we don't want 'sad' and 'das' to end up having the same hash code). But be warned, it is quite *possible* …
~sos~:
That seems very reasonable.
About closing the streams:
would using IOUtils.closeQuietly(); make sure the second stream is closed, even if the first stream fails to close?I have rewritten my code snippet now, (no error handling yet)
could you maybe give it quick look and tell me if I'm doing anything stupid?
One thing that irritates me is that I think it would be best to open the in- and output streams in the same try-catch block,
but that makes error handling difficult, as there is no telling which of the streams throws an IOException for instance.
Or am I mistaken?import java.io.*; public class TextMan { public static void main (String[] args) { try { BufferedReader in = null; BufferedWriter out = null; try { in = new BufferedReader(new InputStreamReader(new FileInputStream("bhaarat.txt"), "UTF-8")); } catch (Exception e) { e.printStackTrace(); } try { out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("out.txt"), "UTF-8")); String strCache; strCache = in.readLine(); int count = 1; //Silly string manipulation, you can probably just ignore this :) while (strCache != null) { strCache = strCache.split(" ", 0)[1]; if (strCache.charAt(0) == 'H' || strCache.charAt(0) == 'S') { out.write(count + ". " + strCache + "\n"); count++; } strCache = in.readLine(); } } finally { if(in != null) in.close(); if (out != null) out.close(); } }catch (Exception e) { e.printStackTrace(); } } }
I realize this could be done with a one-liner using awk and grep, but I'm trying to learn a little programming …
The try-catch-finally (try-catch) is a well known vicious cycle when dealing with closeable resources. There are two ways around this:
* Using the nested-try method (NOT RECOMMENDED, since multiple resources can make the code ugly and this doesn't handle closing of 'out' in case closing of 'in' fails)
public static void main(final String[] args) {
try {
Scanner in = null;
BufferedWriter out = null;
try {
in = new Scanner(new File("bhaarat.txt"), "UTF-8");
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("output.txt")), "UTF-8")); // yuck
while(in.hasNextLine()) {
out.write(in.nextLine());
out.newLine();
}
} finally {
if(in != null) in.close();
if(out != null) out.close();
}
} catch(final Exception e) {
e.printStackTrace();
}
}
* Creating helper methods or using external libraries which take care of exception handling (RECOMMENDED):
public static void main(final String[] args) {
Scanner in = null;
BufferedWriter out = null;
try {
in = new Scanner(new File("bhaarat.txt"), "UTF-8");
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("output.txt")), "UTF-8")); // yuck
while(in.hasNextLine()) {
out.write(in.nextLine());
out.newLine();
}
} finally {
// http://commons.apache.org/io/api-1.2/org/apache/commons/io/IOUtils.html#closeQuietly%28java.io.InputStream%29
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
}
BTW, make sure that in your first attempt of code, you don't end up catching each and every exception. Just let them propagate to the main thread so that the JVM automatically exits by spitting out a stack trace. Add helpful error messages only in case where in the user doesn't need to see the trace but at the same time do make sure that the original exception is "logged" somewhere and not eaten up.
The FilenameFilter is used to filter out files in visual components (e.g. when you navigate to a folder, only *.java files would be seen) and in cases where you need to return file names which satisfy a given criteria. Basically for filtering needs based on "file names", FilenameFilter is used.
FileFilter on the other hand deals with "File" objects i.e. filtering based on a given File attributes like; is the file hidden, is it read only; something which a file name can't give you.
Of course, it's pretty trivial to create a File object based on its name and parent directory so I guess these "two" filters are more of convenient wrappers over the same concept but slightly different use cases.
Not sure if that's a genuine question or not but here ya go: http://www.homemademech.com/anime-articles/12/
Yes, you definitely can do it. If I've captured your requirements correctly, you basically want to "invoke" the functionality implemented by native extensions in your Java code. In that case, look into JNI (the actual specification) and a easier way to go about it using JNA (JNI is too much chore and boilerplate code).
I know this is kind of late but in case you folks didn't know, Japan is still trying to recover from the aftereffects of the calamity which struck it few days back. In these horrid times, every bit of sentiment and help counts. No help given with good intentions is a 'small' help.
In case you can want to lend a helping hand by contributing financially to the relief efforts (which I think everyone should) but are unaware of a tried and tested channel which is not part of the 'sick scam' which some people are trying to pull, I would highly recommend the Google crisis response page.
http://www.google.com/crisisresponse/japanquake2011.html
The donations made from here are safe, trusted and go directly to the Japanese Red Cross. Please don't shy away from donating just because you think you aren't donating much, a small donation is better than no donation.
Remember, 'today you, tomorrow me'. Thank you.
Being a caring person who wants to help does not negate being an idiot.
Non sequitur; idiocy and caring nature are two orthogonal things.
I work very hard for my money and give regularly to a number of charities, but i try to do as much research into how much of my money will make it to the people i am trying to help before i donate.
Again, doesn't related to the discussion here since I already mentioned that these people are non-computer-savvy who normally don't inspect "mail headers" like we do and would be more than convinced to see a "Japan Red Cross" name in the "From" field...
I'm not sure why you think it won't be a good idea to request the sys admins for setting things straight. It's not as if you are asking for a permission to unblock youtube or gmail. Plus, the filter is obviously broken; it allows you to browse some parts of the site but not others like Web Development.
You can always give the reason that this site shows up in google results when you search for fixes to your issues. The worst possible thing that could happen would be the sys admins blocking entire Daniweb domain. Or if you are lucky, they might just realize how stupid their blocking criteria is and modify their rules.
Your problem is that you are using 'long' type where 'double' is desirable. For e.g. what should be power of 10.1^2 ? What does your invocation of 'power(10.1, 2)' print? Your power method is broken but it doesn't throw a compile time error because of your use of `*=` construct. Try replacing it with `result = result * x` and you'll notice where you are going wrong.
I don't see any form element with the name "mmsTitleAdded" which kind of explains why you are not getting any values (unless you have not posted the code which shows this element). If you are trying to get the multiple values of the "SELECT" in your first code snippet, try using "mmsTitle" instead. Also, you can always view what kind of data is submitted to the server using a tool like Firebug extension for Firefox. Really handy I must say to see *what* gets submitted to your server.
Oh and BTW, your code is *really* messy. Avoid using scriptlets in your JSP markup and make sure your internal Ajax requests return a JSON object instead of a "HTML fragment". Sure, the way you have done it makes it easier but unless it's a short term project (school project), maintaining this complicated piece of code would become more and more difficult as the code base grows.
I'm not sure I buy into this idea that if one provides code, they "deprive" or "ruin" anybody's thinking process. Maybe it's because I'm older, have already "been there, done that" as far as formal schooling goes, and I'm a professional programmer now. I've already proved myself and hence no longer need the "if I just give it you, you'll never learn to think for yourself" lecture. I give that lecture to my ten year old nephew, but I know him and feel somewhat responsible for instilling good habits in him. Yeah, I know all sorts of students come here with homework dumps and, if given the verbatim code, won't put any effort into it and hence never learn to think.
IMO it's got nothing to do with age (after all almost everyone advocating it in this thread is a middle aged bloke [rude assumption? maybe :>); it's just a matter of whether you want to give a solution to the OP or want to go out of your way and help him reach the solution, nothing more, nothing less.
There are all kinds of students who post here; those who already have the solution and want to understand how it works, those who don't have the solution and won't mind a ready solution but at the same time have a desire to learn something new and those who have no intention of learning. Posting code is a much bigger problem in a thread which already has an ongoing …
It wasn't meant to sound like an attack and i apologise.After you sent me that message i've re read the rules and i couldn't find myself breaking any.I'm not saying i don't deserve my down-reps but i definitely don't deserve all of them.I apologise for my bad english and i would like to see you handling with my language .I didn't know you had a forum for complains so my bad again.My personal opinion is that you should have a rule saying you can't post full solutions and i will try to stick with this not yet implemented rule if that's ok with you.I didn't really think i should take it from anyone else but a moderator since you're the person in charge here but i did mind the 8 down reps before telling me what i did wrong.Anyway i'm sorry for this and i hope i didn't offended you in any way.
No one can infract you for posting complete solutions (the reason why you haven't received an infraction till now). Reputation, is a different matter. Unless you have a member specifically targeting you with -ve rep, there is little we can do; after all, reputation was meant to be a measure of how individual members feel about the post. If most of the regulars of C++ forum are against posting complete solutions, you would get downvoted.
You have two choices:
OK, so basically anything which would be broken for a couple of hours or so would be by choice and not bad luck? ;-)
Why the reluctance to create more forums, does having more forums affect something that we aren't aware of?
At least from a moderation viewpoint, it amounts to more house keeping which needs to be taken care of. Plus, it's not like it was always this way in the past. Forums *were* created based on user request. But it turns out that the forum is created, it receives little or no activity and becomes target for link spam which might go on unnoticed for a long time.
Another point is having expertise in a given area. Most of the times it turns out that a new forum is created, the member who requested the forum creation actively answers questions on that forum and suddenly disappears. This results in the forum being filled with regulars who are seeking help rather than someone who is capable of resolving them. I know it has to start *somewhere* and it is worth a try but our previous experience has been pretty bad with this stuff.
Looking good, nice job!
BTW, just noticed that this isn't applicable when I click on a particular forum (e.g. Java from the drop-down). Not sure if this is how it was meant to be. Same with permalinks for thread posts (the PERMALINK link). Also, I think it would be wise for everyone to force a refresh (CTRL + R) since I was getting weird issues without it.
> all the suggestions will be greatly appreciated!!
Assuming the normal quadrant and angle measuring convention:
x = cx + r * cos(theta)
y = cy + r * sin(theta)
where:
x, y = coordinates of the point on the circumference of the circle
cx, cy = coordinates of the center of the circle
r = radius
theta = angle in "radians"
After you get (x, y), it's just a matter of drawing a line from the center to (x, y) and you should be good to go. Of course, this would work assuming you convert the angle values from degree to radians and adjust the adjust the read angle values based on how your accelerometer is oriented.
Good read: http://www.yaldex.com/games-programming/0672323699_ch08lev1sec4.html
Of all the posts in this thread, I am in complete agreement with Progr4mmer's post.
To someone beginning programming (not just Java), I'd neither recommend a full-blown IDE or a stupid text editor like Notepad. I mean come on, if you want to test your vision, there are better things to do that "try" to program in Notepad. :-)
I wouldn't recommend a specific text editor but any editor which does smart indentation, syntax highlighting, has the option of converting tabs to spaces, a regex based search/replace and multiple encoding support is worth its weight in gold.
BTW, I just compared the result of the query "starting java" using a US proxy and my own connection and for strange reason, the thread started by me ranks above the official Java tutorial. :-P
with proxy (US proxy):
without proxy (India servers):
> You realize I was joking, right?
You realize that given your position/designation on this site, you can be easily quoted out of context, right? :-)
Anyways, on the topic of improved content, I do see a reduction in the "plz gimme codez and projectz", more first timers using code tags and a lot of new faces to keep the forum alive in case the old-timers decide to ditch it i.e. looking good from a beginner forum view point. What I feel is actually lacking is "good" non-student questions and members who can answer those. It still feels as though 99% of the site members consists of students/aspiring programmers and only 1% who actually earn their bread/butter by programming, but then again I'm sure you are aware of this. Not saying that there isn't anyone who can answer those, just that such niche questions normally drop off the radar of members for reasons unknown.
I'd be more interested in hearing the views of non-moderating staff contributing members since they are the ones who spend the most time in the respective forums.
Glad to hear that a long time lurker finally decided to join Daniweb and help out others. Welcome to Daniweb. :)
if you state you cannot delete my posts, can u please delete the IP addresses / folder paths / file names that I have mentioned?
Again, that would be kind of impractical. You have around 60+ posts, all of which contain either some sort of IP address/file name. Editing all those posts to make sure the context of the thread remains unchanged and at the same time snipping out the IP address/name/paths is something which I can't do in the small amount of time I dedicate for this site. Not to mention your posts in turn were "quoted" by other members which increases the number of posts which have to be edited. :(
Also, to respond to your PM, I can't delete your posts; this isn't my site and deleting posts is against the rules. Maybe you should get in touch with the site owner.
I received your PM and would want to say that unfortunately I won't be able to comply with your request. The contents which you want to be deleted would take the meaning out of the thread, rendering the entire thread useless.
As already clarified in my previous post, we *try* to help out members by deleting sensitive information from their posts which include credentials, home address etc. Also, it's worth noting that Daniweb isn't the only place where you have your "sensitive" information posted publicly:
http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=18035
http://bytes.com/topic/python/answers/888277-how-submit-webform-using-clientform
Almost there. :)
Rule 1)
If going by pure generic code (no intermixing with legacy code).
<?> same as <? extends object>.
Even though <?> is a reifiable type and <? extends object> is not, since both doesn't allow adding into the reference type (of the above) hence type safety is always guaranteed between the two.
As far as generic declarations go, <?> is the same as <? extends Object>. The difference is in the the way both are encoded in the class file. Also, there is one corner case which I have come across wherein <?> can't be blindly replaced by <? extends Object>.
Rule 2)
Mixing legacy code and generics.
Raw -> <?> same since both are reifiable type and also since <?> means could be any type or unknown supertype.
Raw -> <? extends Object> unchecked conversion warning since Raw is a reifiable type and <? extends Object> is not. Hence type safety is not guaranteed at run time.
When mixing legacy and generic code, there are two things which come in play:
Does garbage collection occurs in PERM Area of Java Heap ?
AFAIK, yes.
This aspect doesn't come into play a lot when doing regular development and using already existing libraries but becomes apparent when you implement custom classloaders and manage class loading dynamically.
One e.g. would be Tomcat servlet container. Let's assume that Tomcat creates a separate "classloader" for each web application deployed. If out of the many running web apps if one of the web apps is stopped, the corresponding classloader goes out of scope along with the objects/classes created/loaded using that classloader. If now, for some reason a permagen GC is triggered, the classes along with the classloader would now be garbage collected. If you run the JVM with the -verbose:class switch, this can be easily confirmed by the log message "Unloading class somepkg.xxx".
Glad to see that interacting with fellow C#ers on Daniweb has helped you excel in your assignment. If you ever think of giving back to the community, just help out others in need in the C# forum. It would increase your knowledge along with helping out others who are struggling with concepts/assignments. Not to forget that we are more than happy to have someone become a regular here. ;P
Good luck. :)
i got a such type of error in junit+struts2 +spring
If you are "testing" your web application as opposed to individual Java components (which is what JUnit does), look into frameworks specifically tailored for those needs. IMO, a proper abstraction here would be to use Cactus or HttpUnit for testing your "web" requests. Use JUnit if you want to test your *individual* Java components, not the entire HTTP request/response cycle.
After a bit of searching, I found a tutorial which uses Cactus for testing a Struts web application which you might find useful.
By statements do you mean "code"? If yes, then JProfiler which is included with JDK 6 can be used for CPU profiling and at the end of the run gives the total time taken by each method till now. Search around for CPU profiling JProfiler.
SerializedThread is an inner class i.e. a class which depends on some outer parent class i.e. there is an association between your class Main and SerializedThread. When you try to serialize SerializedThread, it also tries to serialize Main class (which doesn't implement Serializable) hence the error.
A couple of solutions: make the main class implement Serializable (not recommended) or move the SerializedThread out of Main (recommended).
> how to store an image from one directory to another directory using jsp?
Can you explain a bit more on what exactly are you trying to do here?
> MoveTo or CopyTo method of java.nio.file.Path class.
AFAICT, Path class is JDK7 only which is still in its "preview release" stages.
Here is wishing all the members of Daniweb (spammers included) a Happy New Year! :-)
Why do local inner classes not allow static variables ? The static fields of the classes could at least have been allowed access from the local method ?
Because static members make little sense when it comes to "local inner classes" since these classes belong to a scope as opposed to another class or a top level package. The "outer" world is not aware of this local inner class and always deals with instances of this class which are typically exposed via some sort of interface.
If there is any state that has to be maintained at the "local inner class" level, it can be easily done by doing the same at the enclosing method level. But probably the biggest reason might have to do with preventing the external entities from modifying the "class" level state of this inner class. Hence, only final primitives are allowed to be declared static when it comes to local inner classes.
class DamnIt {
void damnIt() {
class Test {
static boolean bb = false; // error; not final
final static boolean b = false; // works
final static Object o = new Object(); // error; not primitive
}
}
}
Think of the JVM as a universal VM. JVM byte code is to JVM what x86 assembly is to x86 family of processors (sort of) with the difference being that this byte-code is not aimed at any specific processor architecture but rather a VM which runs on a variety of architectures.
The platform specific stuff is taken care by the different "JVM implementations" which are tasked with taking in the "platform independent" byte-code and translating it to the corresponding platform specific machine code. Here, the JVM installed on your machine performs the job of the translator; translating a machine independent "code" to machine specific code.
What are the things(portions) which are covered in J2SE and J2EE ?
Too big to cover here; read:
* Java SE: http://www.oracle.com/technetwork/java/javase/tech/index.html
* Java EE: http://www.oracle.com/technetwork/java/javaee/tech/index.html
Did java has a further development after oracle brought sun.
The feature list of the Java 7 release (the next version of Java)
Regarding bad titles: just report the first post of the thread and someone from the mod forums might fix that.
Plus, let's not go too off-topic here; how about wait for the OP to explain his/her situation (though I doubt it would happen).
Anything isn't good or bad in an absolute sense. IDE's are a necessity when it comes to professional development since you get paid for each and every minute. The organization doesn't pay you to *learn* but to *develop*. But, when it comes to beginners, IDE's are notorious for making them lazy and taking things for granted.
You'd be surprised at the number of job applicants I've seen who can't name *five* methods of the class they have used all these years. I call these kids the "CTRL + SPACE" generation. :-)
Which directory are you executing this command from? Is your class inside any package? Try: java -classpath .:/home/prem/javaprograms/mysql-connector-java-5.0.8-bin.jar testsql