Skip to content
Advertisement

Tag: methods

How do I execute a method at a particular time in java?

Is there any way to write a program in java, so that its main method schedule (or at a 10-15 min interval) another method to executes it at a particular interval? Answer I think you are looking for the Time class. See Timer Class API You can use this class like: You want to perform a Method every 600 miliseconds.

Working on an RPN calculator code assignment in Java

This is my second programming class and I am new to Java. I have been working on my first assignment and it involves classes and methods. I know very little about these topics and find myself lost. My assignment asks me to create a RPN calculator that asks the user for two numbers and an operator. The calculator performs the

What is addNotify();?

I’ve tried to find a laymans definition of addNotify() but I can’t really get any answer using Google. As far as I know, when overriding addNotify() in my class, I should call super.addNotify(); and then do whatever else afterward. My question is, does addNotify() run automatically? What is it’s purpose and what happens when I override it and furthermore, why

Why does this Java method appear to have two return types?

where Foo is my own class. What is the return type of this method? Why does it seem to have two return types? Answer No, you don’t have two return types. It’s a generic method you are seeing. <E extends Foo> → You are declaring a generic type for your method; List<E> → This is your return type. Your method

What does .class mean in Java?

What does .class mean in Java? For example, if I created a class called Print. What does Print.class return? Answer When you write .class after a class name, it references the class literal – java.lang.Class object that represents information about a given class. For example, if your class is Print, then Print.class is an object that represents the class Print

How To Check If A Method Exists At Runtime In Java?

How would one go about checking to see if a method exists for a class in Java? Would a try {…} catch {…} statement be good practice? Answer I assume that you want to check the method doSomething(String, Object). You might try this: This will not work, since the method will be resolved at compile-time. You really need to use

Count words in a string method?

I was wondering how I would write a method to count the number of words in a java string only by using string methods like charAt, length, or substring. Loops and if statements are okay! I really appreciate any help I can get! Thanks! Answer

Advertisement