Found 9150 Articles for Object Oriented Programming

How to implement an interface using an anonymous inner class in Java?

Shriansh Kumar
Updated on 16-May-2025 17:46:18

2K+ Views

What is an Anonymous Inner Class In Java, an anonymous inner class is a class that doesn't have a name, we will directly define it at the time of instantiation. You can use it in cases where you need to override methods of a class (or interface) only once, without creating a separate named class. Syntax of Anonymous Inner Class When you are using a class to create an anonymous inner class in Java, use the following syntax: Class objectName = new Class() { // Override necessary methods }; When you are implementing an interface ... Read More

Interface variables are static and final by default in Java, Why?

Shriansh Kumar
Updated on 21-May-2025 15:04:19

20K+ Views

In Java, interfaces are used to achieve abstraction and multiple inheritance. They can contain methods and variables, but there are specific rules about how those members should behave. For example, all variables declared in an interface are public, static, and final by default, even if you don't use these keywords while defining variables. To understand the reason behind it, we first need to understand what static and final mean in Java. What is a Static Variable in Java? The static variables are defined using the static keyword. These variables belong to the class rather than to any specific object, which ... Read More

How many non-access modifiers are there in Java?

raja
Updated on 24-Feb-2020 08:07:53

233 Views

Java provides some other modifiers to provide the functionalities other than the visibility. These modifiers are called Non-Access ModifiersStatic  The members which are declared as static are common to all instances of a class. Static members are class level members which are stored in the class memory.Final  This modifier is used to restrict the further modification of a variable or a method or a class. The value of a variable which is declared as final can’t be modified once it gets a value. A final method can not be overridden in the subclass and you can not create a subclass ... Read More

How to compile & run a Java program using Command Prompt?

Shriansh Kumar
Updated on 24-Apr-2025 18:17:52

19K+ Views

Command prompt is a command line interface that accepts text-based inputs or commands and performs tasks based on those command. Nowadays, there are various integrated development environments (IDEs) that are available to compile, build, and run Java programs within their environment. However, we can also compile and run Java programs using the Command Prompt. Compiling and Running Java Programs using CLI To compile and run Java programs outside the IDEs using the Command Prompt, we need to install the JDK and set its path in our system. To set up the development environment for Java on your local machine, we ... Read More

What are the different steps involved to execute a Java program?

Shriansh Kumar
Updated on 16-May-2025 19:05:14

3K+ Views

Java is an object-oriented programming language that provides various features like platform independence, security, garbage collection, etc. Unlike other programming languages, programs written in Java go through a specific sequence of steps during the compilation and execution process. Java follows the same process no matter where and how you compile and execute Java programs, whether using an IDE or the Command Prompt. In this article, we will discuss and understand the steps Java follows to execute programs. Compilation and Execution Process of Java Program Java program execution follows 5 major steps, which are as follows: Step 1: Edit or ... Read More

Scope and lifetime of variables in Java?

raja
Updated on 06-Feb-2020 09:24:32

10K+ Views

Instance VariablesA variable which is declared inside a class and outside all the methods and blocks is an instance variable. The general scope of an instance variable is throughout the class except in static methods. The lifetime of an instance variable is until the object stays in memory.Class VariablesA variable which is declared inside a class, outside all the blocks and is marked static is known as a class variable. The general scope of a class variable is throughout the class and the lifetime of a class variable is until the end of the program or as long as the ... Read More

What is JSON.parse() and and explain its use in javascript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

184 Views

JSON.parse()When the data is received from web server, the data is always a string .So to change it to the object, JSON.parse() method is used. Example Live Demo    var obj = '{"name":"Jon", "age":20, "city":"Columbia"}';    var res = JSON.parse(obj);    document.write(res);   console.log(res); output[object object] {"name":"Jon", "age":"20", "city":"Columbia"}

What is JSON.stringify() and explain its use in javascript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

223 Views

JSON.stringify()If we need to send data to a web server the data should be a string.To change the object literal to string JSON.stringify() method should be used.For instanceExample-1 Live Demo var obj = {name:"rekha", age:40, city:"newyork"}; var myJSON = JSON.stringify(obj); document.getElementById("demo").innerHTML = myJSON; Output{"name":"rekha","age":40,"city":"newyork"}Example-2 Live Demo    var obj = {"name":"ramesh","age":30,"family":           [{"mother":"geetha","father":"rao"}],"city":"berlin"};    var myJSON = JSON.stringify(obj);    document.getElementById("demo").innerHTML = myJSON; Output{"name":"ramesh","age":30,"family":[{"mother":"geetha","father":"rao"}],"city":"berlin"}

What is an object in JavaScript and access any property ?**

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

128 Views

Accessing Property Of An ObjectWithout objects there is no JavaScript. Everything such as boolean,numbers,functions etc are all objects.Accessing properties of an object is explained in the following method.Example-1 Live Demo    myObj = {"name":"Ramesh","age":30,"family":            [{"mother":"Geetha","father":"Rao"}],"city":"Berlin"};            var res = myObj.family[0].mother;   document.write(res); OutputGeethaExample-2 Live Demo    myObj = {"name":"Ramesh","age":30,"family":            [{"mother":"Geetha","father":"Rao"}],"city":"Berlin"};    var res = myObj.city;    document.write(res); OutputBerlin

How to set Temporary and Permanent Paths in Java?

raja
Updated on 11-Feb-2020 07:39:28

22K+ Views

There are two ways to set the path in java, First is Temporary Path and second is Permanent Path.Setting Temporary PathOpen command prompt in WindowsCopy the path of jdk/bin directory where java located (C:\Program Files\Java\jdk_version\bin)Write in the command prompt: SET PATH=C:\Program Files\Java\jdk_version\bin and hit enter command.Setting Permanent PathGo to My Computer ---> Right Click on it ---> Advanced System Settings ---> Advanced Tab ---> Click on Environment VariablesClick on New tab of User variables, assign value JAVA_HOME to Variable Namejava\jdk_version\bin path (copied path) to Variable Value and click on OK ButtonFinally, click on OK button.Read More

Advertisements