Categories
discuss

Where do I begin learning all the different JavaScript technologies/libraries?

I’m building a site that’s sort of a cross between StackOverflow and Digg (only a different genre). Typically in the past I would have just built it using ASP.Net web forms. However I want to use this project as a way to learn new technologies. I’m using ASP.Net Mvc which is really great, but I need to learn/use some kind of javascript libraries.

For instance, when someone votes on a post I want it to be updated with the vote count immediately, or if someone types in text into the “tags” textbox, I want it to give a drop-down of currently used tags etc. Basically I want to provide a lot of the AJAXy stuff for my site.

So my question is where to I begin? I feel bombarded with so many options and I’m not sure where to start or even what they are. Can someone straighten me out and provide some explanation and direction?

  • JSON
  • JQuery
  • MS-AJAX

I’m sure there are bunch of others I can recall at the moment.

Answer

You should definitely start with the basics of Javascript. Start with things like printing “Hello World” to the page. Move on to basic language features like variables, loops, conditionals, and functions. I recommend the W3Schools Introduction to Javascript. Don’t get too caught up in trying to do object-oriented programming in Javascript. It is painful and confusing, even for some experienced Javascript programmers.

Next I strongly recommend learning to use a cross-browser Javascript library, rather than trying to do everything by hand (specifically: interacting with the DOM, performing XmlHttpRequests aka AJAX calls, etc.). I recommend the jQuery library. It provides a solid foundation for all of the cool AJAX-y things you want to do, and there are loads of plugins available for it.

jQuery is a Javascript framework that allows easy and reliable interactions with the Document Object Model (DOM). In simplest terms, the DOM is the representation of all the HTML elements in a web page. The DOM is slightly different from browser to browser, and interacting with it “by hand” is tedious and error prone. jQuery solves this problem by essentially doing all the hard work behind the scenes. It is much more powerful than that, really, but that’s the major feature. It also provides support for page events, custom events, plugins, CSS manipulation, and much more.

JSON is another term you mentioned. It stands for JavaScript Object Notation. JSON is simply a lightweight way to represent structures in Javascript (and other languages too, actually). To be honest, the Wikipedia JSON Article provides a much better summary of how JSON is used with AJAX than I ever could, so you might want to give it a read.

Here is the basic order of events:

  1. Your Javascript code makes an AJAX call to a web page. You can do this using the AJAX functions in jQuery.
  2. The result produced by that web page is a JSON object. For example, it might produce a string that looks like: { 'firstname':'Robert', 'lastname':'Smith' }
  3. The result is received by your AJAX call and evaluated using the special Javascript “eval” function.
  4. You are left with a native Javascript object that you can work with in your code. You can then do stuff like: document.write('Hello ' + result.firstname + ' ' + result.lastname)

Here are a few useful links I have collected over the past year or so that have helped me. I hope they help you too!

The most important thing to remember is: learn by doing. Experiment. Try new things. Make a bunch of proof of concept pages. With Javascript, that’s really the best way to get your feet wet. Good luck!

Categories
discuss

Variable naming conventions in Java?

In PHP, we (at least the good programmers) always start general variable names with a lower-case letter, but class variables/objects with an upper-case letter to distinguish them. In the same way we start general file names with a lower case letter, but files containing Classes with an upper case letter.

E.g:

<?php
$number=123;
$string="a string";
$colors_array=array('red','blue','red');
$Cat=New Cat();
?>

Are the conventions the same in java, i.e Objects starting with upper-case but the rest with lower case, or does everything start with lower case as I’ve read in other places?

Answer

Generally, all variables will start with lower case:

int count = 32;
double conversionFactor = 1.5d;

Some people like to put static constants in all case:

public static final double KILOGRAM_TO_POUND = 2.20462262;

Things get more annoying when you deal with acronyms, and there is no real standard on whether you should use:

HTMLHandler myHtmlHandler; 

or

HTMLHandler myHTMLHandler.

Now, either way, note that the class names (Object, String, HTMLHandler) always start with a capital letter, but individual object variables start lowercase.

Categories
discuss

Detecting Java Project Cruft

I’m a NetBeans 6.5 user and am searching for a way of generating a list of methods/classes that are not used within a set project group.

I know I can right click on each method and select “Find Usages” but I’m looking for an automation to that process.

I’m willing to look at something that runs outside of netbeans, as long as it generates a list of cruft methods/classes.

Thanks.

Answer

Obfuscators like proguard can shrink your jars by removing unused methods/classes. Maybe it is possible to get a verbose output which contains the list of removed (hence unused) classes/methods.

Here you can find more information about finding dead code with proguard.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..