[Solved] Runtime object creation in java [closed]

Yes reflection can provide dynamic object creation(on fly ) Class anonymous = Class.forName(“CLass name”); anonymous.getInstance(); All objects are created at Runtime in java. 10 solved Runtime object creation in java [closed]

[Solved] Don’t understand the usage thing in java

The String args[] parameter of your main method is an array of Strings which indexes can be filled when you’re executing your program from the command line. Here is how to do it in from your command line : javac GuessingGame.java // This will compile your Java code file java GuessingGame one two three // … Read more

[Solved] What does mean, lines.next.toInt in Java [closed]

You can get this done in java using any reader. e.g- BufferedReader, FileReader anything like this. public class InJava { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); // //in main() public static void main(String [] args) { Object obj= br.readLine(); } } If you are using a list use Iterator. public class InJava { List<double> lst= new … Read more

[Solved] Syntax error on eclipse [closed]

Change insert to : private Node insert(Node node, int data) { if (node == null) { node = new Node(data); } else { if (data <= node.data) { node.left = insert(node.left, data); } else { node.right = insert(node.right, data); } } return (node); } In eclipse : Press Ctrl + a and then Ctrl+shift+f to … Read more

[Solved] How to reduce memory leak in java?

lets analyze a few of the the possible error messages: java.lang.OutOfMemoryError: Java heap space java.lang.OutOfMemoryError: PermGen space java.lang.OutOfMemoryError: Requested array size exceeds VM limit java.lang.OutOfMemoryError: request <size> bytes for <reason>. Out of swap space? java.lang.OutOfMemoryError: <reason> <stack trace> (Native method) Here’s the MemLeak class: package com.post.memory.leak; import java.util.Map; public class MemLeak { public final String … Read more

[Solved] How to convert every other character to upper case in a string [closed]

If you want to get the uppercase of a char, you should use Character.toUpperCase(c), not String’s toUpperCase. So, I think you might be looking for something like this: public static void main(String[] args) { String alphabet = “abcdefghijklmnopqrstuvwxyzåäö”; System.out.println(alphabet); StringBuilder sb = new StringBuilder(); for (int i = 0; i < alphabet.length(); i++) { char … Read more

[Solved] Optimizing thread calls in Java [closed]

Use a loop and an ExecutorService. ExecutorService executor = Executors.newCachedThreadPool(); for (int i = 0; i < count; i++) { executor.execute(new TokenStarter()); } That should recreate your code, but is not optimal. You probably want to limit the amount of threads that run concurrently: ExecutorService executor = Executors.newFixedThreadPool(desiredParallelism); solved Optimizing thread calls in Java [closed]

[Solved] How to access a string in a void method from another void method? [closed]

You need to pass it as a parameter or create a “global variable” IE you could do either of the following… public void methodOne(String string){ System.out.println(string); } public void methodTwo(){ String string = “This string will be printed by methodOne”; methodOne(string); } OR (a better solution) Create a global variable under the class declaration… public … Read more

[Solved] Java- Overloading and Overriding Concept

To find out for yourself what is happening exactly, you could run your code in a debugger and step through it to see what happens step by step. This is what happens: When you create a new Derived object, the field value in the Base part is first initialized to 0. Then the constructor of … Read more