Create Static Class Object Without Reference of Outer Class in Java

Maruthi Krishna
Updated on 02-Jul-2020 13:59:06

1K+ Views

A static member (method/variable) belongs to the class and it will be loaded into the memory along with the class. You can invoke it without creating an object. (using the class name as reference). There is only one copy of the static field available throughout the class i.e. the value of the static field will be same in all objects. You can define a static field using the static keyword.Examplepublic class Sample{    static int num = 50;    public static void demo(){       System.out.println("Value of num in the demo method "+ Sample.num);    } } public class ... Read More

Why Static Methods of Parent Class Gets Hidden in Child Class in Java

Maruthi Krishna
Updated on 02-Jul-2020 13:57:37

3K+ Views

When we have two classes where, one extends another and if, these two classes have same method including parameters and return type (say, sample) the method in the sub class overrides the method in the super class.i.e. Since it is inheritance. If we instantiate the subclass a copy of superclass’s members is created in the subclass object and, thus both methods are available to the object of the subclass.But if you call the method (sample), the sample method of the subclass will be executed overriding the super class’s method.Exampleclass Super{    public static void sample(){       System.out.println("Method of ... Read More

Call Non-Static Method of Abstract Class from Static Method in Java

Maruthi Krishna
Updated on 02-Jul-2020 13:56:05

9K+ Views

A method which does not have body is known as abstract method. It contains only method signature with a semi colon and, an abstract keyword before it.public abstract myMethod();To use an abstract method, you need to inherit it by extending its class and provide implementation to it.Abstract classA class which contains 0 or more abstract methods is known as abstract class. If it contains at least one abstract method, it must be declared abstract.Hence, if you want to prevent instantiation of a class directly, you can declare it abstract.Accessing non-static methods of an abstract classSince you cannot instantiate an abstract ... Read More

Static Reference to Non-Static Fields in Java

Maruthi Krishna
Updated on 02-Jul-2020 13:54:14

11K+ Views

A class in Java will have three kinds of variables namely, static (class), instance and, local.Local variables − These variables belong to and declared/defined within the methods/blocks/constructors. The scope of these variables lies within the method (or, block or, constructor) and will be destroyed after he execution of it.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 object. i.e. ... Read More

Ethernet Performance

Moumita
Updated on 02-Jul-2020 13:47:48

618 Views

Ethernet is a set of technologies and protocols that are used primarily in LANs. The performance of Ethernet is analysed by computing the efficiency of the channel under different load conditions.Let us assume an Ethernet network has k stations and each station transmits with a probability p during a contention slot. Let A be the probability that some station acquires the channel. A is calculated as −A = kp (1−p)kpThe value of A is maximized at p = 1/k. If there can be innumerable stations connected to the Ethernet network, i.e. k → ∞, the maximum value of A will ... Read More

Ethernet Throughput

Moumita
Updated on 02-Jul-2020 13:46:23

2K+ Views

Throughput of a system refers to the rate of processing of a task thereby generating results. Ethernet is a set of technologies primarily used in LANs, whose primary data units are frames. The throughput of Ethernet is measured by the rate of successful delivery of frames over a communication channel.There are several methods for representing Ethernet throughput. The least ambiguous among them is calculation of channel efficiency. Channel efficiency, is the percentage of the net bit rate (in bits per second) of a channel that is actually communicated. Suppose that an Ethernet connection has a speed of 100 Mbps. But, ... Read More

Ethernet Performance

Moumita
Updated on 02-Jul-2020 13:44:52

2K+ Views

Ethernet is a set of technologies and protocols that are used primarily in LANs. The performance of Ethernet is analysed by computing the efficiency of the channel under different load conditions.Let us assume an Ethernet network has k stations and each station transmits with a probability p during a contention slot. Let A be the probability that some station acquires the channel. A is calculated as −A = kp (1−p)kpThe value of A is maximized at p = 1/k. If there can be innumerable stations connected to the Ethernet network, i.e. k → ∞, the maximum value of A will ... Read More

Syntax for Passing Scanner Object as Parameter in Java

Maruthi Krishna
Updated on 02-Jul-2020 13:43:08

5K+ Views

Until Java 1.5 to read data from the user programmers used to depend on the character stream classes and byte stream classes.From Java 1.5 Scanner class was introduced. This class accepts a File, InputStream, Path and, String objects, reads all the primitive data types and Strings (from the given source) token by token using regular expressions.By default, whitespace is considered as the delimiter (to break the data into tokens).To read various datatypes from the source using the nextXXX() methods provided by this class namely, nextInt(), nextShort(), nextFloat(), nextLong(), nextBigDecimal(), nextBigInteger(), nextLong(), nextShort(), nextDouble(), nextByte(), nextFloat(), next().Passing Scanner object as a ... Read More

Fix Exception in Thread Main in Java

Maruthi Krishna
Updated on 02-Jul-2020 13:41:17

21K+ 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

Declare Static Variable Within a Method in Java

Maruthi Krishna
Updated on 02-Jul-2020 13:38:47

7K+ Views

A static filed/variable belongs to the class and it will be loaded into the memory along with the class. You can invoke them without creating an object. (using the class name as reference). There is only one copy of the static field available throughout the class i.e. the value of the static field will be same in all objects. You can define a static field using the static keyword.Examplepublic class Sample{    static int num = 50;    public void demo(){       System.out.println("Value of num in the demo method "+ Sample.num);    }    public static void main(String ... Read More

Advertisements