Print/list public methods/functions of class in java (example)

Given a class in java containing public,private & protected methods. Get/list/print public methods of class using class Class. We will use getMethods() of Class to retrieve public methods. 1. Program: print/list public methods/functions of class in java (example) package org.learn.classes; import java.lang.reflect.Method; class University { private String name; private String location; private float area; private… Read More »

Create object/instance of class by name using Class.forName in java (examples)

Given an application in java. We would like to create the instance of classes by specifying class name. Instances of the class Class represent classes and interfaces in a running Java application. We will get the reference of loaded class using Class.forName(“Complete path of a class”) And then, we can create instance of loaded class. Class Class does… Read More »

Get & Set default timezone of java virtual machine (JVM) – example

We would like to get/set the default timezone in java. TimeZone represents a time zone offset, and also figures out daylight savings. We will use package java.util.TimeZone to get/set default time zone. 1. Important methods of TimeZone class 2. Program: Get & Set default timezone of java virtual machine (JVM) package org.learn; import java.util.TimeZone; public class DemoTimeZone… Read More »

Convert local file path to URL & URI in java (example)

Given a File in java. We would like to convert path of a file to URL & URI path. e.g. If path of file on local windows operating system is “D:\Code\Local File Path.txt” URL & URI of local file path will be “file:/D:/Code/Local%20File%20Path.txt” We will use toURL() and toURI() method of File class . 1.… Read More »

Page 2 of 4412345...102030...Last »