Found 7442 Articles for Java

What are the uses of super keyword in java?

Maruthi Krishna
Updated on 29-Jun-2020 12:23:24

1K+ Views

The super keyword in Java is a reference to the object of the parent/superclass. Using it, you can refer/call a field, a method or, a constructor of the immediate superclass.Referring to a field using super keywordAs mentioned above, you can refer to an instance filed/variable of the immediate superclass from an instance method or, a constructor of a subclass, using the "super" keyword.If a class extends another class, a copy of members of the parent class will be created in the subclass i.e. Using the object of the subclass you can access the members of both subclass and the superclass.If ... Read More

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

237 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

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

How to count rows – count (*) and Java

Vikyath Ram
Updated on 30-Jul-2019 22:30:26

10K+ Views

The SQL Count() function returns the number of rows in a table. Using this you can get the number of rows in a table.select count(*) from TABLE_NAME;Let us create a table with name cricketers_data in MySQL database using CREATE statement as shown below −CREATE TABLE cricketers_data(    First_Name VARCHAR(255),    Last_Name VARCHAR(255),    Date_Of_Birth date,    Place_Of_Birth VARCHAR(255),    Country VARCHAR(255), );Now, we will insert 5 records in cricketers_data table using INSERT statements −insert into cricketers_data values('Shikhar', 'Dhawan', DATE('1981-12-05'), 'Delhi', 'India'); insert into cricketers_data values('Jonathan', 'Trott', DATE('1981-04-22'), 'CapeTown', 'SouthAfrica'); insert into cricketers_data values('Kumara', 'Sangakkara', DATE('1977-10-27'), 'Matale', 'Srilanka'); insert into cricketers_data values('Virat', 'Kohli', DATE('1988-11-05'), 'Delhi', ... Read More

Can we return Result sets in JDBC?

Rishi Raj
Updated on 30-Jul-2019 22:30:26

1K+ Views

Yes, just like any other objects in Java we can pass a ResultSet object as a parameter to a method and, return it from a method.Let us create a table with name MyPlayers in MySQL database using CREATE statement as shown below −CREATE TABLE MyPlayers(    ID INT,    First_Name VARCHAR(255),    Last_Name VARCHAR(255),    Date_Of_Birth date,    Place_Of_Birth VARCHAR(255),    Country VARCHAR(255),    PRIMARY KEY (ID) );Now, we will insert 7 records in MyPlayers table using INSERT statements −insert into MyPlayers values(1, 'Shikhar', 'Dhawan', DATE('1981-12-05'), 'Delhi', 'India'); insert into MyPlayers values(2, 'Jonathan', 'Trott', DATE('1981-04-22'), 'CapeTown', 'SouthAfrica'); insert into MyPlayers values(3, 'Kumara', 'Sangakkara', ... Read More

Advertisements