java.lang.Class is one of the most important classes in java but mostly overlooked by Java developers. It is very useful in the sense that it provides several utility methods like getClass(), forName() which is used to find and load a class, you might have used to load Oracle or MySQL drivers. It also provides methods like Class.newInstance() which is the backbone of reflection and allows you to create an instance of a class without using a new() operator. The class has no public constructor and its instance is created by JVM when a class is loaded.
Wednesday, July 9, 2025
Wednesday, April 2, 2025
How to take array input from command line in Java ? Scanner Example
There is no direct way to take array input in Java using Scanner or any other utility, but it's pretty easy to achieve the same by using standard Scanner methods and asking some questions to the user. For example, if you want to take a one-dimensional array of String as input then you can first ask the user about the length of the array and then you can use a for loop to retrieve that many elements from the user and store them in an array. You can use the next() to take a String input from the user. Similarly, if you need to take an integer array or double array, you can use the nextInt() or nextDouble() method of the Scanner class.
Labels:
Array
,
core java
,
Java basics
Wednesday, May 25, 2022
How to Set Classpath for Java on Windows and Linux? Steps and Example
What is CLASSPATH in Java? Classpath in Java is the path to the directory or list of the directory which is used by ClassLoaders to find and load classes in the Java program. Classpath can be specified using CLASSPATH environment variable which is case insensitive, -cp or -classpath command-line option or Class-Path attribute in manifest.mf file inside the JAR file in Java. In this Java tutorial, we will learn What is Classpath in Java, how Java resolves classpath and how Classpath works in Java alongside How to set the classpath for Java in Windows and UNIX environment.
Labels:
core java
,
core java interview question
,
Java basics
,
programming
Subscribe to:
Posts
(
Atom
)