Browsed by
Category: Java

Arraylist to Array Using ToArray() in java

Arraylist to Array Using ToArray() in java

Syntax: <T> T[] toArray(T[] a) Eg : String[] y = x.toArray(new String[0]); T – the runtime type of the array to contain the collection Parameters: a – the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose. Returns: an array containing the elements of this list Throws: ArrayStoreException – if the runtime type of the specified array is not a…

Read More Read More

596 total views, 6 views today

hashMap Vs TreeMap Vs LinkedHashMap

hashMap Vs TreeMap Vs LinkedHashMap

════════════╦═════════════════════╦═══════════════════╦═════════════════════╗ ║ Property ║ HashMap ║ TreeMap ║ LinkedHashMap ║ ╠══════════════╬═════════════════════╬═══════════════════╬═════════════════════╣ ║ Iteration ║ no guarantee order ║ sorted according ║ ║ ║ Order ║ will remain constant║ to the natural ║ insertion-order ║ ║ ║ over time ║ ordering ║ ║ ╠══════════════╬═════════════════════╬═══════════════════╬═════════════════════╣ ║ Get/put ║ ║ ║ ║ ║ remove ║ O(1) ║ O(log(n)) ║ O(1) ║ ║ containsKey ║ ║ ║ ║ ╠══════════════╬═════════════════════╬═══════════════════╬═════════════════════╣ ║ ║ ║ NavigableMap ║ ║ ║ Interfaces ║ Map ║ Map ║ Map ║…

Read More Read More

600 total views, 2 views today

Why StringBuffer/StringBuilder should be avoided in HashMap?

Why StringBuffer/StringBuilder should be avoided in HashMap?

Why StringBuffer/StringBuilder should be avoided in HashMap?   This is one of the core java interview question under collections category. Generally in all the map manipulations we use string and avoid stringbuffer and stringbuilders, because both are mutable. What is the issue if is mutable ? If you are keeping your hashmap’s key/value as stringbuilder/stringbuffer then once after you inserted the value in the map, if any of the key/value modified then it actually affects inside the map as well,…

Read More Read More

354 total views, no views today

Generate angular + Java code using yeoman & Jhipster

Generate angular + Java code using yeoman & Jhipster

Generate angular + Java code using yeoman & Jhipster Ensure you have installed yeoman (yo when dealing with npm and yarn) and jhipster (generator-jhipster when dealing with npm and yarn). If not installed, have a quick look at,     Step 1: Run yo jhipster     It will ask around 10 to 15 questions, you can provide the sample values as per the above screenshot and proceed to step 2:   Step 2: Angular 5 & Java Codes are…

Read More Read More

570 total views, 1 views today

Core Java Programming Interview Questions

Core Java Programming Interview Questions

Core Java Programming Interview Questions: All these below are purely java programming interview questions collected from different attendees and different companies. Walk through all the programming questions and try to figure it out before checking the answers below.   Basics:   1.What is the output ? package in.javadomain; class Basics { public static void main(String[] args) { System.out.println(“I am main method” + new Basics()); } Basics() { System.out.println(“I am construtor!”); } }   Output: I am construtor! I am main…

Read More Read More

458 total views, no views today

Java program to check whether the String is Pangram or Not

Java program to check whether the String is Pangram or Not

Java program to check whether the String is Pangram or Not: What is Pangram ? If a given sentence has all the alphabets then it is a valid pangram.   If the below sentence is given as input then it has to return “Pangram” The quick brown fox jumps over the lazy dog   If the below sentence is given as input then it has to return “Not a Pangram” The quick brown fox jumps over the dog Pseudo code…

Read More Read More

667 total views, no views today

Reflection Example for 100% Dummies

Reflection Example for 100% Dummies

Reflection Example for 100% Dummies: I know in all the recent interviews reflection relation question are asked along with the other tough and popular core java interview questions mentioned here.   As mentioned in the title this is purely for 100% dummies who just heard only the term “Reflection”. I was also in the list of 100% dummies, after reading some blogs and tutorials about “Reflection” & “Reflection Examples”, I got some good understanding.   I am going to share…

Read More Read More

334 total views, no views today

Java Remote Debugging Web Application Steps

Java Remote Debugging Web Application Steps

Java Remote Debugging Web Application Steps: Java web applications are complex to setup and do debugging all the time for all the issues. In those cases, we can smartly keep the code deployed currently in local and just do remote debugging to figure out the issues. It is much easy with IBM WebSphere or Eclipse. Step 1: Add these two entries in your web application server consoles / jvm properties: -Dwas.debug.mode=true -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=13123   Step 2: And in Eclipse, Debug as…

Read More Read More

421 total views, no views today

Java Collection Framework (As per Java 8) All Covered in One Image

Java Collection Framework (As per Java 8) All Covered in One Image

Java Collection Framework (As per Java 8) All Covered in One Image: Even many experienced java developers know only list/set/map and few know vector hashtable and queues. But so much more than that are actually there in the java collection framework. I am publishing the single java collection framework image to understand the complete collection hierarchy interface/sub interface and its implementation classes. You can refer this for high-level collection java hierarchy, this is created based java 8 official oracle documention…

Read More Read More

491 total views, no views today

Binary Search Implementation in Java Example

Binary Search Implementation in Java Example

Binary search is one of the most important searching algorithm to know and understand for search functionality. In the below we are going to return the array position based on the searching number existence in the array, if it does not exist then we will return -1.   Binary search basically works this way, 1. Numbers should be sorted in the array before beginning with binary search. 2. Check the middle number with the number which need to be searched…

Read More Read More

487 total views, 1 views today