What is Blank Final Variable and Static Blank Final Variables in Java

Maruthi Krishna
Updated on 02-Jul-2020 14:19:27

2K+ Views

Static variables − Static variables are also known as class variables. You can declare a variable static using the keyword. Once you declare a variable static there would only be one copy of it in the class, regardless of how many objects are created from it.public static int num = 39;Instance variables − These variables belong to the instances (objects) of a class. These are declared within a class but outside methods. These are initialized when the class is instantiated. They can be accessed from any method, constructor or blocks of that particular class.You must access instance variables using an ... Read More

Call Another Enum Value in an Enum's Constructor using Java

Maruthi Krishna
Updated on 02-Jul-2020 14:16:29

3K+ 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 Days {    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }Methods and variables in an enumerationEnumerations are similar to classes and, you can have variables, methods (Only concrete methods) and constructors within them.For suppose we have elements in an enumeration with values as −enum Scoters {    ACTIVA125(80000), ACTIVA5G(70000), ACCESS125(75000), ... Read More

Throw Exception Manually in Java

Maruthi Krishna
Updated on 02-Jul-2020 14:11:35

5K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Exampleimport java.util.Scanner; public class ExceptionExample {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter first number: ");       int a = sc.nextInt();       System.out.println("Enter second number: ");       int b = sc.nextInt();       int c = a/b;       System.out.println("The result is: "+c);   ... Read More

Multiple Try Blocks with One Catch Block in Java

Maruthi Krishna
Updated on 02-Jul-2020 14:10:01

9K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Exampleimport java.util.Scanner; public class ExceptionExample {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter first number: ");       int a = sc.nextInt();       System.out.println("Enter second number: ");       int b = sc.nextInt();       int c = a/b;       System.out.println("The result is: "+c);   ... Read More

Read DataInputStream Until the End without Catching EOFException in Java

Maruthi Krishna
Updated on 02-Jul-2020 14:09:12

1K+ Views

While reading the contents of a file in certain scenarios the end of the file will be reached in such scenarios a EOFException is thrown.Especially, this exception is thrown while reading data using the Input stream objects. In other scenarios a specific value will be thrown when the end of file reached.In the DataInputStream class, it provides various methods such as readboolean(), readByte(), readChar() etc.. to read primitive values. While reading data from a file using these methods when the end of file is reached an EOFException is thrown.ExampleFollowing program demonstrates how to handle the EOFException in Java.import java.io.DataInputStream; import ... Read More

Download YouTube Audio using Python pafy

Hafeezul Kareem
Updated on 02-Jul-2020 14:07:57

1K+ Views

In this article, we will see how to extract details about Youtube videos and download them in different formats using the pafy module. Head over to the link for official documentation.Install the pafy module using the following commandpip install pafyIf you run the above command, it will generate the following results on the successful installation of the module pafy.Collecting pafy Using cached https://files.pythonhosted.org/packages/b0/e8/3516f761558525b00d3eaf73744eed5c267db 20650b7b660674547e3e506/pafy-0.5.4-py2.py3-none-any.whl Installing collected packages: pafy Successfully installed pafy-0.5.4Check whether you can import the pafy module or not by running the following command.import pafyIf you found no errors then it's done. Otherwise install the following module to solve ... Read More

Build Horizontal Navigation Bar with Inline List Items in CSS

Anvi Jain
Updated on 02-Jul-2020 14:04:12

878 Views

Use Inline List Items to build a horizontal navigation bar. Set the elements as inline.ExampleYou can try to run the following code to create horizontal navigation bar:Live Demo                    ul {             list-style-type: none;             margin: 0;             padding: 0;          }          .active {             background-color: #4CAF50;             color: white;          }          li {             border-bottom: 1px solid #555;             display: inline;          }                              Home          Company          Product          Services          Contact          

Arrow to the Top of the Tooltip with CSS

Krantik Chavan
Updated on 02-Jul-2020 14:02:26

880 Views

Use the bottom CSS property to add arrow to the top of the tooltip.ExampleYou can try to run the following code to add a tooltip with arrow to the top:Live Demo           .mytooltip .mytext {          visibility: hidden;          width: 140px;          background-color: blue;          color: #fff;          z-index: 1;          top: 150%;          left: 50%;          margin-left: -60px;          text-align: center;          border-radius: 6px;          padding: 5px 0;          position: absolute;       }       .mytooltip {          position: relative;          display: inline-block;       }       .mytooltip .mytext:after {          content: "";          position: absolute;          bottom: 100%;          left: 50%;          margin-left: -10px;          border-width: 3px;          border-style: solid;          border-color: transparent transparent blue transparent;       }       .mytooltip:hover .mytext {          visibility: visible;       }               Keep mouse cursor over me           My Tooltip text          

Add Rounded Corners to a Button with CSS

Daniol Thomas
Updated on 02-Jul-2020 14:01:59

2K+ Views

To add rounded corners to a button, use the border-radius property.ExampleYou can try to run the following code to add rounded corners −Live Demo                    .button {             background-color: yellow;             color: black;             text-align: center;             font-size: 15px;             padding: 20px;             border-radius: 15px;          }                     Result       Click below for result:       Result    

Static Factory Method and New Keyword in Java

Maruthi Krishna
Updated on 02-Jul-2020 14:00:04

200 Views

Factory pattern is a design pattern (creational pattern) which is used to create multiple objects based on the data we provide. In it we create an object abstracting the process of creation.ExampleBelow given is the example implementation of the factory pattern. Here, we have an interface with name Employee and 3 classes: Student, Lecturer, NonTeachingStaff, implementing it. We have created a factory class (EmployeeFactory) with a method named getEmployee(). This method accepts a String value and returns an object of one of the classes, based on the given String value.import java.util.Scanner; interface Person{    void dsplay(); } class Student implements ... Read More

Advertisements