Are static local variables allowed in Java?

karthikeya Boyini
Published on 23-Jul-2018 12:45:02
Unlike C, C++, Java does not allow static local variables. The compiler will throw the compilation error.ExampleCreate a java class named Tester.Tester.javaLive Demopublic class Tester {    public static void main(String args[]) {       static int a = 10;    } }OutputCompile and Run the file to verify ... Read More

Assigning values to static final variables in java

Samual Sam
Published on 23-Jul-2018 12:40:28
In java, a non-static final variable can be assigned a value at two places.At the time of declaration.In constructor.ExampleLive Demopublic class Tester {    final int A;    //Scenario 1: assignment at time of declaration    final int B = 2;    public Tester() {       //Scenario ... Read More

Ternary Relationship in Database

Kristi Castro
Published on 23-Jul-2018 12:37:17
In Ternary relationship three different Entities takes part in a Relationship.Relationship Degree = 3For Example: Consider a Mobile manufacture company.Three different entities involved:Mobile - Manufactured by company. Part - Mobile Part which company get from Supplier. Supplier - Supplier supplies Mobile parts to Company.Mobile, Part and Supplier will participate simultaneously in a ... Read More

Can we overload or override a static method in Java?

karthikeya Boyini
Published on 23-Jul-2018 12:36:03
If a class has multiple functions by the same name but different parameters, it is known as Method Overloading. If a subclass provides a specific implementation of a method that is already provided by its parent class, it is known as Method Overriding. Method overloading increases the readability of the ... Read More

Entity Relationship Participation in Database

Kristi Castro
Published on 23-Jul-2018 12:32:07
In a Relationship, Participation constraint specifies the existence of an entity when it is related to another entity in a relationship type. It is also called minimum cardinality constraint.This constraint specifies the number of instances of an entity that can participate in a relationship type.There are two types of Participation ... Read More

Non Access Modifiers in Java

Samual Sam
Published on 23-Jul-2018 12:28:51
Java provides a number of non-access modifiers to achieve much other functionality.The static modifier for creating class methods and variables.The final modifier for finalizing the implementations of classes, methods, and variables.The abstract modifier for creating abstract classes and methods.The synchronized and volatile modifiers, which are used for threads.The Static ModifierStatic VariablesThe static ... Read More

Binary Relationship in Database

Kristi Castro
Published on 23-Jul-2018 12:23:32
A Binary Relationship is the relationship between two different Entities i.e. it is a relationship of role group of one entity with the role group of another entity.There are three types of cardinalities for Binary Relationships −1. One-to-One2. One-to-many3. Many-to-ManyOne-to-OneHere one role group of one entity is mapped to one ... Read More

Assigning long values carefully in java to avoid overflow

karthikeya Boyini
Published on 23-Jul-2018 12:16:25
In case of having the operation of integer values in Java, we need to be aware of int underflow and overflow conditions. Considering the fact that in Java, The int data type is a 32-bit signed two's complement integer having a minimum value of -2, 147, 483, 648 and a ... Read More

Copying file using FileStreams in Java

Samual Sam
Published on 23-Jul-2018 12:12:08
This example shows how to copy the contents of one file into another file using read & write methods of FileStreams classes.ExampleLive Demoimport java.io.*; public class Main {    public static void main(String[] args) throws Exception {       BufferedWriter out1 = new BufferedWriter(new FileWriter("srcfile"));       ... Read More

Conversion of Stream To Set in Java

karthikeya Boyini
Published on 23-Jul-2018 12:06:28
We can convert a stream to set using the following ways.Using stream.collect() with Collectors.toSet() method - Stream collect() method iterates its elements and stores them in a collection.collect(Collector.toSet()) method.Using set.add() method - Iterate stream using forEach and then add each element to the set.ExampleLive Demoimport java.util.*; import java.util.stream.Stream; import java.util.stream.Collectors; ... Read More
Advertisements