Get the First Element from a Sorted Set in Java

Samual Sam
Updated on 30-Jul-2019 22:30:24

600 Views

To create a Sorted Set, firstly create a Set.Set s = new HashSet();Add elements to the above set.int a[] = {77, 23, 4, 66, 99, 112, 45, 56, 39, 89}; Set s = new HashSet(); try { for(int i = 0; i < 5; i++) { s.add(a[i]); }After that, use TreeSet class to sort.TreeSet sorted = new TreeSet(s);Get the first element, using the first() method −System.out.println("First element of the sorted set = "+ (Integer)sorted.first());The following is the code to get the first element from a Sorted Set ... Read More

Positive Acknowledgement with Retransmission in PAR

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

2K+ Views

Positive Acknowledgement with Retransmission (PAR) is a group of error – control protocols for transmission of data over noisy or unreliable communication network. These protocols reside in the Data Link Layer and in the Transport Layer of the OSI (Open Systems Interconnection) reference model. They provide for automatic retransmission of frames that are corrupted or lost during transit. PAR is also called Automatic Repeat ReQuest (ARQ).PARs are used to provide reliable transmissions over unreliable upper layer services. They are often used in Global System for Mobile (GSM) communication.Working PrincipleIn these protocols, the receiver sends an acknowledgement message back to the ... Read More

Demonstrate Constructors in a Multilevel Hierarchy in Java

Arushi
Updated on 30-Jul-2019 22:30:24

2K+ Views

Multilevel inheritance is when a class inherits a class which inherits another class. An example of this is class C inherits class B and class B in turn inherits class A.A program that demonstrates constructors in a Multilevel Hierarchy in Java is given as follows:Example Live Democlass A {    A() {       System.out.println("This is constructor of class A");    } } class B extends A {    B() {       System.out.println("This is constructor of class B");    } } class C extends B {    C() {       System.out.println("This is constructor of class C"); ... Read More

Change Value from 1 to Y in MySQL Select Statement Using CASE

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

172 Views

You can use CASE from MySQL to change value from 1 to Y. Let us first create a table. The query to create a table is as follows:mysql> create table changeValuefrom1toY    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> isValidAddress tinyint(1),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.76 sec)Now you can insert some records in the table using insert command. The query is as follows:mysql> insert into changeValuefrom1toY(isValidAddress) values(1); Query OK, 1 row affected (0.22 sec) mysql> insert into changeValuefrom1toY(isValidAddress) values(0); Query OK, 1 row affected (0.16 sec) mysql> insert ... Read More

How India Can Create More Salaried Jobs

Knowledge base
Updated on 30-Jul-2019 22:30:24

106 Views

India is a developing country. Got bored of hearing this again and again, right? For it to be a well-developed country, India needs to focus more on developing its economic status. India has less than one-fifth of workers who are in salaried employment.More job creation would boost up India’s rank in Global Prosperity ladder. India is still in lower middle-income status which needs some salaried jobs to boost its status. The economic survey 2017-18 says if the per capita income in India grows at 6.5% per year, India would reach upper-middle-income status by the mid-to-late 2020s.In my view, a few ... Read More

Get Last Entry from NavigableMap in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

207 Views

To display the last entry from NavigableMap in Java, use the lastEntry() method.Let us first create NavigableMap.NavigableMap n = new TreeMap(); n.put("A", 498); n.put("B", 389); n.put("C", 868); n.put("D", 988); n.put("E", 686); n.put("F", 888); n.put("G", 999); n.put("H", 444); n.put("I", 555); n.put("J", 666);Get the last entry now.n.lastEntry()The following is an example to get the last entry from NavigableMap.Example Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { NavigableMap n = new TreeMap(); n.put("A", 498); n.put("B", 389); ... Read More

Variable in Subclass Hides the Variable in Super Class in Java

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

456 Views

Sometimes the variable in the subclass may hide the variable in the super class. In that case, the parent class variable can be referred to using the super keyword in Java.A program that demonstrates this is given as follows:Example Live Democlass A {    char ch; } class B extends A {    char ch;    B(char val1, char val2) {       super.ch = val1;       ch = val2;    }    void display() {       System.out.println("In Superclass, ch = " + super.ch);       System.out.println("In subclass, ch = " + ch);    } ... Read More

Concatenate More Than 2 Fields with SQL

Chandu yadav
Updated on 30-Jul-2019 22:30:24

15K+ Views

To concatenate more than 2 fields with SQL, you can use CONCAT() or CONCAT_WS() function. The syntax is as follows. Let us first see using CONCAT().SELECT CONCAT(yourColumnName1, '/', yourColumnName2, '/', yourColumnName3, '/', ......N) AS anyVariableName FROM yourTableName;The syntax is as follows:SELECT CONCAT_WS(‘/’, yourColumnName1, yourColumnName2, .....N) AS anyVariableName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table MoreThan2ColumnConcat    -> (    -> Id int,    -> Name varchar(20),    -> Age int,    -> Marks int    -> ); Query OK, 0 rows affected (2.59 sec)Insert some ... Read More

Display All Tables Inside a MySQL Database Using Java

Rishi Rathor
Updated on 30-Jul-2019 22:30:24

1K+ Views

We will see here how to display all tables inside a MySQL database using Java. You can use show command from MySQL to get all tables inside a MySQL database.Let’s say our database is ‘test’. The Java code is as follows to show all table names inside a database ‘test’.The Java code is as follows. Here, connection is established between MySQL and Java −import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import com.mysql.jdbc.Connection; import com.mysql.jdbc.DatabaseMetaData; public class GetAllTables {    public static void main(String[] args) throws SQLException {       Connection conn = null;       try { ... Read More

Using Run-Time Polymorphism in Java

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

452 Views

A single action can be performed in multiple ways using the concept of polymorphism. Run-time polymorphism can be performed by method overriding. The overridden method in this is resolved at compile time.A program that demonstrates run-time polymorphism in Java is given as follows:Example Live Democlass Animal {    void sound() {       System.out.println("Animal makes sound");    } } class Cat extends Animal {    void sound() {       System.out.println("Cat Meows");    } } class Dog extends Animal {    void sound() {       System.out.println("Dog Barks");    } } class Cow extends Animal {    void ... Read More

Advertisements