shukla raghav

Ranch Hand
+ Follow
since Aug 03, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by shukla raghav

Thanks Stephan that was short and to the point. And thanks Ritchie for elucidating the reasons behind how twos complement works for datatypes in Java
8 months ago
I was trying to derive the Max and Min value of a java int type.

Key Points :

1. int takes 4 bytes = 32 bits
2. its signed data type so first bit will be assigned as signed bit (if value = 0 then its positive integer else if 1 then negative integer)
3. number of bits used for values = 31

Max value  = when all value bits are 1 and signed bit =0,
  therefore Max Value = Sum = (1 x 2^0) + (1 x 2^1) + (1 x 2^2) + (1 x 2^3).........(1 x 2^31)

Applying Formula for Geometric Progression

 Max Value  = a((r^n) - 1) / (n-1) = ((2^31) - 1) / (2-1) = (2^31) - 1 = 2147483648 - 1 = 2147483647
 
and the Min value should be just the Negative of the Max value because the sole difference between the two cases is the change in the Sign Bit value and nothing else. One should be just the negative of another then why is the value Max value = 2,147,483,647 while Min value is -2,147,483,648 ?

8 months ago
Hello Mr. Miroslav.

I was going through the free chapter of this book. I have reservations around your description of following features of OOP.

1. Abstraction: In my understanding abstraction does not mean to extract the common functionality without providing specific implementation. Abstraction refer to abstracting away the complexity or hiding the complexity or the details of implementation from the calling program. That is why the most common example of abstraction given in text books since ages is that of a car. A driver (synonymous with caller progam) is just provided with steering, transmission, gas pedal and breaks. The driver does not need to know the details of how the engine should work. And we can implement abstraction by using access-specifiers. With the help of access specifiers we can ensure to whom and how much details can be exposed. I can make the methods that can be accessed by a calling program public but this public method can in turn call a private method that encloses the complexity.
Rather the implementation of an interface itself is public because the implementation of an interface i.e the overriding method cannot be more restrictive than overridden method. So i dont understand how interface can help hide complexity from the calling program.

2. Encapsulation : In my understanding, all the data that has one single reason to change must be enclosed in single construct (class) and thats encapsulation. If my entity defines - then i better encapsulate all publisher info into a single class. Only expose whats required is actually abstraction and not encapsulation as I just mentioned above

Am I correct or missing something?  I love to be correct but I also enjoy being corrected.
8 months ago
Hi Kathy, Bert and Elisabeth,

I am eager to put Lambdas and Streams API to practice. I am sure this book would surely demistify some of these complex topics which are a Paradigm shift for a Java 8 aspirant.
I am personally excited to learn implementation of functional programming techniques and to understand and appreciate its benefits over previous ways of handling things in Java.

My excitement is soaring high

Thanks for this much awaited book

Sometimes I think that knowing Java is more of an impediment to learning JavaScript than a help. Be sure not to try and take OO in JavaScript beyond what is natural to the language. Be sure to embrace the functional nature of JavaScript and not rely over-heavily on the OO aspect.



Yes Mr. Bibeault, exactly that was my feeling while i started exploring object oriented javascript. There are certain features in OO based JS that at once seem like a great feature but you exactly don't know how are these utilized in a practical application. At one point i thought why not to go ahead with purely functional way of JS but then being a java developer the ease and manageability aspect of OO paradigm pushes you to go for the Object Oriented version of a technology.

Since Mr Raynders has well elucidated the strange capabilities of javascript, i have used the later approach he has suggested and works well for me. Thank you Mr Raynders.
I have recently started following Javascript and that too Object Oriented JS and also i am impressed with Object Oriented JS except for its poor support for collections. Anyways getting back to the main topic..As an exercise i tried to create a Validation library for my application but it seems the instance values scopes are either not understood by me or else this is strange behavior. In order to illustrate this behavior i have sliced down the library to basic minimum in order to present here.

  • The below given sample validates if the email format is correct or not.
  • The problem is visible when you enter the correct format like
    johndoe@gmail.com and click submit.
  • It will trigger the registered event which modifies the IS_ERROR
    instance field to false and displayed by alert 1.
  • Then if you click the submit button the update function is triggered by onclick event of the submit button that tries to display the
    IS_ERROR value again as per the alert 2.


  • surprizingly these two values are different. How is that possible?
    What am i missing?

    test.html


    validations.js

    Scenario : This is a customer support application and the scenario in question is Issue Resolution Scenario. Support Manager clicks a certain link which shows list of issues to be resolved. Corresponding to each issue is an input field where the Support Manager can add the name of a Support Executive and submits the form. This UI form is rendered from issueResolution.jsp .



    Backing Form Object : Resolution.java



    issueResolution.jsp



    If you see the issueResolution.jsp, the form would have multiple input tags. I expect the value of name attribute to form the Key in the allotments map in the backing object and the data entered by the user to be binded to corresponding value in the allotments map in the backing object (i.e. Resolution object).

    Since this is not a straight forward conversion. Using Property Editors and WebDataBinders is one way i would like to explore. But in this scenario it seems a little complicated. I am open to all ways except MessageConverters as of now.




    8 years ago
    Well i used apache commons codec for encoding and decoding the xml. escaping will not work here. Yes the encoding did the trick.

    9 years ago
    Hi Surendra, Actually i am not using any JSP as of now. Currently we are testing our REST API using FireFox Rest Client. yes it has got something to do with the way parameter values are passed although it seems to me that the = sign in prolog <?xml version="1.0" is taken as another assignment operator. But quite possible that replacing spaces with %20C or whatever HTML entity for space may do the trick.
    9 years ago

    In my current application i am required to pass two parameters to the REStful Spring MVC application. One parameter is an id and the other is an xml passed as a string.



    There is a complex operation that needs to be performed before the spring container passes the parameter to the controller method. Therefore i am using a Custom HttpMessageConverter to parse the obtained XML into a Template object.

    Here is the part of the Custom Converter that i am using



    To Test this i am using FireFox Rest Client (see attatchment)

    The problem is that i am just recieving <?xml version from http request where as the typeid parameter is perfectly mapped.

    All suggestions are welcome.
    9 years ago
    So Jayesh you mean to say that if the value in rest of the fields remain unchanged then there wont be any update operation for rest of the fields, Which to me does make some sense. In such a case we may for general purposes consider no additional cost associated with complete update. Do you have reference to any authentic resource that confirms the same. In that case it will save me lot of effort.

    10 years ago
    Well, I have considered writing utility that dynamically generate SQL at runtime with variable number of placeholders. The number of placeholders would always be same as the number of non-null params. This way i can use APPROACH-2 abstracting the logic for dynamic query generation and null-checks. I will post the code as soon as it is done.

    What i am surprised is that this is a pretty common use-case. How come i am unable to get some kind of a standard best practice for this ? how do you all handle such a situation. An update is mostly on partial data.

    Wish to look for as many replies as possible



    10 years ago


    I am myself surprised that this question never occurred to me before but this time i am bothered since i am creating my own application.

    I have a TaskDetail class that has 30 fields. while updating there could be only a small part of TaskDetail that may be updated like just the "endDate" of the task. We can use two strategies to update this field.

    APPROACH 1 : Update entire object with all the 30 fields and let the rest fields be overwritten in the database with the same value expect the changed field which will be updated with new value.
    OR
    APPROACH 2 : Update just the field that has been changed. In this case we would treat Employee as a DTO and just populate the "endDate" field with new value since it is the only field that needs to be changed.


    Both the approaches seem to have its pros and cons

    APPROACH 1 : (PROS) - Its a cleaner approach. (CONS) - We are unnecessarily over-writing 29 additional field for the sake of one field.

    APPROACH 2 : (PROS) - We are just updating the fields that are modified (CONS) - Makes the DAO dirty looking because we would need 30 null checks to identify which of field have to be updated.

    This problem is making me a little uncomfortable.

    Which of this approach is an accepted one or there is a third approach? I am not very much in favor of using hibernate although prefer Spring JDBC template.
    10 years ago
    I have developed a multi-module maven project with 9 modules. i wanted to test one of my service classes. so i simply wrote a main method in the class and executed the class and was left surprized with an exception stack that said "FileNotFoundException" and futher the reason was - The filename, directory name, or volume label syntax is incorrect

    Here are the details



    I am simply passing an XML as a string to build() method which processes the XML to create a Template Object using SAX parser. I dont think so the code here is causing any problem but it has got something to do with maven. I am recieving following exception when i run this main method.

    Exception in thread "main" java.io.FileNotFoundException: D:\Raghave\OSRMediaManager\mediamanager\documentmanagementsystem\ <page> <attribute key="color" param="@{BaseColor.BLUE}"\> <attribute key="size" param="12.2f"\> <\font> <content class="java.lang.String"\> <attribute key="anchor" param="123i" \> <attribute key="background" param="123i,145f,134d" \> <attribute key="font" param="${chunkfont}"\> <position xpos="23" ypos="25"\> <\title> <\template> (The filename, directory name, or volume label syntax is incorrect)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(Unknown Source)
    at com.bluebench.mediamanager.dms.utility.TemplateBuilder.build(TemplateBuilder.java:41)
    at com.bluebench.mediamanager.dms.utility.TemplateBuilder.main(TemplateBuilder.java:70)




    If you look at the stack you will see "java.io.FileNotFoundException: D:\Raghave\OSRMediaManager\mediamanager\documentmanagementsystem\" here this path is the path of the current maven module from which this class TemplateBuilder and main method are executed. How is it possible that JVM is unable to find the path of module from which the main method is executed ?

    Is It something like we cannot directly execute a main class from within maven module. IF this is true, i wanted to know why so and what are the options available for a quick test in that case ?

    I AM STUCK..
    10 years ago