Programming Articles

Page 2546 of 2547

Are 'this' and 'super' keywords in Java?

Prabhas
Prabhas
Updated on 30-Jul-2019 451 Views

Yes, this and super are keywords in Java. Where ‘this’ is used as a reference of the current object and, ‘super’ is used as a reference to the superclass object.

Read More

Is main a keyword in Java?

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

No, main is not a keyword in Java.

Read More

Is null a keyword in Java?

usharani
usharani
Updated on 30-Jul-2019 657 Views

No, null is not a keyword. Though they seem like keywords null, true and, false are considered as literals in Java.

Read More

How to add items to an array in java dynamically?

Ankitha Reddy
Ankitha Reddy
Updated on 30-Jul-2019 11K+ Views

Since the size of an array is fixed you cannot add elements to it dynamically. But, if you still want to do it then, Convert the array to ArrayList object.Add the required element to the array list.Convert the Array list to array.Exampleimport java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class AddingItemsDynamically {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter the size of the array :: ");       int size = sc.nextInt();       String myArray[] = new String[size];       System.out.println("Enter elements of the array ...

Read More

How (where) are the elements of an array stored in memory?

Priya Pallavi
Priya Pallavi
Updated on 30-Jul-2019 2K+ Views

In Java, arrays are objects, therefore just like other objects arrays are stored in heap area. An array store primitive data types or reference (to derived data) types Just like objects the variable of the array holds the reference to the array.

Read More

How to convert BLOB to Byte Array in java?

Ramu Prasad
Ramu Prasad
Updated on 30-Jul-2019 8K+ Views

You can contents of a blob into a byte array using the getBytes() method.Exampleimport java.awt.Image; import java.awt.image.BufferedImage; import java.sql.Blob; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Arrays; public class BlobToByteArray { public static void main(String[] args) throws Exception { Image image = new BufferedImage(300, 400, BufferedImage.TYPE_INT_RGB); String JDBC_DRIVER = "com.mysql.jdbc.Driver"; String DB_URL = "jdbc:mysql://localhost/mydb"; String USER = "root"; String PASS = "password"; ...

Read More

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

Abhinaya
Abhinaya
Updated on 30-Jul-2019 665 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 732 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

How to access the members of a class from another class in Java?

radhakrishna
radhakrishna
Updated on 30-Jul-2019 13K+ Views

To access the members of a class from other class. First of all, import the class. Create an object of that class. Using this object access, the members of that class. Suppose there is a class in a package called myPackage with a method named display() package myPackage; public class Sample { public void display() { System.out.println("Hello"); } } You can access it as. import myPackage; public class MyClass { public static void main(String args[]) { Sample s = new Sample(); s.done(); } } Output hello

Read More
Showing 25451–25460 of 25,467 articles
Advertisements