Programming Articles

Page 2539 of 2546

Can interfaces have constructors in Java?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 798 Views

No, interfaces can’t have constructors for the following reasons − All the members of an interface are abstract, and since a constructor cannot be abstract. Still, if you try to write a constructor within an interface it will generate a compile time error. Example public interface InterfaceTest { InterfaceTest(){ } public abstract void display(); public abstract void show(); } Error C:\Sample>javac InterfaceTest.java InterfaceTest.java:2: error: expected public InterfaceTest(){ ^ 1 error

Read More

Can constructors be inherited in Java?

Monica Mona
Monica Mona
Updated on 30-Jul-2019 4K+ Views

No, constructors cannot be inherited in Java. In inheritance sub class inherits the members of a super class except constructors. In other words, constructors cannot be inherited in Java therefore, there is no need to write final before constructors. Example public interface InterfaceTest { public InterfaceTest(){ } public abstract void display(); public abstract void show(); } Still, if you try to write constructors in an interface it will generate a compile time error. Error C:\Sample>javac InterfaceTest.java InterfaceTest.java:2: error: expected InterfaceTest(){ ^ 1 error C:\Sample>

Read More

What is the difference between a String object and a StringBuffer object in java?

Rishi Raj
Rishi Raj
Updated on 30-Jul-2019 469 Views

String class is immutable once you create an object of string you can modify its data.The StringBuffer class is immutable, once you create a StringBuffer object you can change/modify the contents of it.This class provides various methods to manipulate its data such as append(), delete(), insert() etc.

Read More

How many public classes of the same name it can have in Java?

Swarali Sree
Swarali Sree
Updated on 30-Jul-2019 2K+ Views

A Java file contains only one public class with a particular name. If you create another class with same name it will be a duplicate class. Still if you try to create such class then the compiler will generate a compile time error. Example public class Example { } public class Example{ public void sample(){ System.out.println("sample method of the Example class"); } public void demo(){ System.out.println("demo method of the Example class"); } ...

Read More

What are the prerequisites for learning Java?

vanithasree
vanithasree
Updated on 30-Jul-2019 2K+ Views

In fact, you can directly start learning Java without any prior knowledge of programming language. But, the syntax in Java is similar to the syntax of the C programming language, therefore, Knowing C language helps to get hold of Java quickly. Having introduced to object-oriented principles before starting Java, also helps in the understanding of the language so, having an idea on object-oriented languages such as C++ also helps. In short, if you know C or C++ it will be a little bit easier to cope with Java technology.

Read More

What is the difference between Object oriented programming and Object based programming?

Prabhas
Prabhas
Updated on 30-Jul-2019 21K+ Views

Many of us have a misconception that Java script is an object oriented language. But, the truth is Java Script is an Object Based Language. Object Based languages are different from Object Oriented Languages: Object Based Languages Object based languages supports the usage of object and encapsulation. They does not support inheritance or, polymorphism or, both. Object based languages does not supports built-in objects. Javascript, VB are the examples of object bases languages. Object Oriented Languages Object Oriented Languages supports all the features of Oops including inheritance and polymorphism. They support built-in objects. C#, Java, VB. Net ...

Read More

What is a composition in Java?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 30-Jul-2019 435 Views

The composition is also a type of aggregation where the relationship is restrictive i.e. If two objects are in composition, the composed object will not exist without the other.

Read More

How to create a string from a Java ArrayList?

George John
George John
Updated on 30-Jul-2019 14K+ Views

To convert the contents of an ArrayList to a String, create a StringBuffer object append the contents of the ArrayList to it, finally convert the StringBuffer object to String using the toString() method. Example import java.util.ArrayList; public class String_ArrayList { public static void main(String args[]) { ArrayList al = new ArrayList(); al.add("Hello"); al.add("are"); al.add("you"); StringBuffer sb = new StringBuffer(); for (String s : al) { sb.append(s); sb.append(" "); } String str = sb.toString(); System.out.println(str); } } Output Hello are you

Read More

How to print new line in Java?

Sai Subramanyam
Sai Subramanyam
Updated on 30-Jul-2019 2K+ Views

The java.io.PrintStream.println() method prints an array of characters and then terminate the line. This method behaves as though it invokes print(char[]) and then println(). Using this method you can print the data on the console. import java.io.*; public class PrintStreamDemo { public static void main(String[] args) { char[] c = {'a', 'b', 'c'}; // create print stream object PrintStream ps = new PrintStream(System.out); // print an array and change line ps.println(c); ps.print("New Line"); // flush the stream ps.flush(); } } Output abc New Line

Read More

What are the different build tools in Java?

Ankitha Reddy
Ankitha Reddy
Updated on 30-Jul-2019 266 Views

"On a mean, a developer spends a considerable quantity of your time doing mundane tasks compiling the code, packaging the binaries, deploying the binaries to the checkserver, testing the changes," copying the code from one location to another. To automate and simplify these tasks we can use build tools like Ant, Maven, Gradle etc.

Read More
Showing 25381–25390 of 25,451 articles
Advertisements