
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9150 Articles for Object Oriented Programming

2K+ Views
The length property is only applicable to arrays and strings. So when we call the length property on an object we will get undefined.ExampleLive Demo var object = {prop:1, prop:2}; document.write(object.length); OutputundefinedWhereas arrays and strings will display their length when length property is used on them.ExampleLive Demo var string = 'hello'; var array = [1, 2, 3]; var len1 = string.length; var len2 = array.length; document.write(len1); document.write(""); document.write(len2); Output5 3In javascript, we have Object.keys() property, which checks whether there are any properties or not. If we use the length property ... Read More

2K+ Views
Java Garbage collector tracks the live object and objects which are no more need are marked for garbage collection. It relieves developers to think of memory allocation/deallocation issues.When an object created in Java program is no longer reachable or used it is eligible for garbage collection.Following are some scenarios where a Java object could be unreachable/unused.Object inside a method − In Java a method is stored in the stack memory. When you call a method, JVM fetches it into the stack and executes it. After the execution it is popped out of the stack then, all its variables will be ... Read More

3K+ Views
To compare two objects the object class provides a method with name equals(), this method accepts an object and compares it with the current object. If the references of these two objects are equal, then it returns true else this method returns false.ExampleIn the following example we have a class Employee with two variables name, age and a parameterized constructor.From the main method we are creating two objects by passing same values and, comparing both values using the equals() method.Since the equals() method of the Object class returns true only if the references of the two objects are equal, this ... Read More

10K+ Views
Yes, you can pass objects as arguments in Java. Consider the following example: Here we have a class with name EmployeeExampleIn the following Java example, we a have a class with two instance variables name and age and a parameterized constructor initializing these variables.We have a method coypObject() which accepts an object of the current class and initializes the instance variables with the variables of this object and returns it.In the main method we are instantiating the Student class and making a copy by passing it as an argument to the coypObject() method. Live Demoimport java.util.Scanner; public class Student { ... Read More

1K+ Views
The finalize() method belongs to the Object class. Right before closing an object, the garbage collector makes sure that there are no more references to it and, calls the finalize() method on it.Therefore, once you override the finalize() method in it, you can do all the cleanup activity like closing the resources like database connection, network connection, etc.protected void finalize throws Throwable{}It is invoked only once during the execution of a program.Following are some notable points about the finalize method.Since this method belongs the Object class, which is the super class of all the classes in java, you can override ... Read More

11K+ Views
A class in a blue print/user defined datatype in java that describes the behavior/state that the object of its type support.Examplepublic class Student { String name "Krishna"; int age = 20; void greet() { System.out.println("Hello how are you"); } }An object is an instance of a class created from it using the new keyword. Once you create an object of a class, using it you can access he members of the class. In the below given code an object of the class Student is created.public class Example { public static void main(String ... Read More

4K+ Views
To compare two objects the object class provides a method with name equals(), this method accepts an object and compares it with the current object. If the references of these two objects are equal, then it returns true else this method returns false.ExampleIn the following example we have a class Employee with two variables name, age and a parameterized constructor.From the main method we are creating two objects by passing same values and, comparing both values using the equals() method.Since the equals() method of the Object class returns true only if the references of the two objects are equal, this ... Read More

1K+ Views
To convert a Date object to LocalDate object in Java −Convert the obtained date object to an Instant object using the toInstant() method.Instant instant = date.toInstant();Create the ZonedDateTime object using the atZone() method of the Instant class.ZonedDateTime zone = instant.atZone(ZoneId.systemDefault());Finally, convert the ZonedDateTime object to the LocalDate object using the toLocalDate() method.LocalDate givenDate = zone.toLocalDate();ExampleFollowing example accepts a name and Date of birth from the user in String formats and converts it to LocalDate object and prints it. Live Demoimport java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; import java.time.LocalDate; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.Date; import java.util.Scanner; public class DateToLocalDate { public static void ... Read More

3K+ Views
Both JRadioButton and JCheckBox components can extend the JToggleButton class in Java, the main difference is that JRadioButton is a group of buttons in which only one button can be selected at a time, whereas JCheckBox is a group of checkboxes in which multiple items can be selected at a time. JRadioButton A JRadioButton is a component that represents an item with a state selected or unselected. Usually, a group of radio buttons is created to provide options to the user, but only one option can be selected at a time. JRadioButton will generate an ActionListener, ChangeListener, and ItemListener interfaces. Instantiating JRadioButton: JRadioButton Radio_Name = new JRadioButton(); ... Read More

2K+ Views
When there are no more references to an object, the object is finalized and when the Garbage Collection starts these finalized objects get collected this will done automatically by the JVM. We can call garbage collection directly but it doesn't guarantee that the GC will start executing immediately.We can call the Garbage Collection explicitly in two waysSystem.gc() methodRuntime.gc() methodThe java.lang.Runtime.freeMemory() method returns the amount of free memory in the Java Virtual Machine (JVM). Calling the gc() method may result in increasing the value returned by the freeMemory.ExampleLive Demopublic class GarbageCollectionTest { public static void main(String args[]) { System.out.println(Runtime.getRuntime().freeMemory()); ... Read More