Home >> Feeds Directory >> Computers >> Programming >> Java Programming

Java Programming

Java programming FAQ
FAQs about Java programming, how to call one object from another, exceptions, OS, domain name and static context queries.
  • How do Java front- and back-end skill sets differ?
    A: This is a somewhat arbitrary distinction to make about Java development, since applications often have front- and back-end components and it is important to understand how both aspects are integrated. In general terms, back-end development is concerned with database storage and retrieval, servlets, Web application frameworks and Enterprise Java Beans. This requires a good understanding of SQL and database applications, JDBC, network principles, servlet containers, the HTTP protocol and an appreciation of concurrent programming issues.

  • Is there a tool to type Java code and see what happens?
    A: Sounds like you're looking for a user interface where you can enter Java statements and execute them. The BlueJ interactive Java environment is designed for people who are new to Java programming and lets you execute arbitrary Java statements to see how they work.

  • How can Java restrict viruses?
    A: The Java Runtime Environment (JRE) is the plug-in software that runs Java applets in Web browsers. Normally Java applets are executed in a so-called ?sandbox? environment inside the Web browser that prevents direct access to the host computer's file system and blocks potentially hazardous operations.

  • Can CSS support Java applets?
    A: It is possible to control the position and spacing between Java applets and other HTML document elements using CSS, but the CSS associated with the Web page cannot affect the visual appearance of the applet embedded in it.

  • What is a good beginner's book about Java?
    A: Thinking In Java by Bruce Eckel is a good beginner's book on Java, which is available as a free download too.

  • What is the difference between the JVM, JRE and JDK?
    A: The JDK, also called the Java Software Development Kit (SDK), is the full suite of tools required to develop, package and publish Java applications. The Sun Java SDK includes the full Java class library, with a compiler, decompiler, profiler, JAR signer, key signing tool and many other tools.

  • What's the difference between JVM and JIT?
    A: The Java Virtual Machine (JVM) is a program that runs on a computer operating system and executes Java program code. The JVM takes the Java code and compiles it to a format that can be run directly on the computer's processor. The JVM controls the interface between the Java code and the computer like audio software enables us to play the same CD on a Windows, Mac or GNU Linux computer.

  • What is the difference betwen invoke and call?
    A: There is no practical difference in the meaning of "invoke" versus "call" in Java programming, both mean that one class executes a method or constructor on itself or another class. In general terms the word invoke means to call upon an agent for help or guidance, or appeal for confirmation or corroboration, or summon an entity. Java programs can also be thought of as a sequence or network of messages that are sent between classes to trigger behaviour and get a response. The metaphor is basically the same in both cases.

  • Does the order of the operands in == matter?
    A: With this sort of question it is often easiest to try it yourself and see. You will find that single boolean comparisons are equivalent whichever way round you have the values.

  • How do I add two numbers in Java?
    A: To add two numbers in Java, use the simple mathematical plus operator, which may be applied to any numeric variable type, as below:

  • How can I add two numbers using a method?
    A: For simple mathematical functions a method would usually declare the input variables as method arguments and a return type that matches the required numeric type for the result. In the simplest case an add(int, int) method would return an int value, as below:

  • How should I round a double up to an int?
    A: To round a double value up and convert it to an int value takes two operations. The static Math.ceil(double) method returns a double value that is equal to the "next highest" integer. You must then give an explicit down cast to an int, as below.

  • How can I calculate minimum, maximum and average using Java?
    A: Assuming you have data values in a Java storage structure, the key part of the process is to iterate through the values, check and store the minimum and maximum values, the running total and number of data points. Lets take the simple case of an iterator over a set of DataPoint objects that have an int getValue() method.

  • What are bitwise and bit shift operators?
    A: Java bitwise operators act on the binary representation of primitive numbers int and long. Bitwise shift operators perform low level mathematical actions as if they physically shift binary digits left and right. The bitwise logical operators compare numbers bit by bit and transform them according to boolean logic. The examples below show how the 32 bit binary values are transformed by each operator and highlight some significant exceptions in the the use of shift operators in mathematics.

  • Why does this for loop instantiation fail to compile?
    A: If you declare a variable in a for loop without braces the Sun compiler will fail with the message "not a statement", but the message is misleading. A more appropriate error message would be "o is already defined". In this case there is no contained scope for the variable o, so every pass through the loop would have the effect of declaring the variable again and again.

  • How do I call another class in the same folder?
    A: Assuming the Java classes are in the same package, one class should instantiate the other to call an instance method, or use a class name reference to call a static method, as below.

  • How do you put both files in the same package to call them?
    A: If two Java source files are located in the same directory and neither explicitly declare a package name, they are implicitly in the same default package and no explicit import statements are required between them. Both classes can refer to each other, instantiate and call methods on each other directly provided there are no visibility modifiers that would prevent this.

  • How do I access a variable declared in another class?
    A: The examples below uses three classes, VariableHost, VariableCaller and VariableSubclass, all in the same default package for simplicity. The VariableHost class has a static class variable and an instance variable and the cases show how they are accessed from the host class itself and the other classes.

  • What is a recursive method?
    A: A recursive method is one whose method body includes a call to itself, so that it is called repeatedly until an expected condition is met or it cannot continue the recursion any longer. These methods often take an object or numeric argument that is subject to progressive interrogation or mathematical processing at each pass. Recursive methods must be designed carefully to ensure that they do not result in a very deep or endless recursion, which is likely to cause an OutOfMemoryError.

  • What is a singleton?
    A: A singleton class is one in which instantiation is restricted to ensure that only one instance is created for the current Java Virtual Machine. Singletons usually have a private default constructor, to prevent direct instantiation, and a static method to obtain a "new" reference to the single instance. On its first call, the static instance method creates the object using a private constructor and stores a static reference to it for all subsequent calls.


Newsfeed display by CaRP
Home  ::  RSS Feeds Directory  ::  RSS Feed Reader  ::  Add RSS Feed  ::  Sitemap

 

Send email or call Arun (+91-98310-27107) for Joint Ventures