Found 9326 Articles for Object Oriented Programming

What is the difference between PATH and CLASSPATH in Java?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:20

664 Views

Before running Java programs on your machine you need to set two environment variables namely, PATH − The path environment variable is used to specify the set of directories which contains executional programs. When you try to execute a program from command line, the operating system searches for the specified program in the current directly, if available, executes it. In case the programs are not available in the current directory, operating system verifies in the set of directories specified in the ‘PATH ’ environment variable. CLASSPATH − The class path environment variable is used to specify the location of the ... Read More

What is the Eclipse keyboard shortcut for "System.out.println()" in Java?

Govinda Sai
Updated on 30-Jul-2019 22:30:20

11K+ Views

To get System.out.println() line in eclipse without typing the whole line type sysout and press Ctrl + space.

What is the Eclipse keyboard shortcut for "public static void main(String[] args) " in Java?

Ramu Prasad
Updated on 20-Feb-2020 05:29:13

7K+ Views

To get public static void main(String[] args) line in eclipse without typing the whole line type main and press Ctrl + space then, you will get the option for the main method select it.

Does Java support default parameter values for a method?

Sravani S
Updated on 16-Jun-2020 11:12:26

2K+ Views

Java does not support the concept of default parameter however, you can achieve this usingMethod overloadingUsing method overloading if you define method with no arguments along with parametrized methods. Then you can call a method with zero arguments.Variable argumentsIn Java methods parameters accept arguments with three dots. These are known as variable arguments. Once you use variable arguments as a parameter method, while calling you can pass as many number of arguments to this method (variable number of arguments) or, you can simply call this method without passing any arguments.ExampleLive Demopublic class Sample {    void demoMethod(String... args) {   ... Read More

Can we define an interface inside a Java class?

Sravani S
Updated on 16-Jun-2020 11:20:18

6K+ Views

Yes, you can define an interface inside a class and it is known as a nested interface. You can’t access a nested interface directly; you need to access (implement) the nested interface using the inner class or by using the name of the class holding this nested interface.ExampleLive Demopublic class Sample {    interface myInterface {       void demo();    }    class Inner implements myInterface {       public void demo() {          System.out.println("Welcome to Tutorialspoint");       }    }    public static void main(String args[]) {       Inner obj ... Read More

Can we define a class inside a Java interface?

V Jyothi
Updated on 20-Feb-2020 05:46:54

6K+ Views

Yes, you can define a class inside an interface. In general, if the methods of the interface use this class and if we are not using it anywhere else we will declare a class within an interface.Exampleinterface Library {    void issueBook(Book b);    void retrieveBook(Book b);    public class Book {       int bookId;       String bookName;       int issueDate;       int returnDate;    } } public class Sample implements Library {    public void issueBook(Book b) {       System.out.println("Book Issued");    }    public void retrieveBook(Book b) { ... Read More

What is the use of marker interfaces in Java?

Johar Ali
Updated on 30-Jul-2019 22:30:21

394 Views

An interface with no methods in it is referred to as a tagging interface. There are two basic design purposes of tagging interfaces -Creates a common parent As with the EventListener interface, which is extended by dozens of other interfaces in the Java API, you can use a tagging interface to create a common parent among a group of interfaces. For example, when an interface extends EventListener, the JVM knows that this particular interface is going to be used in an event delegation scenario.Adds a data type to a classThis situation is where the term, tagging comes from. A class that ... Read More

How to truncate a file in Java?

Swarali Sree
Updated on 20-Feb-2020 09:55:21

982 Views

The flush() method of the FileWriter class flushes the contents of the file. You can use this method to truncate a file.Exampleimport java.io.File; import java.io.FileWriter; public class FileTruncate {    public static void main(String args[]) throws Exception {       File file = new File("myData");       FileWriter fw = new FileWriter(file, false);       fw.flush();       System.out.println("File truncated");    } }OutputFile truncated

How to open a plain text file in Java?

Samual Sam
Updated on 20-Feb-2020 09:54:30

238 Views

You can access a plain text using the File class.ExampleLive Demoimport java.io.File; public class ReadFile {    public static void main(String[] args) {       File f = null;       String str = "data.txt";       try {          f = new File(str);          boolean bool = f.canExecute();          String a = f.getAbsolutePath();          System.out.print(a);          System.out.println(" is executable: "+ bool);       } catch (Exception e) {          e.printStackTrace();       }    } }Output C:\Users\data is executable: true

How to create a pdf file in Java?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:20

2K+ Views

You can create a PDF file using the PDF Box library. You can set the environment for pdf box by following Pdf Box Environment Tutorial. Example import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; public class CreatingEmptyPdf { public static void main(String args[]) throws IOException { PDDocument document = new PDDocument(); document.addPage(new PDPage()); document.save("C:/pdfBox/BlankPdf.pdf"); System.out.println("PDF created"); document.close(); } } Output PDF created

Advertisements