Skip to main content

Core Java





Core Java Interview Questions


Core Java Assignments




1. Write a Java program to convert temperature from Fahrenheit to Celsius degree.


Test Data
Input a degree in Fahrenheit: 212
Expected Output:
212.0 degree Fahrenheit is equal to 100.0 in Celsius


2.  Write a java program to find out a number is even or odd.


Test Data
Input a number: 35
Expected Output: ODD


3. Write a java program to print the following pattern depending upon input number.


Test Data:1
Input a number: 4
Expected Output:


*
**
***
****


Test Data:2
Input a number: 7
Expected Output:


*
**
***
****
*****
******
*******


4. Write a java program to reverse the digit of a number.


Test Data:1
Input a number: 478
Expected Output: 874
Test Data:1
Input a number: 123456
Expected Output: 654321


5. Write a Java program to sort a given array list.




6. Write a Java program to create a HashSet. Then put some arbitrary value in the set. Then print all the elements of the HashSet. Then remove all the elements of the HashSet. Then check the HashSet is empty or not.




7. Write a Java program to create a HashMap. Then put some arbitrary key-value in the map. Then print all the elements of the HashMap. Then remove all the elements of the HashMap. Then check the HashMap is empty or not.





Concurrency in Java



Table of Contents:







Introduction



What is concurrency?


You are reading this tutorial. And maybe your notepad software is open to take input from you. And at the same time you may have given your browser some tasks to download some videos and also listening some music from YouTube. And so on….
As you are habituated with these simultaneous activity with your computer, you may have taken this for granted. But if you dive deep into this, you will find that not only there are multiple tasks are being done simultaneously but also for every single task there are multiple task having done by your system like that streaming Youtube Music must simultaneously read the digital audio off the network, decompress it, manage playback, and update its display.
So, softwares that is able to do such things, is called concurrent software.


According to Oracle Doc:


“The Java platform is designed from the ground up to support concurrent programming, with basic concurrency support in the Java programming language and the Java class libraries. Since version 5.0, the Java platform has also included high-level concurrency APIs.”






Processes and Threads



In concurrent programming there are two basic units of execution:


  1. Processes
  2. Threads


Though in Java concurrent programming is mostly concerned with threads.


Processes:


  • Every process has a self contained execution environment. Each process has its own memory space.
  • It’s heavyweight.
  • Interprocess communication cost is higher.


Threads:
  • Thread is a lightweight process and it exist within a process — every process has at least one thread.
  • Threads share the process's resources, including memory and open files and this makes for efficient (but potentially problematic) communication.
  • Communication cost between threads is low.


The below picture depicts the relationship between process and thread well where 4 processes are there and in Process 1 there are 3 threads i.e. T1, T2 and T3 and the dotted lines between T1, T2 and T3 are showing the inter-thread communication and lightweightness of the same as these shares common memory of Process 1.






Common Java Program Examples:


Fibonacci series



Prime Number



Palindrome


Factorial



Armstrong Number



Sorting
Bubble Sort



Searching






Important Links for Reference / for future use:





Comments

  1. Nice article with useful resources. Thanks for sharing.
    https://www.flowerbrackets.com/java-program-to-check-armstrong-number/

    ReplyDelete

Post a Comment