tag:blogger.com,1999:blog-57251602261465723292024-03-14T04:07:01.226-07:00java discussionjavamitra, SamastipurJava Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.comBlogger167125tag:blogger.com,1999:blog-5725160226146572329.post-41612145129481064962023-04-02T00:05:00.001-07:002023-04-02T00:05:46.242-07:00C macro for factorial <div>Macro in C for computing the factorial of a number:</div><div>#include <stdio.h></div><div><br></div><div>#define FACT(n) ((n <= 1) ? 1 : n * FACT(n-1))</div><div><br></div><div>int main() {</div><div> int n = 5;</div><div> int result = FACT(n);</div><div> printf("Factorial of %d is %d\n", n, result);</div><div> return 0;</div><div>}</div><div><br></div><div>Result:</div><div>Factorial of 5 is 120</div><div><br></div><div>Explanation:</div><div>In this example, the FACT macro with an argument n is defined that calls itself recursively to compute the factorial of n.</div><div><br></div><div>The ternary operator is used to check whether n is less than or equal to 1. If so, it returns 1, which is the base case of the recursive algorithm. If n is greater than 1, the macro multiplies n by the result of FACTORIAL(n-1), which computes the factorial of n-1.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div>Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-27105105129152475262023-04-01T00:30:00.001-07:002023-04-01T02:20:09.254-07:00macro programming in C<br><div>Macro programming in C involves the use of preprocessor directives to define macros, which are essentially short pieces of code that can be used to simplify the programming process. Here's an example of how to use macros in C:</div><div><br></div><div>#include <stdio.h></div><div><br></div><div>#define SQUARE(x) ((x) * (x))</div><div><br></div><div>int main()</div><div>{</div><div> int num = 5;</div><div> int square = SQUARE(num);</div><div><br></div><div> printf("The square of %d is %d\n", num, square);</div><div><br></div><div> return 0;</div><div>}</div><div>In this example, we define a macro called SQUARE, which takes a single argument x and returns the square of x. We then use the macro in our main function to calculate the square of the variable num, and store the result in a new variable called square.</div><div><br></div><div>video demonstration</div><div><br></div><div>Also we surround the entire macro definition with parentheses to ensure that the order of operations is correct, and surround the argument x with parentheses within the macro itself to prevent any unexpected behavior when the macro is used.</div><div><br></div><div>When we compile and run this program, we should see the following output:</div><div><br></div><div><br></div><div>The square of 6 is 36</div><div><br></div><div>This is because the macro SQUARE has replaced the expression SQUARE(num) with ((num) * (num)), which evaluates to 25 in this case.</div>Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-45230819023626633212021-07-17T09:40:00.004-07:002021-07-17T09:42:05.781-07:00How to sort elements of vector object on particular column<p></p><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen="" class="BLOG_video_class" height="266" src="https://www.youtube.com/embed/F_NZDaEHlOk" width="320" youtube-src-id="F_NZDaEHlOk"></iframe></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;">Using sort() method on vector object we can sort elements of vector object.</div><div class="separator" style="clear: both; text-align: left;">For this purpose we need to create our own comparator.</div><div class="separator" style="clear: both; text-align: left;">Steps to follow</div><div class="separator" style="clear: both; text-align: left;">1. Create own Comparator class by implementing Comparator interface and define compare method.</div><div class="separator" style="clear: both; text-align: left;">2. use vector.sort() method and pass the object of your own Comparator implemented class.</div><div class="separator" style="clear: both; text-align: left;">3. finally you vector object will have sorted elements as per your compare() method defined.</div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;">Please go through the above video for more in details.</div><div class="separator" style="clear: both; text-align: center;"><br /></div><br /> <p></p>Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-49475141205920870362021-07-04T09:02:00.009-07:002021-07-17T09:42:27.129-07:00Java Collection #20 | Using Vector Part-2<iframe frameborder="0" height="270" src="https://youtube.com/embed/o-tFrSbbrOI" width="480"></iframe><div>How to add custom object to Vector?</div><div>What is the requirement to be able to search an custom object from vector?</div><div>Why and how to override equals() method?</div>Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com1tag:blogger.com,1999:blog-5725160226146572329.post-20690893300049113282021-07-04T08:43:00.004-07:002023-04-01T02:18:19.774-07:00Java Collection #19 | Using Vector<div>Video demonstration </div><div><br></div><div>How to use java.util.Vector</div><div>How it is different from java.util.ArrayList</div><div>Different ways to add or remove elements.</div><div><br></div><div>In Java, a vector is a dynamic array that can grow or shrink in size based on the number of elements it contains. The Vector class in Java is a part of the java.util package and provides methods for manipulating dynamic arrays.</div><div><br></div><div>To use the Vector class in Java, we need to import the java.util package at the beginning. Here is an example:</div><div><br></div><div><br></div><div><br></div><div>import java.util.Vector;</div><div><br></div><div>public class MyClass {</div><div> public static void main(String[] args) {</div><div> // create a vector</div><div> Vector<String> vector = new Vector<String>();</div><div> </div><div> // add elements to the vector</div><div> vector.add("Apple");</div><div> vector.add("Banana");</div><div> vector.add("Orange");</div><div> </div><div> // get the size of the vector</div><div> int size = vector.size();</div><div> System.out.println("Size of vector: " + size);</div><div> </div><div> // access an element in the vector</div><div> String element = vector.get(1);</div><div> System.out.println("Element at index 1: " + element);</div><div> </div><div> // remove an element from the vector</div><div> vector.remove(2);</div><div> </div><div> // print all elements in the vector</div><div> for (String s : vector) {</div><div> System.out.println(s);</div><div> }</div><div> }</div><div>}</div><div><br></div><div><br></div><div>In this example, we create a vector of strings, add elements to it, get the size of the vector, access an element in the vector, remove an element from the vector, and print all elements in the vector using a for-each loop. Note that the Vector class is synchronized, which means that it is thread-safe and can be used in a multi-threaded environment.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div>Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com2tag:blogger.com,1999:blog-5725160226146572329.post-15468487924958226712021-07-02T12:43:00.002-07:002021-07-02T12:43:18.085-07:00Requirement to use TreeSet for custom object<p> </p><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen="" class="BLOG_video_class" height="266" src="https://www.youtube.com/embed/327EwSlAR0A" width="320" youtube-src-id="327EwSlAR0A"></iframe></div>The video explains about<p></p><p>1. How to use TreeSet?</p><p>2. What is the requirement for a custom object to be added to Treeset?</p><p>3. What is Comparable and Comparator?</p><p>4. When and how to use Comparable?</p><p>5. When and how to use Comparator?</p><p>6. How to iterate the elements added to the TreeSet object?</p>Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-31134311390486377072020-06-11T08:10:00.001-07:002020-06-11T08:10:51.020-07:00Promote your service in your local area<ul><li class="text-muted">Join <a href="https://wamfeos.com/">wamfeos.com</a></li><li class="text-muted">To be a part of family.</li><li class="text-muted">To fill the gap between producer and consumer services.</li><li class="text-muted">To reach to the needy person to serve in your locality.</li><li class="text-muted">To satisfy your daily needs by your local service provider.</li><li class="text-muted">You can raise a request as per your time schedule:</li><ul><li class="text-muted">To provide best service.</li><li class="text-muted">To receive the best service.</li><li class="text-muted">The consumer will add a feedback after work completion.</li><li class="text-muted">This feedback will help others to select the best service provider near them depending upon the feedback & area pincode.</li><li class="text-muted">The feedback points will be shown with every service provider profile.</li></ul></ul><h5 class="text-muted">Membership Benefits:</h5><ul><li class="text-muted">Own custom web page on <a href="https://wamfeos.com/">wamfeos.com</a> (AMC applied).</li><li class="text-muted">You will have an dashboard to manage your own profile & service page.</li><li class="text-muted">You will able to</li><ul><li class="text-muted">Add and change your logo.</li><li class="text-muted">Upload profile picture.</li><li class="text-muted">Add your own article with images(if any).</li><li class="text-muted"><b>Promote</b> your products or services.</li><li class="text-muted">get online enquiry request.</li><li class="text-muted">As per consumer satisfaction, service provider will receive a feedback from consumer that will help you to get more valuable consumers.</li><li class="text-muted">Your profile will be viewed by other visitors, sorted on the basis of the feedback.</li></ul></ul>Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-80254673752080698732020-02-27T03:30:00.001-08:002020-02-27T03:30:46.361-08:00what is pointer<div>Pointer in c language is a variable that stores the address of other variable at run time (dynamically). It can be of any primitive data type or user defined data type. Pointer enables us to access a variable that might be defined outside the function. <br></div>Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com2tag:blogger.com,1999:blog-5725160226146572329.post-79517254744399361532020-02-27T03:29:00.001-08:002020-02-27T03:29:46.772-08:00Why doesn't Java have pointers?<div>First we need to discuss about pointer before going further.</div><div><br></div><div>Pointer in c language is a variable that stores the address of other variable at run time (dynamically). It can be of any primitive data type or user defined data type. Pointer enables us to access a variable that might be defined outside the function. </div><div><br></div>Java has pointers everywhere but terminology is different. In java, objects created are referred/pointed by reference variable. Except primitive data type, everything in java is instance or object which can be used via reference variable which is similar to pointer in c/c++. <div>But there is no 'address of' (&) operator to get the address of the object as we can in c/c++.</div><div><br></div><div>So, </div><div>1. we can't use pointer arithmetic like things in java. </div><div>2. We can't use get the address of an object.</div><div>3. We can't move from one node to another by incrementing the pointer, as we can in c/c++</div><div>4. We can use pointer for an array and traverse the whole array via pointer increment or decrement.</div><div><br></div>Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-60031263718360279822020-01-11T02:50:00.002-08:002020-01-11T03:11:43.241-08:00Send or Receive Email using java<div dir="ltr" style="text-align: left;" trbidi="on">
It is necessary to activate your gmail account to be accessed from less secure app. For this purpose You should have to be login to your gmail account which you want to for sending/receiving email using java and then just visit following <a href="https://myaccount.google.com/u/1/lesssecureapps" target="_blank">link</a> whose screenshot is given below.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDUNxACGsVXyjYgq-4e8abIpDtZRn7xKVSMLa9fzm7RmNbjtl1QKCyBGi1DxxAFhGV7IDUXxzkxuIRPmZ-Mex-S49H5b8qfCWN7enKaO2BLeLk4gkxTHzgzheNLPOpH9yrvE0fHyGp_5Q/s1600/lesssecureappaccess.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="384" data-original-width="929" height="132" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDUNxACGsVXyjYgq-4e8abIpDtZRn7xKVSMLa9fzm7RmNbjtl1QKCyBGi1DxxAFhGV7IDUXxzkxuIRPmZ-Mex-S49H5b8qfCWN7enKaO2BLeLk4gkxTHzgzheNLPOpH9yrvE0fHyGp_5Q/s320/lesssecureappaccess.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
Now you have to click the toggle button to ON the allow less secure apps.</div>
<div class="separator" style="clear: both; text-align: left;">
It will allow your java program to access your gmail.</div>
<div class="separator" style="clear: both; text-align: left;">
If you need video instruction regarding program just follow these two videos:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
How to fetch email from Gmail using javamail API</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/WIiKphBuykk/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/WIiKphBuykk?feature=player_embedded" width="320"></iframe><br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
How to send email from your gmail using Java</div>
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/ONa3TFdTS88/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/ONa3TFdTS88?feature=player_embedded" width="320"></iframe><br />
<br /></div>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-75344117433408941932019-06-19T22:16:00.000-07:002019-06-19T22:16:17.719-07:00How do you reverse any string without using any function<div dir="ltr" style="text-align: left;" trbidi="on">
Just loop for strings length in reverse order, use pick each character from last index to first and concatenate into single string<br />
<br />
<br />
Please add your answer in comment section </div>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com1tag:blogger.com,1999:blog-5725160226146572329.post-59128181524235926552019-06-19T22:10:00.002-07:002019-06-19T22:16:17.711-07:00How do you remove all white spaces from a give. String<div dir="ltr" style="text-align: left;" trbidi="on">
Use StringTokenizer with default constructor and retrieve and concatenate all the tokens into a single string.<br />
<br />
On <a href="https://www.quora.com/How-do-you-remove-all-white-spaces-from-a-string-in-Java/answer/Amit-Ranjan-317?ch=10&share=0ed28195&srid=h5t7z">quora</a></div>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com1tag:blogger.com,1999:blog-5725160226146572329.post-37396560696371956402019-03-20T00:47:00.001-07:002019-03-20T00:47:01.723-07:00float vs double<p dir="ltr"><b>float</b></p>
<p dir="ltr">If we want 5 to 6 decimal places of accuracy then we should go for float.</p>
<p dir="ltr">Float data type is a single-precision 32-bit IEEE 754 floating point.</p>
<p dir="ltr">Float is mainly used to save memory in large arrays of floating point numbers.</p>
<p dir="ltr">Default value is 0.0f.</p>
<p dir="ltr">Takes 4 bytes to store a variable.</p>
<p dir="ltr">Range is -3.4 E38 to +3.4 E3</p>
<p dir="ltr"><b>double</b></p>
<p dir="ltr">If we want 15 to 16 decimal places of accuracy then we should go for double.</p>
<p dir="ltr">double data type is a double-precision 64-bit IEEE 754 floating point.</p>
<p dir="ltr">This data type is generally used as the default data type for decimal values, generally the default choice.</p>
<p dir="ltr">Default value is 0.0d.</p>
<p dir="ltr">Takes 8 bytes to store a variableRange is -1.7 E308 to +1.7 E308</p>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-76032180276857805132019-03-19T23:56:00.001-07:002019-03-19T23:56:38.119-07:00Python Keyword<p dir="ltr"><br>
Method Description<br>
and A logical operator<br>
as To create an alias<br>
assert For debugging<br>
break To break out of a loop<br>
class To define a class<br>
continue To continue to the next iteration of a loop<br>
def To define a function<br>
del To delete an object<br>
elif Used in conditional statements, same as else if<br>
else Used in conditional statements<br>
except Used with exceptions, what to do when an exception occurs<br>
False Boolean value, result of comparison operations<br>
finally Used with exceptions, a block of code that will be executed no matter if there is an exception or not<br>
for To create a for loop<br>
from To import specific parts of a module<br>
global To declare a global variable<br>
if To make a conditional statement<br>
import To import a module<br>
in To check if a value is present in a list, tuple, etc.<br>
is To test if two variables are equal<br>
lambda To create an anonymous function<br>
None Represents a null value<br>
nonlocal To declare a non-local variable<br>
not A logical operator<br>
or A logical operator<br>
pass A null statement, a statement that will do nothing<br>
raise To raise an exception<br>
return To exit a function and return a value<br>
True Boolean value, result of comparison operations<br>
try To make a try...except statement<br>
while To create a while loop<br>
with Used to simplify exception handling<br>
yield To end a function, returns a generator</p>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-71486792619455884682019-03-01T06:01:00.001-08:002019-03-01T06:11:38.993-08:00How to notify Android app user about new version update<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: justify;">
Many times we want to force the user of our Android app to be updated, but the user ignore to update even when Google play store reminds to update. This video fairly deals with this problem.</div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
If the app is already updated, it will show the current version, otherwise a pop-up with a button that says to update. When user click on update, it will open the Google play store, and hence user will do the update. If user click cancel, the application will be terminated.</div>
<div class="separator" style="clear: both; text-align: center;">
<iframe width="320" height="266" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/S39z4f6XLwE/0.jpg" src="https://www.youtube.com/embed/S39z4f6XLwE?feature=player_embedded" frameborder="0" allowfullscreen></iframe></div>
<br /></div>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-37410013867412820212018-12-27T23:32:00.000-08:002018-12-28T00:25:13.251-08:00Anycast<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #565656; font-family: Nunito, sans-serif; font-size: 17px;">AnyCast is a Wi-Fi display receiver, which supports the Miracast standard for Android & Microsoft Windows, and DLNA for the home multimedia application.</span><br />
<br />
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-in.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=IN&source=ac&ref=tf_til&ad_type=product_link&tracking_id=javamitra-21&marketplace=amazon&region=IN&placement=B07DNFHQK9&asins=B07DNFHQK9&linkId=5bc1ff0fa862cf69c9dc380ca1f16e15&show_border=false&link_opens_in_new_window=false&price_color=333333&title_color=0066c0&bg_color=ffffff" style="height: 240px; width: 120px;">
</iframe>
<br />
<br />
<br /></div>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-10175141389967456852018-09-15T23:43:00.001-07:002018-09-15T23:43:05.852-07:00Scholarship for graduate and post graduate females<div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSfsx8k6BkhNRTJjD8-KDC9sdqiTAin8PoK31jyC_zjfrGlRs2tAnKbVQTtj_7WkqPVJkjt6LhdkaIxd2H43lqcPV6BWbmBEQtTX5dBPv2Q4PfhOMxr5mG2z5IgTc8uSn-NhiHH4jqhZM/s1600/IMG-20180916-WA0014.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSfsx8k6BkhNRTJjD8-KDC9sdqiTAin8PoK31jyC_zjfrGlRs2tAnKbVQTtj_7WkqPVJkjt6LhdkaIxd2H43lqcPV6BWbmBEQtTX5dBPv2Q4PfhOMxr5mG2z5IgTc8uSn-NhiHH4jqhZM/s640/IMG-20180916-WA0014.jpg"> </a> </div>Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com3tag:blogger.com,1999:blog-5725160226146572329.post-24339647942143429312018-05-20T00:58:00.001-07:002018-05-20T00:58:01.668-07:00What is Object oriented programming:<p dir="ltr"></p>
<p dir="ltr">Father - Son, go and get Red Label<br>
Son - 750ml or 1 ltr??</p>
<p dir="ltr">Mother - Son, go and get Red Label<br>
Son - 500gms or 1 kg??!!</p>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-81924548871923213462018-05-09T21:28:00.001-07:002018-05-10T02:36:19.393-07:00My student achieved a certificate<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAXBGLEz8WcRZ8-TUMqhzWSc1kM7OZLvzld_K7IYe3EF9eqgTSoOSq0oiv0V_hCfdSaBK6cyObnynWZgWx-fS7NfbB4sJs98-mVM4uaZn5gNQNffZl-5LEGDmC62Nm3jS9c1fwVnqcUuM/s1600/IMG-20180510-WA0000.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAXBGLEz8WcRZ8-TUMqhzWSc1kM7OZLvzld_K7IYe3EF9eqgTSoOSq0oiv0V_hCfdSaBK6cyObnynWZgWx-fS7NfbB4sJs98-mVM4uaZn5gNQNffZl-5LEGDmC62Nm3jS9c1fwVnqcUuM/s320/IMG-20180510-WA0000.jpg" width="320" /> </a> </div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
Its great news for me, when I knew that Er. Mayank Kumar has worked on java project for ZipUnzip software, and achieved this certificate from Vinoba Behave University, Hazaribag.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
He is one of my best student and I wish him a bright future.</div>
</div>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com1tag:blogger.com,1999:blog-5725160226146572329.post-33391598912515865912018-05-09T03:24:00.001-07:002018-05-09T03:31:53.431-07:00Why downcasting in java is dangerous<p dir="ltr">By casting we don't cast the real object, but just labelled it in different ways. Cat can be upcast to Animal, but the real object always remains cat, however we labelled it as Animal, however if need to get the properties of cat, we have to downcast from Animal to Cat.</p>
<p dir="ltr">But, if we will try to downcast in inappropriate class type which is not actually referred by the reference variable, then it gives an exception.</p>
<p dir="ltr">For example:</p>
<p dir="ltr">If superclass reference holds the object of subclass then it's okay to type cast, but just imagine if it doesn't…</p>
<p dir="ltr">class A{}</p>
<p dir="ltr">class B extends A{}</p>
<p dir="ltr">A a = new B()</p>
<p dir="ltr">B b = (B)a; // no problem</p>
<p dir="ltr">A a1 = new A();</p>
<p dir="ltr">B b1 = (B)a1; // type cast causes error</p>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-55251382404745656472018-04-17T09:32:00.001-07:002018-04-17T09:32:52.050-07:00Why the java.lang.System neither abstract nor instantiable<p dir="ltr">It’s to prevent you from making a subclass that can be instantiated. In Java:</p>
<p dir="ltr">* an abstract class cannot be instantiated, but its subclasses can be </p>
<p dir="ltr">* a final class cannot be subclassed </p>
<p dir="ltr">* <u>a</u> class cannot be both final and abstract</p>
<p dir="ltr">The System class has a <b>private constructor</b> to prevent you from instantiating it (this is good practice for “utility classes”), and it is final <u>to</u> prevent you from getting around that by <i>creating a subclass that has a usable constructor</i>. And because it is final, it cannot be abstract</p>
<p dir="ltr">Regards: https://www.quora.com/Why-isn-t-the-Java-lang-system-class-in-Java-an-abstract-when-it-cannot-be-instantiated/answer/Jon-Harley?share=782923fd&srid=h5t7z</p>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com7tag:blogger.com,1999:blog-5725160226146572329.post-69081854469627090322018-03-28T06:51:00.001-07:002018-03-28T06:51:25.520-07:00What, If i reject you in this interview<p dir="ltr"><i>This question is asked to check the performance of the candidate under stress.</i></p>
<p dir="ltr">When the interviewer asks this question, you are already in his <b>top list</b>.</p>
<p dir="ltr"><b>Interviewer-</b><b> What is the answer of "If I reject you in this interview then what will you do"?</b></p>
<p dir="ltr"><i>Don’t get tensed. Keep your cool. Think about your interviewer. Be a bit empathetic.</i></p>
<p dir="ltr"><b>Worst answer</b></p>
<p dir="ltr">I will learn and make myself better. I won’t get hurt bla bla bla.</p>
<p dir="ltr">(Nobody wants to hire someone who is self centered and thinks about himself only).</p>
<p dir="ltr"><b>Good answers</b></p>
<p dir="ltr">I’m sorry that I wasted your time, Sir. Have a wonderful day ahead. Hope you find the right candidate.</p>
<p dir="ltr"><b>or</b></p>
<p dir="ltr">I will eat something good in my lunch and will watch Game of Thrones (with a humour).</p>
<p dir="ltr"><b>or</b></p>
<p dir="ltr">(If it is a campus interview)</p>
<p dir="ltr">You can say “Okay Sir. No problem. Let me know if I can help you with any other thing. If you want, I can be your guide for a local tour.”</p>
<p dir="ltr"><b>(Companies hire people who can work continuously without losing their cool in stressful conditions.)</b></p>
<p dir="ltr"><b>Best Answer (If you want to take a risk)</b></p>
<p dir="ltr"><b>You-</b><b> </b>Of course, you can reject me.</p>
<p dir="ltr"><i>(Treat the interviewer as your client. First agree with him. Keep your cool.)</i></p>
<p dir="ltr"><b>Interviewer-</b><b> </b>Okay. I’m going to reject you.</p>
<p dir="ltr"><b>You-</b><b> </b>But!!!</p>
<p dir="ltr"><b>Interviewer-</b><b> </b>But what?</p>
<p dir="ltr"><b>You-</b> Will you find another candidate like me?</p>
<p dir="ltr"><i>(You just questioned his decision. He has to think again.)</i></p>
<p dir="ltr"><b>Interviewer-</b><b> </b>I will try to find a better one.</p>
<p dir="ltr"><i>(But, when, how, where? lots of probability.)</i></p>
<p dir="ltr"><b>You-</b><b> </b>It may take you some time, Sir. But, what if you won’t find a good candidate like me?</p>
<p dir="ltr"><i>(You just stated him the consequences if he won’t select you today.)</i></p>
<p dir="ltr"><b>Interviewer-</b><b> </b>I will call you and hire you. Is that okay?</p>
<p dir="ltr"><b>You-</b><b> </b>Do you think, I will be available for hiring?</p>
<p dir="ltr"><i>(You just created an urgency. If he won’t hire you today, he will lose you for ever.)</i></p>
<p dir="ltr"><b>What you think, will you get hired after this?</b></p>
<p dir="ltr">I’m sure, you will get selected…</p>
<p dir="ltr">Regards : <u>Quora</u> - Barun <u>Mohanty</u></p>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-23361351475247769682018-01-25T00:48:00.001-08:002018-01-25T00:48:27.383-08:00UGC NET New Pattern<div class="separator" style="clear: both; text-align: center;"> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsS4jYr21nXgphogUnszBCJ2DmMYwLhUmrx4HhmiOKheaRMnZ3IwJw9OAVPZnunNhcEpy3a_J2DRzu48NWc8vxNZchlwuxc1l2e5khqdpJHDm2xVwDcR6XF1Kf-J2mq3x3wxVxNUWpU5M/s1600/IMG-20180124-WA0026.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> <img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsS4jYr21nXgphogUnszBCJ2DmMYwLhUmrx4HhmiOKheaRMnZ3IwJw9OAVPZnunNhcEpy3a_J2DRzu48NWc8vxNZchlwuxc1l2e5khqdpJHDm2xVwDcR6XF1Kf-J2mq3x3wxVxNUWpU5M/s640/IMG-20180124-WA0026.jpg"> </a> </div>Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-7143098413295452912017-08-25T21:32:00.001-07:002017-08-25T21:32:11.734-07:00Why it shows error when we keep different class name in different program<p dir="ltr">If you want to keep different class name, just remove '<b>public</b>' keyword before class name.</p>
<p dir="ltr">It should be taken care that <b>if a class is declared public, the java file name should be same as class name.</b></p>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0tag:blogger.com,1999:blog-5725160226146572329.post-73186182162197375362017-08-14T07:37:00.001-07:002017-08-14T07:37:09.456-07:00Why Char array is preferred over String to store password<p dir="ltr">String is <b>immutable</b> in java and stored in a separate pool called String pool pool of interned String. Once it's created it stays in the pool until unless it is garbage collected. <br>
So even though we are done with password it's available in memory for longer duration and there is no way to avoid it. It's a security risk because anyone having access to memory dump can find the password as clear text.<br>
If we use char array to store password, we can set it to blank once we are done with it. So we can control for how long it's available in memory that avoids the security threat with String.</p>
<p dir="ltr"><a href="http://googleweblight.com/i?u=http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html&hl=en-IN">String</a> strPassword="Unknown";<br>
char[] charPassword= new char[]{'U','n','k','w','o','n'};<br>
System.out.println("String password: " + strPassword);<br>
System.out.println("Character password: " + charPassword);</p>
<p dir="ltr">String password: Unknown<br>
Character password: [C@110b053]<br>
</p>
Java Mitrahttp://www.blogger.com/profile/08501750120817164659noreply@blogger.com0