Get access to the calculator with java [closed] - java

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 1 year ago.
Improve this question
I'm working on a java project and I want to attach a calculator from the operating system. But I haven't any idea to do that. If there any idea it would be a great help.

You can use
java.lang.Runtime.getRuntime().exec("[path]\calc.exe");
To open the calculator. But beware: The only way that you can communicate with applications you open this way is through the Process streams: in/out/err (assuming calc is set up to communicate as such)

in cmd you can type calc.exe and run it, to run calculator through the java use the java.lang.Runtime class to run commands:
try {
Runtime.getRuntime().exec("calc.exe");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
more details about Shell Commands in java read this...

Related

Selenium Negative Test Cases to execute in "for" loop [closed]

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 2 years ago.
Improve this question
I want the "for" loop to keep executing even after the error occurs in Selenium java using negative test cases in an "if" "else"if-else statement. Some examples would really be helpful.
Use try Catch inside for loop.
for(int i=0;i<=10;i++){
try{
//your goes code here
}catch(Exception e){
System.out.println("Exception thrown "+e);
}
}

How to convert batch to exe programmatically [closed]

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 6 years ago.
Improve this question
I want to know how I can convert a .bat file to a .exe file programmatically in Java, I'mm trying to make a Batch IDE.
Thanks!
Here is a snippet of code that I found online:
public static void main(String[] args) {
try {
Runtime.getRuntime().exec("c:\\executable.exe");
Runtime.getRuntime().exec("cmd /c c:\\batch_file.bat");
} catch (IOException e) {
}
}
More information on this topic can be found here.

Extract Try/Catch blocks - Microsoft convention/standard [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm reading the book 'Clean Code' of Robert C. Martin and he strongly recommend to "extract the bodies of the try and catch blocks out into functions of their own"
Here is the book example, to make it clear:
public void delete(Page page)
{
try
{
deletePageAndAllReferences(page);
}
catch (Exception e)
{
logError(e);
}
}
private void deletePageAndAllReferences(Page page) throws Exception {
deletePage(page);
registry.deleteReference(page.name);
configKeys.deleteKey(page.name.makeKey());
}
private void logError(Exception e) {
logger.log(e.getMessage());
}
The reasons to do that are:
try/catch blocks confuse the structure of the code and mix error processing with normal processing
nice separation that makes the code easier to understand and modify.
The thing is, I've been working for a few years over several project and this never was a rule, and I didn't find people who follow this even in environments where they really care about clean code.
So I want to know:
The book examples are based on Java and I'm working with C#/.NET, there is any standard or convention coming from Microsoft of from the .NET community about this?
One reason that I can think of is what if the catch block had more than one line to it. For example if you were logging the error, sending a notification email, and rolling back a database transaction or something. If you start adding other things to the catch block you'll find yourself having to repeat code.

Java self print program without file io [closed]

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.

How would i play a specific song in iTunes through java? [closed]

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 4 years ago.
Improve this question
How would i play a specific song in iTunes through java?
I assume I need to somehow connect to iTunes and use the play function with a certain parameter....Can anyone point me in the right direction to learning how to do this?
According to that answer, there is no API. There is only an SDK (via COM) for Windows.
In Mac OS, iTunes is controlled via AppleScript(example).
Ik it's too late, but u can use apple script editor. for instance,
Runtime runtime = Runtime.getRuntime();
String[] args = {"osascript" , "-e" , "tell application \"iTunes\" to play"};
try{
Process process = runtime.exec(args);
}catch (Exception ex) {
}
this will play a song in itunes

Categories