Object Oriented Programming Articles

Page 583 of 589

How to convert a byte array to a hex string in Java?

Abhinaya
Abhinaya
Updated on 30-Jul-2019 687 Views

The printHexBinary() method of the DatatypeConverter class accepts a byte array and returns a hex string.Exampleimport javax.xml.bind.DatatypeConverter; public class ByteToHexString { public static void main(String args[]) { String sam = "Hello how are you how do you do"; byte[] byteArray = sam.getBytes(); String hex = DatatypeConverter.printHexBinary(byteArray); System.out.println(hex); } }Output48656C6C6F20686F772061726520796F7520686F7720646F20796F7520646F

Read More

How to declare a class in Java?

mkotla
mkotla
Updated on 30-Jul-2019 14K+ Views

Following is the syntax to declare a class. class className { //Body of the class } You can declare a class by writing the name of the next to the class keyword, followed by the flower braces. Within these, you need to define the body (contents) of the class i.e. fields and methods.To make the class accessible to all (classes) you need to make it public. public class MyClass { //contents of the class (fields and methods) }

Read More

Why do Java array declarations use curly brackets?

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

Curly brackets usually denote sets and ensembles while parenthesis usually in most Algol-based programming languages curly braces are used to declare arrays.

Read More

Why are classes sometimes declared final in Java?

Sreemaha
Sreemaha
Updated on 30-Jul-2019 686 Views

If a class is declared final, you cannot inherit it. If you try it gives you a compile-time error as − Example final class Super { private int data = 30; } public class Sub extends Sub { public static void main(String args[]){ } } Output Exception in thread "main" java.lang.Error: Unresolved compilation problem: at Sub.main(Sub.java:7)

Read More

What is a composition in Java?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 30-Jul-2019 446 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

What is the difference between compositions and aggregations in Java?

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

In Aggregation relationship among classes by which a class (object) can be made up of any combination of objects of other classes. It allows objects to be placed directly within the body of other classes.A 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

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 a method in Java that ends in a semicolon and has no method body?

Sharon Christine
Sharon Christine
Updated on 30-Jul-2019 872 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

What is Callable interface in Java?

Sharon Christine
Sharon Christine
Updated on 30-Jul-2019 1K+ Views

The Callable interface is found in the package java.util.concurrent. The Callable object can return the computed result done by a thread in contrast to a runnable interface which can only run the thread. The Callable object returns a Future object which provides methods to monitor the progress of a task being executed by a thread. The future object can be used to check the status of a Callable and then retrieve the result from the Callable once the thread is done. It also provides timeout functionality.

Read More

What is the difference between Component class and Container class in Java?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 4K+ Views

The class Component is the abstract base class for the non-menu user-interface controls of AWT. A component represents an object with graphical representation. The class Container is the superclass for the containers of AWT. The container object can contain other AWT components.

Read More
Showing 5821–5830 of 5,881 articles
« Prev 1 581 582 583 584 585 589 Next »
Advertisements