Skip to main content

Daily Java questions

1​. What do you know about Java?

Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.

2. What are the supported platforms by JavaProgramming Language?

Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX/Linux like HP-Unix, Sun Solaris, Redhat Linux, Ubuntu, CentOS, etc.

3. List any five features of Java?

Some features include Object Oriented

Platform Independent

Robust

Interpreted

Multi-threaded

4. Why is Java Architectural Neutral?

It’s compiler generates an architecture-neutral object file format, which makes the compiled code to be executable on many processors, with the presence of Java runtime system.

5. What is a singleton class? Give a practical example of its usage.

A singleton class in java can have only one instance and hence all its methods and variables belong to just one instance. Singleton class concept is useful for the situations when there is a need to limit the number of objects for a class.

The best example of singleton usage scenario is when there is a limit of having only one connection to a database due to some driver limitations or because of any licensing issues.

Comments

Popular posts from this blog

What is Servet ?

A servlet is a java class that extends an application hosted on a web server. Handles the HTTP request-response process (for our purposes) Often thought of as an applet that runs on a server. Provides a component base architecture for web development, using the Java Platform The foundation for Java Server Pages (JSP). Alternative to CGI scripting and platform specific server side applications.

Compact Strings -  Java 9 Feature

Motivation The current implementation of the String class stores characters in a char array, using two bytes (sixteen bits) for each character. Data gathered from many different applications indicates that strings are a major component of heap usage and, moreover, that most String objects contain only Latin-1 characters. Such characters require only one byte of storage, hence half of the space in the internal char arrays of such String objects is going unused Description We propose to change the internal representation of the String class from a UTF-16 char array to a byte array plus an encoding-flag field. The new String class will store characters encoded either as ISO-8859-1/Latin-1 (one byte per character), or as UTF-16 (two bytes per character), based upon the contents of the string. The encoding flag will indicate which encoding is used. String-related classes such as AbstractStringBuilder, StringBuilder, and StringBuffer will be updated to use the same representation, as wi...

What is Applet ?

***What is an Applet? An Applet is a program that can be referenced by an HTML source code of a web page. It is dynamically downloaded from a web server to a browser and it is executed in the environment provided by the browser. Applet Viewer can also be used to execute  the applet. ***FirstApplet.java import java.applet.Applet; import java.awt.Graphics; /*<applet code=“FirstApplet” width=200 height=200> </applet>*/ public class FirstApplet extends Applet { public void paint(Graphics g) { g.drawString(“Hello World”,20,100); } } *** In the above example, The first two line is importing the java.applet and java.awt.Graphics package. The third line is the comment entry which is used only for applet viewer to execute the applet using the HTML source code. The next line declares the FirstApplet class which extends Applet class. Note that each applet created by user must extend the Applet class. There is a paint() method defined...