Java Script

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

INTERVIEW QUESTIONS- JAVA SCRIPT

Q1.JavaScript vs. Jscript


Both JavaScript and Jscript are almost similar. Java script was developed by Netscape. Microsoft implemented its own scripting language and named it as Jscript. As Jscript runs in Internet Explorer, it has the access to different objects that are exposed by the browser. ActiveXObject is one such object.

Q2.What is the difference between Client side JavaScript and Server side JavaScript.
Client side java script comprises the basic language and predefined objects which are relevant to running java script in a browser. The client side java script is embedded directly by in the HTML pages. This script is interpreted by the browser at run time. Server side java script also resembles like client side java script. It has relevant java script which is to run in a server. The server side java scripts are deployed only after compilation.

Q3.where are cookies actually stored on the hard disk?


The storage of cookies on the hard disk depends on OS and the browser. The Netscape navigator on Windows, the file cookies.txt contains all the cookies. The path is : c:\Program Files\Netscape\Users\username\cookies.txt The Internet Explorer stores the cookies on a file by name [email protected] is c:\Windows\Cookies\[email protected]

Q4.What is the difference between a web-garden and a web-farm?


Web garden is a web hosting system. It is a setup of multi processors in single server. Web farm is a web hosting system. It is a multi-server scenario.

Q5.What is the difference between SessionState and ViewState?


The values of controls of a particular page of the client browser is persisted by ViewState at the time of post back operation is done. If the user requests another page, the data of previous page is no longer available. The data of a particular server persists in the server by SessionState. The availability of the user data is up to the completion of a session or closure of the browser.

Q6.How to Accessing Elements using javascript?


The elements of JavaScript are accessed by their names. By default the browser is accessed by the element windows and the page by document. The corresponding element has user defined names for forms and its elements. For example var passwd = windows.document.frmLogin.password.value; assigns the value of the password field of the form fromLogin in the current document, where password is the name of the element and frmLogin is the name of the form. Like wise any form element is accessed.

Q7. What is the difference between undefined value and null value?
Undefined value: A value that is not defined and has no keyword is known as undefined value. For example in the declaration, int number; the number has undefined value. Null value: A value that is explicitly specified by the key word null is known as null value. For example in the declaration, String str=null; the str has a null value. The keyword null is used here

Q8.How to set the cursor to wait in JavaScript?


The cursor can set to wait in JavaScript by using the property cursor property. The following example illustrates the usage. window.document.body.style.cursor = "wait"; // sets the cursor shape to hour-glass.

Q9. What is decodeURI(), encodeURI() in JavaScript?


To send the characters that can not be specified in a URL should be converted into their equivalent hex encoding. To perform this task the methods encodeURI() and decodeURI() are used. For example, the following code snippet performs the encoding of URL: <script type="text/javascript"> var uri = http://www.mysite.com/city?=Banglore; // original URI var ncodeuri=encodeURI(uri); document.write("<br />ncodeuri); var dcodeuri = decodeURI(ncodeuri); document.write(<br>/>dcodeuri); </script>

Q10.Methods GET vs. POST in HTML forms.


Encoding form data into URL is needed by the GET method. The form data is to be appeared within the message body , by the POST method. By specification, GET is used basically for retrieving data where as POST is used for data storing, data updating, ordering a product or even e-mailing.

Q11.What does the EnableViewStateMac setting in an aspx page do?


EnableViewStateMac setting is a security measure in ASP.Net. It ensures the view state for a page not to tamper. To to so EnableViewStateMac=true is used. ASP.net detects the change in the value of view state sent to the browser when Postback action takes place and raises an error Validation of view state MAC failed.

Q12.What are windows object and navigator object in JavaScript?


Windows object is top level object in Java script. It contains several other objects such as, document, history, location, name, menu bar etc., in itself. Window object is the global object for Java script that is written at client-side. Information pertaining to the client browser and system is returned by the navigator object of JavaScript. Navigator object is the top level object for all users

Q13.How to detect the operating system on the client machine in JavaScript?


The navigator.appVersion string should be used to find the name of the operating system on the client machine. The following code snippet returns the appropriate Operating systems. var OSName="Unknown OS"; if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows"; if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS"; if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX"; if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

Q14.How to set a HTML document's background color in JavaScript?


Using document object the back ground color can be changed by JavaScript. The following example illustrates it. <html> <body> <script type="text/javascript"> document.body.bgColor="green"; </script> </body> </html>.

Q15. How do you assign object properties in JavaScript?


Java script object properties are assigned like assigning a value to a variable. For example, the title property of document object can be assigned as follows: document.title="Welcome to the world of Javascripting"; The submit value of forms action object is assigned as follows: Document.form.action=submit

Q16.What is JavaScript?
Java script is a scripting language used for client side scripting. Web pages can be made more interactive with java script. Java script runs on client system which does not require constant downloads from the website. Java script is suitable for designing interactive web sites. It supports some of the objects like Array, String, Object, Date etc. It enables the HTML code to interact scripting, thus enables web authors to combine the sites with dynamic content.

Q17.What boolean operators does JavaScript support?


Java script supports &&, || and ! boolean operators.

Q18.Is a javascript script faster than an ASP script?


Yes, java script is faster than ASP script. Since java scripting is written for client-side machines / browsers, it does not need the web servers support for execution. Hence it is always faster than ASP scripting.

Q19.What is == operator?
The == operator in java script is used for determining equality of two variables or values. The expression returns true if both the values are equal.

Q21.What is negative infinity?


Negative infinity is a number in java script, which is derived by dividing negative number by zero

Q22.Whats relationship between JavaScript and ECMAScript?


ECMA stands for European Computer Manufacture Association. ECMA script is the official name for java script for accessing XML elements.

Q23.What does isNaN function do?


NaN stands for not-a-number. The function isNaN determines the argument or the value is a NaN. The function returns true if the argument is not a number, otherwise returns false

Q24.How to read and write a file using javascript?


Files can be read and written by using java script functions fopen(),fread() and fwrite(). The function fopen() takes two parameters 1. Path and 2. Mode (0 for reading and 3 for writing). The fopen() function returns -1, if the file is successfully opened. Ex: file=fopen(getScriptPath(),0); The function fread() is used for reading the file content. Ex: str = fread(file,flength(file) ; The function fwrite() is used to write the contents to the file. Ex(): file = fopen("c:\MyFile.txt", 3);// opens the file for writing fwrite(file, str);// str is the content that is to be written into the file.

Q25.How do you create a new object in JavaScript?


A function is used for creating custom object classes, by calling it by using the keyword new. A special variable this is references the new object that is being constructed(current object). This function must not return a value. The following code snippet depicts the creation of an object of class myclass. function myclass() { this.containedValue = 0; this.othercontainedValue = 0; this.anothercontainedValue = 0; } var myobject = new myclass();

Q26.How to create arrays in JavaScript?


Arrays are created by using new Array() in Java Script. For example var employees = new Array(); The elements to this array is assigned as follows employees[0] = "Kumar" employees[1] = "Fedrick"

Q27.Overview of Ruby programming language.


Ruby is a dynamic, open source programming language. It focuses on productivity and simplicity. The syntax is elegant which is natural to read and easy to write and use. The language is flexible, since it allows the developers alter freely all its parts. At will, one can remove essential parts and redefined. For instance , the symbol + can be redefined by the word plus to one of the its classes Numeric. Ruby supports multiple programming paradigms, such as, functional, imperative, object oriented, relative. Dynamic memory management and dynamic type systems are additional features of Ruby

Q28.What is Rails?
Ruby on Rails is a web application framework. It is written in Ruby. Compare to other frameworks for web application, the big deal is the way Ruby on Rails does. A web application finished in days instead of weeks, it is noticed by the community. Maintenance and/or extension of messy and hard web applications is flexible with ruby rails.

Q29.Describe class libraries in Ruby.


Ruby class libraries comprise of variety of domains, such as thread programming, data types, various domains. It has additional libraries evolving day by day. The following are the domains which has relevant class libraries. Text processing - File, String, Regexp for quick and clean text processing. CGI Programming - There are supporting class library for CGI programming support like, data base interface, eRuby, mod_ruby for Apache, text processing classes. Network programming Various well-designed sockets are available in ruby for network programming. GUI programming Ruby/Tk and Ruby/Gtk are the classes for GUI programming

XML programming UTF-8 text processing regular expression engine make XML programming very handy in ruby. .

30.Explain the concepts and capabilities of garbage collection feature of Ruby.


Garbage collection is the process of reclaiming the memory space. Ruby avoids memory leaks at a great extent. Ruby performs garbage collection automatically. The memory resource management for allocation and deallocation is not hard coded. Dynamic storage space allocation in the memory space is done there by avoiding scores of application crashes.

31.Describe the environment variables present in Ruby.


Environment variables can be directly accessed by using ENV hash. Environment variables can be directly read or written to by using the index operator supplied with a string argument. The child processes of ruby script only are affected by writing ruby environment variables. Ex: #!/us/bin/envy ruby # Print some variables puts ENV['PATH'] puts ENV['EDITOR'] # Change a variable then launch a new program ENV['EDITOR'] = 'edit' Environment variables can be set by using Set TEST=value Environment Variables Used by Ruby

RUBYOPT - To add command line switches. RUBYPATH - To list the path when used with the -S switch on the command line. RUBYPATH will be added to the paths searched when looking for Ruby scripts. The paths in RUBYPATH precede the paths listed in PATH. RUBYLIB The paths list will be added to the path list of Ruby that uses for searching libraries including the program with the require method. The paths in RUBYLIB will be searched before other directories.

32.Interpolation is a very important process in Ruby, comment.


Inserting a string into a literal is called as interpolation. Interpolation is a very important process in Ruby. Interpolation can be done by using only one way by embedding # within {}. A new name is referred to the copy of the original name.

33.What is the use of super in Ruby Rails?


The function super is used to invoke the original method, searching of the method body starts in the super class of the object that was found to contain the original method. The following example depicts the same. def url=(address) super (address.blank? || address.starts_with?('http')) ? address : http://#{address} end

34.What is the use of load and require in ruby?


The load and require both are used for loading the available code into the current code. load always reloads the code every time. Autoload is always sounds good and it is suggested to use require. In the case where loading the code every time when changed or every time someone hits the URL, it is suggested to use load which is reasonable.

35.Explain the use of global variable $ in Ruby


The global variable is declared with $ prepended. It has full scope in the application. These variables can be used anywhere within an application. For Example: $departmentName = Operations Proper care is to be taken when using global variables, as they can also be changed from anywhere within the application, which leads to bug tracking later. This process can make the bug tracking more difficult.

36.Explain the difference between nil and false in ruby.


The differences of the methods nil and false are: - nil cannot be a value, where as a false can be a value - A method returns true or false in case of a predicate, other wise nil is returned. - false is a boolean data type, where as nil is not. - nil is an object for NilClass, where as false is an object of for FalseClass

37.Explain how to obtain a performance profile of my Java Program.


To improve the performance of a program, performance analysis is used. The usual purpose of this analysis is to determine which sections of a program to optimize which means to increase its overall speed, decrease its memory requirement or sometimes both. This analysis is called Profiling. The Java2 platform provides profiling capability using Heap Analysis Tool (HAT). The heap analysis tool analyzes profile reports of the heap. The heap is a block of memory the JVM uses when it is running. The heap analysis tool generates reports on objects that were used to run application. Not only we can get a listing of the most frequently called methods and the memory used in calling those methods, but we can also track down memory leaks. Memory leaks can have a significant impact on performance. To obtain performance profiles of My Java program run the application with Xrunhprof. For Example: java -Xrunhprof My Javaprogram The IDE like eclipse has The Eclipse Test & Performance Tools Platform (TPTP) which provides profiling tool for identifying and isolating performance problems such as performance bottlenecks, object leaks and system resource limits. The tool targets applications of all levels of complexity, from simple standalone Java applications to Eclipse plug-ins or complex enterprise applications running on multiple machines and on different platforms.

38.Explain the purpose of the executable files that have an extra _g at the end of their names, e.g. java_g.
java_g is a non-optimized version of java suitable for use with debuggers like jdb. When using java_g to run a program that loads a shared library, we must supply a debug version of the library. We can create a debug version of a library by simply appending "_g" to the file's name. For example, if the library was hello.dll, change the name to hello_g.dll. This file gives the debugging information

39.If Java is platform independent, why doesn't it run on all platforms?


Java runs mostly on all platforms. For running a Java program we need JVM on all the platforms. If JVM is not installed on any platform than we are not able to run Java programs. Java API has standard library and API that can run on any platform. But the API of different languages like C and C++ is different for different platforms. The API for Windows is totally different than the API for Linux, and the API for Mac OS X is totally different again. When you write a C or C++ program that uses the Windows API, then your source code will be largely useless on a Linux system or on a Mac - because the Windows API doesn't exist there. So we can run Java programs on any platform but before this we have to install JVM for interpreting the byte code. The byte code of Java or war or jar files can be taken to any platform and can be run directly on the platform having JVM.

40.Explain how to access native operating system calls from my Java program.
To access native operating system calls from my Java program JNI is used. Java native Interface (JNI) is a programming framework that allows Java code to interact with code written in another language, typically C or C++. JNI enables one to write native methods to handle situations when an application cannot be written entirely in the Java programming language. It is also used to modify an existing application which is written in another programming language so that it can be accessible to Java applications. Many of the standard library classes depend on JNI to provide functionality to the developer and the user. The Java Development Kit (JDK) provides tools and library routines that help the Java programmer interface with native code. The system calls are written in C and C++ so to access these call JNI is used.

41.How do we create and use sockets in Java?


A socket is a software endpoint that establishes communication between a server program and one or more client programs. The socket associates the server program with a specific hardware port on the machine where it runs so any client program anywhere in the network with a socket associated with that same port can communicate with the server program. In Java, TCP/IP socket connections are implemented with classes in java.net package. The programming is done on both server side and client side.TCP/IP server applications rely on the ServerSocket and Socket networking classes

42.Explain how to send data from my Java program to a CGI program.


There are two methods of sending data from Java program to a CGI Program: a.) The first method is that we can use CGI scripting on both client and server by using Java. The client-side part covers using GET and POST from applets to talk to CGI programs. The server-side part covers implementing CGI programs in Java that handle GET and POST (regardless of whether the client uses HTML forms or applets), and also includes a URL decoder and CGI form parser in Java. b.) The second method is by using Servlets and JSP.

Servlets are Java technology's answer to CGI programming. They are programs that run on a Web server and build Web pages. Java servlets are more efficient, easier to use, more powerful, more portable, and cheaper than traditional CGI and than many alternative CGI-like technologies. Java Server Pages (JSP) is a technology that lets you mix regular, static HTML with dynamically-generated HTML. Many Web pages that are built by CGI programs are mostly static, with the dynamic part limited to a few small locations.

43.Explain the difference between a URL instance and a URLConnection instance.


URLConnection is a class under java.net package. The abstract class URLConnection is the superclass of all classes that represent a communications link between the application and a URL. Instances of this class can be used both to read from and to write to the resource referenced by the URL. URL instance represents the location of the resources. URLConnection instance is used both to read from and to write to the resource referenced by the URL.

44.How do I read a line of input at a time in Java?


The standard input stream is represented by the InputStream object System.in. For reading a whole line at a time BufferedReader is chained to an InputStreamReader that in turn is chained to System.in. For example: This program read line from a file students and displays it on screen. import java.io.*; import java.util.*; public class stud { public static void main (String args[ ]) throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(newFileInputStream(students))); String s= ; while ((s= br.readLine())!=null) System.out.println(s); } catch (IOException e) { System.out.println(e); } }

45.Why is thread synchronization important for multithreaded programs?


Threads share the same memory space, i.e., they can share resources. However, there are critical situations where it is desirable that only one thread at a time has access to a shared resource. For this Java provides synchronization to control access to shared resources. For the consistency of data Synchronization is used. Without synchronization it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often leads to an error. For example: public class MyStack { int idx=0; char [ ] data= new char[6]; public void push (char c)

{ data [idx]=c; idx++; } public char pop () { Idx--; return data[idx]; } }

You might also like