Shutting Down PC with few lines of Code using Java and Python
The Very Common and Creative use of Programming Languages is done rarely and those who do it are only the true learners of programming. Sometimes "Programming" is an Emotion. We Convert our Human Ideas into a Few Line of Codes and Execute them. There are many Program Codes by you can shut down your system. But here we are going to see "How to shut down PC using Java and Python".
The OS Module of Python is used in different types of tasks which are based on operating system. In Java, we will create a class and write some code with timer to shut down the pc.
As I told, We Convert our Human Ideas into a Few Line of Codes and Execute them. There are many Program Codes by you can shut down your system.
Python and Java both programming languages are strong enough to perform this task through operating system.
This you can call a creative use of programming languages; may use for project implementation. As I told Programming refers to conversion of Human Ideas into Machine Language.
I suggested holding a "Python Object Oriented Programming Seminar", but the acronym was unpopular. - Joseph Strout
So, Let's get started with the Line of Code - Using Python and Java.
Source Code - (Shut Down using Python)
import os
def shutdown_PC():
os.system("shutdown /s /t 1")
shutdown_PC()
So, this was the Code for Shutting Down PC using Python Programming. As it's a very short code and that's a specialty of python. The code just get short when it comes to python and gets longer when it comes towards java. Similar to it we have written a top pick on What Ahead in Career - Python or Java.
Immutable objects are also safer. Passing a mutable object to untrusted code, or otherwise publishing it where untrusted code could find it, is dangerous — the untrusted code might modify its state, or, worse, retain a reference to it and modify its state later from another thread. On the other hand, immutable objects cannot be subverted in this manner by malicious or buggy code, so they are safe to share and publish freely without the need to make defensive copies. -Brian Goetz, Java Concurrency in Practice
So, moving toward java, we'll need to create a class, so I'll name the class as ShutdownComputer
Source Code - (Shut Down using Java)
public class ShutdownComputer {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
System.out.println("Time in Seconds: ");
Double timeInSeconds = scanner.nextDouble();
Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec("shutdown -s -t " + timeInSeconds);
System.exit(1);
}
}
So, this was the creative code based on Shutting Down your Computers using Python and Java.
For More Creativeness - I Recommend you to Read "How to Calculate the Execution Time of a Python Program and Create Acronyms"
As we all know Python and Java both are top industry level languages. Some Ups and Down are found, but later it becomes a choice of interest to opt in.