Programming Articles

Page 2540 of 2545

Is it necessary that a try block should be followed by a catch block in Java?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 725 Views

Not necessarily catch, a try must be followed by either catch or finally block. Example import java.io.File; public class Test{ public static void main(String args[]){ System.out.println("Hello"); try{ File file = new File("data"); } } } Output C:\Sample>Javac Test.java Test.java:5: error: 'try' without 'catch', 'finally' or resource declarations try{ ^ 1 error

Read More

What are checked exceptions in Java?

Swarali Sree
Swarali Sree
Updated on 30-Jul-2019 986 Views

A checked exception is an exception that occurs at the time of compilation, these are also called as compile time exceptions. These exceptions cannot simply be ignored at the time of compilation; the programmer should take care of (handle) these exceptions. if you use FileReader class in your program to read data from a file, if the file specified in its constructor doesn't exist, then a FileNotFoundException occurs, and the compiler prompts the programmer to handle the exception. Example import java.io.File; import java.io.FileReader; public class FilenotFound_Demo { public static void main(String args[]) { ...

Read More

What is a JAR file?

varun
varun
Updated on 30-Jul-2019 3K+ Views

A java archive file is a file format/ archiving tool which contains all the components of an executable Java application. All the predefined libraries are available in this format. To include any of these (other than rt.jar) in to your project you need to set the class path for this particular JAR file. You can create a JAR file using the command line options or using any IDE’s. Creating a Jar file You can create a Jar file using the jar command as shown below. jar cf jar-file input-file(s) Let us consider an example, create a Sample Java ...

Read More

What are native methods in Java and where are they used?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 2K+ Views

A native method in Java is a method whose implementation is written in other languages such as c and c++. The ‘native’ keyword is used before a method to indicate that it is implemented in other language.

Read More

What is the difference between a Java method and a native method?

Swarali Sree
Swarali Sree
Updated on 30-Jul-2019 677 Views

A native method is the one whose method implementation is done in other languages like c++ and Java. These programs are linked to Java using JNI or JNA interfaces. The difference between normal method and native method is That the native method declaration contains native keyword and, the implementation of the method will be other programming language. Example Tester.java public class Tester { public native int getValue(int i); public static void main(String[] args) { System.loadLibrary("Tester"); System.out.println(new Tester().getValue(2)); ...

Read More

Is it possible to use Python modules in Octave?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 30-Jul-2019 367 Views

There is no straightforward way to do this. But it is possible to run a Python program and parse the output. You can execute any shell command using the function system (cmd, flag). The second argument is optional. If it is present, the output of the command is returned by system as a string. If it is not supplied, any output from the command is printed, with the standard output filtered through the pager. For example,output = system ("python /path/to/your/python/script.py", 1)

Read More

What is a method in Java that ends in a semicolon and has no method body?

Sharon Christine
Sharon Christine
Updated on 30-Jul-2019 857 Views

An abstract method is the one which has no definition and declared abstract. In short, an abstract method contains only method signature without body. To use this method, you need to inherit this method by extending the class and provide the method definition. Example public abstract class Employee{ private String name; private String address; private int number; public abstract double computePay(); }

Read More

How to prohibit a Python module from calling other modules?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 30-Jul-2019 296 Views

You can use "Sandboxed Python". A "Sandboxed Python" would let you permit or forbid modules, limit execution slices, permit or deny network traffic, constrain filesystem access to a particular directory (floated as "/"), and so on. It is also referred to as RestrictedExecution. There are many ways to implement sandboxing on Python. You could Modify the CPython Runtime, Use Another Runtime, Use Operating System Support, etc to implement such a sandbox. You can read more about sandboxing at: https://wiki.python.org/moin/SandboxedPythonPypi has a package called RestrictedPython(https://pypi.python.org/pypi/RestrictedPython) that is a defined subset of the Python language which allows to provide a program input ...

Read More

What are number format exceptions in Java?

Sai Subramanyam
Sai Subramanyam
Updated on 30-Jul-2019 261 Views

This Exception happens once you associated convert a string variable in an incorrect format to a whole number (numeric format) that's not compatible with one another. Example public class Test { public static void main(String[] args) { int data = Integer.parseInt("hello"); } } Output Exception in thread "main" java.lang.NumberFormatException: For input string: "hello" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at a6.dateAndTime.Test.main(Test.java:5)

Read More

What is the difference between javac, java commands?

Sreemaha
Sreemaha
Updated on 30-Jul-2019 8K+ Views

The javac command is used to compile Java programs, it takes .java file as input and produces bytecode. Following is the syntax of this command. >javac sample.java The java command is used to execute the bytecode of java. It takes byte code as input and runs it and produces the output. Following is the syntax of this command. >java sample Let us consider an example create a Sample Java program with name Sample.java Sample.java public class Sample { public static void main(String args[]) { System.out.println("Hi welcome ...

Read More
Showing 25391–25400 of 25,445 articles
Advertisements