Maruthi Krishna has Published 952 Articles

How to append data to a file in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Aug-2019 08:31:13

564 Views

In most scenarios if you try to write contents to a file, using the classes of the java.io package, the file will be overwritten i.e. data existing in the file is erased and the new data is added to it.But, in certain scenarios like logging exceptions into a file (without ... Read More

Can the main method in Java return a value?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Aug-2019 08:26:53

1K+ Views

The public static void main(String args[]) is the entry point of a Java program Whenever you execute a program the JVM searches for the main method and starts executing the contents of it. If such method is not found the program gets executed successfully, but when you execute the program ... Read More

Can we have integers as elements of an enum in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Aug-2019 08:15:03

8K+ Views

Enumeration (enum) in Java is a datatype which stores a set of constant values. You can use enumerations to store fixed values such as days in a week, months in a year etc.You can define an enumeration using the keyword enum followed by the name of the enumeration as −enum ... Read More

What is a variable, field, property in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Aug-2019 08:10:05

1K+ Views

In programming to hold data members we use variables, Java you can declare three types of variables namely, Local variables − Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the ... Read More

How to include current date when logging exceptions to a file with FileOutputStream in java?

Maruthi Krishna

Maruthi Krishna

Updated on 06-Aug-2019 07:50:57

254 Views

There are several logging frame works available to log your data into files. You can also define your own method. In either cases to add the current time to your logged exception you can use the LocalDateTime class.It is an immutable class representing the date-time, it stores date-time as year-month-day-hour-minute-second. ... Read More

When a lot of changes are required in data, which one you choose String or StringBuffer in java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Aug-2019 14:42:20

499 Views

The String type is a class in Java, it is used to represent a set of characters. Strings in Java are immutable, you cannot change the value of a String once created.Since a String is immutable, if you try to reassign the value of a String. The reference of it ... Read More

How to access Static variable of Outer class from Static Inner class in java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Aug-2019 14:39:31

872 Views

A class with in another class is known as inner class, you cannot declare a class static unless it is an inner class. A static inner class is just like other class variables. You can access it (static inner class) without instantiationExampleYou can access the static variable of an outer ... Read More

Why interfaces don't have static initialization block when it can have static methods alone in java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Aug-2019 14:28:28

1K+ Views

An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.A static method is declared using the static keyword and it will be loaded into the memory along with the class. You can access static methods using class name without ... Read More

How to access the object of a class without using the class name from a static context in java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Aug-2019 14:17:52

551 Views

The only possible solution is to get the stack trace of the current thread. Get the class name using an element in the stack trace. Pass it to the forName() method of the class named Class.This returns a Class object and you can get an instance of this class using ... Read More

Are values returned by static method are static in java?

Maruthi Krishna

Maruthi Krishna

Updated on 05-Aug-2019 12:44:44

2K+ Views

Whenever you return values from a static method they are either static nor instance by default, they are just values.The user invoking the method can use them as he wants. i.e. you can retrieve the values and declare them static.But, since you cannot declare variables of a method static if ... Read More

Advertisements