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

You need to start debugging the code (which is pretty small IMO). As a starting point, what's the smallest sample with which you can reproduce this problem? What happens when you run this with inputs [5, 4]?

Which IDE are you using to write code? Can you try out the "debug" functionality of that IDE to step through your code and check the values at every step? If not using an IDE, can you try inserting some println statements to dump the arraylist values after each step?

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

The first one fails because base is inside the function which only comes into the picture when the function is executed. When you exec the code string, the top level definitions get executed, the functions themselves don't.

The second one fails because 'int' is not directly present in the ns dict, it's part of ns['__builtins__']['int']. If you really need access to int at the top-most level, you can start off your namespace by something like ns2 = dict( __builtins__.__dict__.iteritems() ).

If you are really trying to write a "intellisense" like thing, your best bet (more like a safer bet) would be to use parsing tools to parse the python code and create meaningful representation out of it (just like all other basic intellisense editors out there :) ). Something like this:

import ast

code='''
def foo():
    def bar():
        pass
    myval = 10
'''
res = ast.parse(code)
res.body[0].name # your top level function name i.e. foo
res.body[0].body[1].targets[0].id # function local variable i.e. myval
res.body[0].body[1].value.n  # function local variable's value i.e. 10

This can get hairy very quick so I'm sure there might be a few open source wrappers lying around for this sort of parsing...

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

don't use english by default because usually IT does, use a language you all understand.

I don't really agree with this. Programming cuts across boundaries so always assume that the code you write will end up being maintained by some person on the other side of the globe who doesn't speak the same language as you. English has clearly emerged victorious as a de-facto language for writing programs and communicating with fellow developers (look at any major open-source/closed-source project).

Also, this is a problem because once you get into the habit of naming things in a localized language, you'll find it hard to work at any of the well-known (or maybe Fortune 500 as some call it) companies. After all these years of working as a programmer, I have never seen a developer get away from code reviews after using localized names. :)

Regarding naming, don't clutter your class with single alphabet names but at the same time don't go overboard with naming variables. As long as you keep your functions/methods tightly defined, names don't pose much of a problem (as long someone is half-decent at naming them).

Give extra thought when naming class variables; a mess-up with local variables is still acceptable (because they can be fixed easily) but when you start leaking bad names throughout your code base, stuff goes bad.

I feel the most important thing with programming after all these years is "balance". Should this method be 200 lines long or maybe I can …

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

ResultSet is not serializable. You can only send across things which can be serialized across the wire e.g. List, Set etc. Any reason why you want to send the result set to the user instead of the data inside it?

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

I believe it should be fairly easy to figure this one out. When is the NullPointerException thrown? From the stack trace can you locate the line which throws this exception? (InfixToPostfix.<init>(InfixToPostfix.java:22)). What piece of code on that line could possibly be null?

Hint: Java initializes class members to their default value when the class object is created. All references are by default initialized to null.

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

I have read that using protobuffers takes a lot of fooling around with and if you change things with the class then the format breaks, rendering old versions useless

Not really true about the version bit. It takes the same amount of "fooling around" like any other technology but YMMV.

Also, I want to dive in and learn something new, which is a good chunk of why I'm doing this project in the first place

This is a good enough reason for implementing your own binary format for maps as I believe it's a good exercise. Bonus points for trying to make sure your map data can be read from other languages/operating systems.

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

I thought about XML or JSON but after some research I figured out that a binary file exported to my own file extension would be the way to go because apparently it's much faster.

I agree about the text v/s binary part. But any reason you are rolling out your own format instead of using protobuffers?

Anyway, keep in mind that data written using DataOuputStream can only be read using DataInputStream i.e. it is portable across Java versions but not portable across languages/runtimes. If you want to be able to read your map data in C++ or Python let's say, you need to write out raw bytes to the file stream (FileOutputStream). As as example look at how Java's implemention of zip file format write works.

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

Two minor points:

  1. You are ignoring the return value of the delete method; this is important if you are absolutely sure you want to have the file deleted since files opened up in other apps block deletion. Also it makes the logging statement incorrect in case the delete fails.
  2. You have a redundant flush/close call. Calling close on the outermost stream will first flush the underlying stream and then close it.
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Don't try to "push" things, it can have a backlash effect. Let's say I have allocated 2 hours for coding, I try to do whatever I can and break out so that I can relax. Even if I don't manage to solve the problem, I leave all the mental baggage behind when I relax and come back to it later.

The point is that you should feel motivated and not forced when trying out the problem again. If you think of it as a 'chore', it would be difficult to get things done. Also instead of staring at the problem, I tend to browse online forums/resources for related issues. There is a very high possibility that reading something random over the internet gives me a hint to solving the problem at hand.

Regarding game making books, Al Sweigart has a couple of free highly-rated books on this website, check them out at https://inventwithpython.com/

00Gambit commented: Thanks +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

@00Gambit:

If it helps to motivate you, I was a gaming and anime addict long time back (before I had a programming career). These days I have a full-time programming job. I still haven't given up on games/anime but the addiction is no longer around. I make it a point to spend at least some time helping out other folks on forums, learning new things and so on.

I wouldn't really consider myself a very "strong-willed" individual, so if I can break out of the addiction and set my goals to learn something new every once in a while, I'm pretty sure you can do it too!

00Gambit commented: Thanks +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Start hacking on websites like https://www.hackerrank.com/ which give you opportunities to solve problems using your favorite programming language. Trying to work towards a problem will teach you a lot about the different data structures and algorithms.

You gain points and improve in rank as you keep solving problems so that might be one of the motivating factors. I know problem solving doesn't interest everyone but just mentioning in case you might find it interesting.

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

I really don't mind it as long as it's just one size bigger than the actual answer text.

I think the bigger problem is identifying what's the question/who is asking it etc. Daniweb is one of the few forums I have seen that has a lot of "stuff" between the question title and the actual content. Look at any other forums like dreamincode, SO and so on. You have the question title which is immediately followed by a description/actual question. Or in case of some forums it's followed by small buttons or links. In the case of Daniweb, we have the title followed by a lot of free space and then a row of pretty big buttons.

Not to mention the way reputation is shown for OP is different when compared to the actual answers. Wouldn't having a special highlight/border solve the issue?

Just a thought, I'm not exactly claiming that this might be the reason but I wouldn't disagree if someone claims that this forum is unfamiliar, something which is what you should really aim for (familiarity) so that people hopping between forums feel right at home as opposed to confused.

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

Since you need to start and stop the server, you might actually need two servers -- an admin server and a print server. The admin-server manages the print server and the client only sees the "admin" server which acts on the admin commands and passes on the rest of the commands to the actual print server.

It seems like a weird design to have normal clients have access to "admin" functions on the server. A more logical design will be to have two GUIs -- an admin UI and a usual client UI. The client can queue/un-queue/restart jobs etc. but when it comes to adminnistering the actual server, you use the admin-console/UI which would require admin credentials. The admin UI will be directly hooked to the admin-server (which in turn still controls the print server as mentioned in my previous suggestion). The client UI will directly interact with the print server but will have access to limited actions.

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

Even if the processor has a single core, newer Operating systems (not DOS for sure) employ preemptive scheduling which gives the "illusion" of threads running in parallel. Also, even if there is just a single core, the preemptive scheduling means that threads would run in "random" order as scheduled by the OS.

In short, one guaranteed way of printing your output would be to start up the first thread after your second thread is done. Or use synchronization primitives to ensure that first thread always "blocks" until the second one is complete.

EDIT: Also priority is just a "hint" to the OS and is interpreted in an OS specific way. There is "no guarantee" that a thread with higher priority will execute completely before giving way to a thread with lower priority. Read this

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

I'm not sure I understand. You asked "what's the 3rd main" to which the answer was "it's the thread-group name". To which you then wrote "i think it is a process name in which the thread is create is it write".

To answer the last statement, no, it's not the process name but the thread group name as mentioned in my previous post.

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

That's the thread group name. Always consult the sources when in doubt.

Thread#toString

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

but there is a problem read() return -1 and we assign it to char c

Because you need a value to denote EOF/EOS which is not a valid char. Since -1 is not acceptable for a char (char is unsigned after all), read() returns an int.

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

No, because with Java you can create keyloggers for "Java applications". You would need to implement some sort of Windows API hooks if you want to intercept keystrokes across all applications (at the OS level), which is what keyloggers which we all know of are supposed to do.

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

but it only opens the browser--firefox only--for a second, fills out the iframe, and then automatically closes.

I believe this is because the context manager in this case destroys the browser instance the moment it goes out of scope (i.e. as soon as you exit the with block). You can test this out by removing the with block and using your code like:

browser = Browser()
browser.visit(url)
# other stuff
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

There are two main problems with your above approach:

  1. Using the wrong datastructure
  2. Needless repeated computationss burning the CPU

Contains check on a List data structure is expensive due to its O(n) nature and should be avoided; prefer using a Set variant like HashSet.

The needless computation aspect of this problem is very similar to when you are recursively computing factorials. If you want 5! and you are using the naive approach, you end up computing stuff needlessly an exponential number of times. Try tracing the recursive call 10! on a piece of paper to understand more.

If you log the values passed to the method getNextStone, you'll see it getting called countless times for the same set of inputs. The solution here is to use memoization and remember the result of the computations instead of getting into the recursive death spiral. A small change to your code and it now runs pretty fast IMO.

// Java 8 specific code; you might have to change it
class Solution {

    private static HashSet<Integer> listPossibleValues;

    private static HashSet<String> alreadyComputed = new HashSet<>();

    private static int maxStone;

    private static int cnt = 0;

    public static void main(int n, int a, int b) {
        long start = System.nanoTime();
        getPossibleLastValue(n, a, b);
        System.out.printf("It took %s milliseconds for naive approach%n%n", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start));
    }

    private static void getPossibleLastValue(int n, int a, int b) {
        maxStone = n;
        listPossibleValues = new HashSet<Integer>();
        int stone = 0;
        getNextStone(stone, 0, a, b);
        System.out.println(listPossibleValues.stream().sorted().collect(Collectors.toList()));
        System.out.printf("Count=%s%n", cnt);
    }

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

However, I do get extra points if I can do it one line of code. Just to be clear I would have to replace two different words with two different new words that are in one long line of text.

Is using regex a requirement here? You can do this simply by chaining replace or replaceAll calls since the return the updated result string. Also, when you say single line, does it mean just one regex (and the supporting helper code) or literally a single line?

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

It's branch prediction indeed; read this.

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

The simplest (in terms of effort) solution would be to use the CacheBuilder class provided by Guava (also known as Google collections)

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

Just a quick note for those concerned about privacy issues after getting featured as "member of the month": you have every right to not disclose your age, the organization you work at etc. As long as the interview turns out to be interesting, everyone is happy.

Of course, if you feel that sharing what you like, dislike and your interests/hobbies is not your cup of tea, I can understand. But if you are just concerned about your identity getting disclosed, don't be; I'm pretty sure Davey can take care of that! :)

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

I would recommend http://www.daniweb.com/members/377908/Gribouillis

He is a moderator but still not featured?!

Also the following good chaps in no particular order because of their good contributions, active participation and helpful nature:

  1. http://www.daniweb.com/members/432133/ddanbe
  2. http://www.daniweb.com/members/838005/Schol-R-LEA
  3. http://www.daniweb.com/members/137377/woooee
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You have 4 loops in your algorithm which means if we do a naive Big-O analysis the time complexity becomes O(n^3)/O(n^4) which doesn't scale well as the input size keeps growing.

Not sure why the algorithm has to be so complicated. How about something like:

  1. Accept user input and generate all permutations
  2. Create a set of dictionary entries
  3. Check if the given permutation is in the set and you are done...

The problem with your code is that it's doing a "linear" search for finding a word which is going to be painfully slow, especially given your algorithm. If you don't want to revise your algorithm (i.e. want to keep using the alphabet to word list mapping), go with a Set instead of a linked list and you should see visible speedup.

A few generic comments:

for(int r=0; r<Scrabbulous.scrab.combos.getSize(); r++){

This will basically recompute the size every iteration, not something you want. Instead use:

for(int r=0, len = Scrabbulous.scrab.combos.getSize(); r < len; r++){

Also, this piece of code:

for(int k=0; k<Scrabbulous.scrab.combos.Head.getWord().length(); k++){
    if(currDictionWordList.getNode(j).getWord().charAt(k) != Scrabbulous.scrab.combos.getNode(r).getWord().charAt(k)){
        isSame = false;
    }
}

is basically re-implementing equals method of the String class.

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

In addition, you can run both 32/64 bit Java on 64 bit OS.

The most important property of 64-bit JVM's is that it allows you to have large heaps (4+ GB's) which is not possible with 32-bit JVMs. There are a lot of articles floating around which say that 64 bit apps are faster on 64 bit CPU/OS but at the same time you would find articles saying that running a 32bit JVM on a 64bit OS is much faster.

To conclude, I would rather look at my requirements, do some performance testing and then decide whether the move to 64 bit JVM is justified or not rather than asking strangers on the internet. ;)

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

You need to create a "Dynamic Web Project". This is assuming you have downloaded Eclipse for Java EE.

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

At the bottom of every forum/sub-forum page there is a button which says "Mark Forum Read" (right next to Start New Discussion). That should do the trick.

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

Currently, I am writing it to a .TXT file for ease and convenience. Ideally, I would like to output some of the information so that it is formatted with Italics. I'm thinking that using a RTF file would be simplest but i'm not entirely sure as I have never bothered with this problem.

There are other simpler/lightweight formats out there. For e.g. Markdown, which this site uses for posting is good format if you have modest formatting requirements (italics, underline, bold). Plus it has the advantage of being a format which can be read/viewed without any special viewer (as opposed to RTF files). And if for some reason the users need to view a visual report, there are loads of Markdown to HTML/PDF/XXX converters out there.

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

why i can't change the thread title?

As already mentioned by Jim, you can only change/edit the thread title/contents within 30 mins of posting it. After that, it's a mod/admin only thing.

One thing to note here is that if you for some reason need the thread title to be changed or the content edited a bit (due to typos etc.), you can always "Flag bad post" the first post of that thread and request the moderator/admin to do it for you. This is assuming your request is is accordance with the rules.

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

I don't really use Netbeans but as mentioned in my previous post, you need to run the code in both client and embeddable mode with verbose class loading enabled so find out which drivers are getting used. If what you say is correct, then we should see the same JAR file getting loading in both the scenarios.

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

The error means that the version used to create the db file isn't the same as the derby JAR version you are using to access it. Take a look at this thread and see if updating the JAR file helps. Also, this topic in the Netbeans forum if the previous one doesn't work for you.

To check if you are using the same JAR files in both the modes, dump the class files loaded by the JVM when running the client/embedded code. In both cases, you should see the JAR location from which the Derby class files are getting loaded. Given the error, they should point to different locations. Pass the -verbose:class switch to the JVM before starting it.

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

Can any one please let me know why Data loss happing while reading big files?

Because your readLine call actually reads in a line and increments the file pointer. In your current code, you are basically discarding every other line. You need to assign the result of readLine to a variable (as shown above) and print it out for getting expected behaviour.

JeffGrigg commented: Excellent focused and correct answer. +6
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Look into a library called JAXB. It basically eases the task of XML <-> Java objects conversion. The steps would look something like this:

  1. Analyze the XML file format and create a XSD out of it (this is the difficult part)
  2. Autogenerate classes from XSD using xjc
  3. Load XML file and create objects of out it using the JAXB API
  4. Use JDBC to insert those objects in the database

One tutorial which highlights the steps above is this. Once you have the objects, inserting them into the DB shouldn't be that difficult.

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

Minor comments:

head = 0;
tail = head + (size - 1);

head is unnecessary in the second statement.

throw new java.lang.IllegalArgumentException

java.lang is always imported; remove the full qualification.

    if (size == 0)
        throw new java.lang.NullPointerException("size = 0");

NPE is not the correct exception to throw here; maybe NoSuchElementException?

Your sample method is missing a check wherein head+offset can go beyond tail.

More importantly, why are you calling it circular if the capacity is pretty much unbounded + I don't see any sort of wrapping going on here.

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

That error means that your XML file doesn't conform to the XML schema specified for that particular file. So basically it's trying to say that http:basicAuthSupplier is not a valid child for the element http:conduit. I haven't worked on CXF but you should have a look at this CXF wiki page or look at the XSD schema to check the valid combination.

peter_budo commented: Well done :) +15
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You don't need to call any special function, this sort of functionality is taken care by the JDBC standard. The idea is to specify a special flag called Statement.RETURN_GENERATED_KEYS when creating statements. Look at this answer for more details.

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

URL encoding/decoding rules are different from the HTML ones hence URL decoder should only be used for decoding URLs. HTML encoding uses ampersand encoding (&) whereas URL encoding uses % encoding.

For HTML decoding, the StringEscapeUtils class from Apache commons should be used.

somjit{} commented: good info +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

i don't know how to unescape that sequence into java string..could anyone please help me with this??

That's not how a normal HTML response looks like. If that service is in your control, the first action should be to investigate why you are getting hex encoded HTML entities as opposed to a normal string.

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

umm , im not sure what that meant , the class files were inside the bin , and the bin had itself vanished.

I mean when you realized that you didn't have a bin folder, instead of searching for that folder, you need to search for the .class files. Assuming your Eclipse preference is to build automatically, the class files have to be generated somewhere. If not in bin then in some other folder. Unless of course Eclipse starts acting weird and refuses to generate the class files.

regarding github practices , iv seen some people post onlythe source files , is that good ?

That's the norm; almost always, source control is for source code, config files and scripts. Except in some cases like game development in which assets are checked in too as a backup.

so far , i work alone , and i use eclipse when things get complicated , so i thought of uploading the entire project

Nothing bad about that as long as you know how an ideal project should look like. Just make sure that whenever you are uploading an Eclipse specific project, you:

  • Upload the .project file
  • Upload the .settings folder
  • Skip bin and target folder
  • check if the .classpath file contains absolute paths. If it does, no point in uploading it. Otherwise if it refers relative projects, you can upload it as long as the person checking out that project also checks out the dependent projects.
somjit{} commented: good ans , me wants to give reputaion , hence forced to make a crappy comment :P +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

On a related note, this is one of the reasons why you build an Ant or a Maven project since that way you don't end up uploading IDE specific stuff. Since you are already on Github, search around for other Java projects and look at how they manage project dependencies + structure using something like Maven or Gradle. The Eclips Maven plugin m2e makes it simple to create a Maven project.

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

You almost never push autogenerated class-files to your repository unless it's in the form of a JAR. Even JARs can be avoided by providing relevant ant files or maven files for that particular project in which case the user can just build the entire thing on his own.

For your particular problem, not much can be said without looking at the actual repository but if your "pushed" project to github had some absolute paths somewhere in the config, there can be issues. There are also Eclipse project configurations available which put your generated class files in a different folder as opposed to the default 'bin' folder. That might be one of the reasons. Instead of searching for 'bin' folder, you should have searched for the .class files.

somjit{} commented: valuable info +3
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Definitely a fresh feel as others have mentioned, good job. Few comments from my side:

  1. The starting post of the thread or the OP's post should stand out a bit more. The first time I opened up a new thread, I was searching for the question since the original question looks like some sort of a text ad. Maybe add borders or highlight it somehow?
  2. The page numbers at the bottom of the thread should be placed just after the last post and not after the reply box. This is a big one because if you are not scrolled to the bottom, you might think that this particular thread just has one page whereas it actually might have a lot.
  3. As others have already mentioned, the front forum page is a bit busy and hard to follow with all the tags and icons. There should be at least an easy visual way to identify new and old (read v/s unread) threads. Also, on the main forum listing page (e.g. Java front page), there is a lot of free space in the middle. Maybe you can make good use of that instead of crowding up the left part of the page?
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

r is an instance of ResizingArrayQueue whereas the display method is part of ResizingCircularArray?

stultuske commented: guess I missed the obvious there :) +14
somjit{} commented: *facepalm* to me. +3
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

+1; you are correct indeed. I assumed it was a method call. I'll edit my original post to mention that.

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

EDIT: The below explanation assumes someboundmethod is actually called instead of just storing the method reference in d. If d stores the method reference instead of the result of the method call, foo instance will surely hang around as long as d is reachable.

If there's a class called foo and you do d = foo().someboundmethod, will the instance of foo stil be there?

Still around? Maybe.

It is possible that the someboundmethod might add the foo instance to a global collection in which case it might stick around. Something like:

OBJS = []

class Foo(object):

  def somemethod(self):
    OBJS.append(self)

If not the above case, it might still be around but not reachable. Do note that this depends a lot on the Python implementation in consideration so it's safe to assume that as long as an object is referred by some "live" object, it will stick around. If not, it it bound to get garbage collected sooner or later.

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

Just ensure that if you need to replace the literal -, it is always either at the start or at the end of the replacement set. For e.g. txt.replaceAll("[- _?]", "*") works, txt.replaceAll("[ _?-]", "*") also works but txt.replaceAll("[ _-?]", "*") doesn't.

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

When I say the "throw clause" I mean something like

Don't call it "throw", call it "throws" clause. You use throw when you want to throw a new exception i.e. create an actual exception object. Something like:

public void transfer() throws TransferFailedException { // this is the *throws* clause
    if(account1.transferTo(account2).hasFailed()) {
      throw new TransferFailedException(); // this is the *throw* clause
    }
}

and be able to say something like "Oh ok, so nextInt() can't have a throw clause the same way as the intDivide() method can"

Generally speaking, the possible exceptions thrown by a method are documented in the Javadoc. If it's not in the Javadoc, you have no easy way of knowing all the possible exceptions a given method can throw except for diving deep into the source code. For e.g. a lot of standard library methods can throw a NullPointerException if presented with a null input but don't mention it in the Javadocs like Pattern.compile.

So to conclude, just hop over to the Javadocs for finding exception related information for a given method or use an IDE which provides all the details. If a method throws a "checked exception", the compiler will anyways warn you (by asking you to either handle it or propagate it up the call-stack).

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

Firstly, read this: checked v/s unchecked exceptions

in line 10 the method quotient throws an exception that will be caught by the catch statement

Wrong phrasing; there is a possibility that the method quotient might throw an exception. When a method has a throws clause, it means that the method might throw that particular exception (you can have multiple exceptions but you get the point). The most confusing part with exceptions is that when you are dealing wiht unchecked exceptions (i.e. exceptions which extend the RuntimeException class), you are free to omit the throws declaration when defining methods. But, the important point is that the method can still throw an exception. As an example:

public int intDivide(int a, int b) {
  return a / b;
}

public int intDivide(int a, int b) throws ArithmeticException {
  return a / b;
}

Take a look at the methods defined above; what difference do you see? The only difference is that the second method explicitly mentions/states/informs the method consumer/user that intDivide can throw an exception. Notice that all this is orthogonal to the fact that both of them will throw an exception when passed b=0. It's just that the second method mentions it explicitly but the first one doesn't. Why is this possible? Because ArithmeticException is an uncheked exception.

Now let's consider the example of a checked exceptions:

// invalid
public int readFromFile(InputStream in) {
  return in.read();
}

// valid; works
public int readFromFile(InputStream in) throws …
iamthwee commented: solid +14