Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Can anyone tell me how to write a java program that print itself without using file IO. I googled a lot, but I can't find the exact answer. I found some useful tips here . Is there any way to write self print program without using file IO ?
Here you can find many implementations, the first by Bertram Felgenhauer follows:
class S{public static void main(String[]a){String s="class S{public static void main(String[]a){String s=;char c=34;System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}}";char c=34;System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}}
By the way, this is known as a quine, a program whose output is itself.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I read in an online article that in java, the program file name should be same as class name. Why is that?
Also in c# i read that program file name need not be same as class name. Why?
Can someone please explain the difference?
Here is a link to the article:
https://www.tutorialspoint.com/csharp/csharp_program_structure.htm
A Java class file can contain multiple classes and you can name them whatever you want.
But ideally, following the best practices, it is better to write one class per file and name the file as per the name of the Class.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
For example in some Java programs we use main method at below the class
in some Java programs we use main method after at writing methods what is the difference?
There is no difference if we write main method first or last. All the java programs starts the execution from the main class and it is independent from position (first or last).
there is no different, but you have to put all methods in a class...
you can read the manual :-) https://docs.oracle.com/javase/tutorial/getStarted/application/
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
is there any way to search all methods in Java class with regex?
(public|protected|private|static|\s) +[\w\<\>\[\]]+\s+(\w+) *\([^\)]*\) *(\{?|[^;])
With this you can, but search before ask, because i only have used the search to find this answer ^^.
I think you're looking for reflection - see this tutorial for help. Only through reflection can you access information about loaded classes - unless you're thinking of loading in the .java file and analyzing its text.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am currently working on a project where I found this syntax:
Method m = bluetoothDevice.getClass().getMethod("createBond", (Class[]) null);
What is the purpose of "Method" class in Java and why we use it? Please elaborate with an example
Thanks in advance!
PS: I already saw the Java docs but not able to understand it.
The Method class is part of the "reflection" API which is about meta-programming. That means you can deal with structures of your program as data and process it in a java program. This allows flexible generic or abstract solutions. Method itself just represents a method in a Java class. There are other classes representing other parts of Java programs, too (e.g. Class).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm beginner in java
I need to know more about
button.setActionCommand(String command)
I need a command that read variable value, or read integers from text file
thanx in advance
Here's all you need to know about the setActionCommand() method in a Button, in the javadocs. Now that we're at it, I'd rather recommend you use JButton instead.
And please check a tutorial, it's the best you can do when you're learning a new programming language.