Found 9326 Articles for Object Oriented Programming

The most elegant ways to iterate the words of a java string.

Sreemaha
Updated on 24-Feb-2020 10:25:38

2K+ Views

Just split the string based on space and then iterate it. See the example below −Examplepublic class Tester {    public static void main(String[] args) {       String test = "I love learning Java";       String[] subStrings = test.split(" ");       for(String subString: subStrings) {          System.out.println(subString);       }    } }OutputI love learning Java

Loop through an array in Java

radhakrishna
Updated on 24-Feb-2020 10:19:29

187 Views

Following example shows how to loop through an array using a foreach loop.public class Tester {    public static void main(String[] args) {       int[] dataArray = {1, 2, 3, 4};       for(int i: dataArray) {          System.out.println(i);       }    } }

How do we compare String in Java

Giri Raju
Updated on 30-Jul-2019 22:30:21

166 Views

https://www.tutorialspoint.com/javaexamples/string_compare.htm

Why is char[] preferred over String for storing passwords?

Sreemaha
Updated on 24-Feb-2020 10:31:39

130 Views

Yes, Storing password in String object is not safe for following reasons −String objects are immutable and until garbage collected, they remain in memory.String being plain text can be tracked in memory dump of the application.In log, String based password may be printed which can cause a problem.Char[] can be cleared or wiped out after the job is done.

Why use Java annotations?

varma
Updated on 24-Feb-2020 10:15:44

262 Views

Annotations provide information about java elements. Annotations can be interpreted by compiler or IDE at compile time or by JVM at runtime. Annotations can be usedto show attributes of an element: e.g. @Deprecated, @Override, or @NotNullto describe the purpose of an element of the framework, e.g. @Entity, @TestCase, @WebServiceto describe the behavior of an element: @Statefull, @TransactionBefore Java 5, XML was primarily used to store information about java objects, with annotations, this information can be stored within the java code itself.

How to call C++ functions from Java?

varun
Updated on 10-Feb-2020 10:51:32

1K+ Views

Following are the steps to use native methods.Create a header file (.h file) for a CPP program.Create CPP fileCreate a DLLIn java code, declare the method as native, load the DLL using System.loadLibrary() method and call the method.

What are native methods in Java and where should we use them?

Prabhas
Updated on 30-Jul-2019 22:30:21

374 Views

Native methods are written in a different language than java and are declared as native in Java.

What is the native keyword in Java for?

seetha
Updated on 30-Jul-2019 22:30:21

548 Views

The native keyword is used to declare a method as native. It means that method implementation is present in the different language.

How to convert a String to an int in Java

vanithasree
Updated on 25-Feb-2020 05:20:34

315 Views

Following example is converting a String to int.ExampleLive Demopublic class Tester {    public static void main(String[] args) {       String intString = "1234";       int value = new Integer(intString).intValue();       System.out.println(value);    } }Output1234

How to avoid Java code in jsp page?

radhakrishna
Updated on 30-Jul-2019 22:30:21

215 Views

You can use JSTL, JSP Standard Tag Library or EL, Expression Language to avoid scriptlets.

Advertisements