How do you add a class or an interface to a package in java?
Well, the process differs whether you are using either an IDE or the command line binaries.
If you are using an IDE, then it is most likely that your IDE comes with extensive functionality for both managing and creating packages. Look under the "Packages" menu, or, when you are using Eclipse, just right click on the package name in the Package Explorer window and a flood of possibilities will come right up.
If you are using the command line binaries, then there are 2 steps to putting your classes in a package. First, you have to put your class or interface in the appropriate folder structure. For example, if you are using the package com.foo.bar.beebop, then you have to put your class in a folder named beebop, which is in a folder named bar, which is in a folder named foo, which is in a folder named com, which is in your class directory. Then, you have to add a package statement, which is only allowed to be at the top of your class file. For example, if you're using the package com.foo.bar.beebop, then put the following statement at the top of your class:
package com.foo.bar.beebop;
Then skip a line, then come your import statements (if you have any), then stick in another line (if you have inport statements), then your class.
Enjoy!
Give 10 example of close loop control system?
1. lightswitch --> light
2. Toaster --> toast (For timer-based toasters, only -- see below)
3. Water faucet --> water flow amount
4. Water faucets (hot/cold) --> water temperature in the sink or shower.
5. Temperature setting for the stovetop --> heat to cook food
6. TV remote control
7. Clothes dryer (timer based)
8. Volume on a stereo / home entertainment system
9. shades / blinds on a window --> 'regulating' the amount of light coming in from the outside.
10.
Closed loop:
1. Thermostat --> furnace (constant temperature)
2. Toaster setting (light/dark) --> toast (IF the toaster has heat sensors)
3. Refrigerator cold/hot setting --> refrigerator inside temperature (constant)
4. Temperatue setting for oven (not stovetop) --> oven temperature constant
5. Clothes dryer with moisture sensor
6. Washing machine water level
What is mean by method invoking in java?
The virtual method invocation is a little tricky to explain. But I rather show you an example. Suppose you have a super class like this:
public class Super{
public int number = 1;
public String getColor(){
return "red";
}
}
and now we have a subclass of Super:
public class Sub extends Super{
public int number = 2;
public String getColor(){
return "blue";
}
}
All right, so what is the out put of the next program?
public static void main(String[] args){
Super supersub = new Sub(); //You can do this thanks polymorphism
System.out.println( supersub.getColor() + supersub.number );
}
The output could be "blue2" or maybe "red1". Nooo, the real input is "blue1" and this is due the virtual method invocation. Let me explain it better, you are using a variable of the 'Super' type, but you store there a 'Sub' object instead, the output must be either of the two that I predict before, but the java is capable of track in run time the real method implementation that you are using ("the one that return blue") but it can do the same with your object variable.
Can a java program run on the browser?
No it can't, this is the difference between Java and JavaScript (which don't have that much to do with one-another) Java is more like C in that it can on the web-server or on any computer really, but it is not like JavaScript which runs inside a sandbox inside the browser.
When object is created and destroyed in java?
in java object is created as soon a class comes into picture......and distroyed ehwn exit that class.............
(object) it is running instance .........
submitted by- shreyas joshi..
What are the unique advantages of object oriented programming paradigm?
a. OOP provides a clear modular structure for programs which makes it good for defining abstract datatypes where implementation details are hidden and the unit has a clearly defined interface.
b. OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
c. OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.
Why you are calling java programming language java?
One code to run them all!
All you have to do is write one program and it runs on all 3 of the supported OS.
Cell phones are a little different since they can't support everything PC can. They have their own version of java.
Normally if you have to rewrite bits of your program to get it working on both windows and Mac.
What is Objectives Oriented Evaluation Approach to program evaluation?
Objectives Oriented Evaluation Approach is the means by which the worth or merit of a program is assessed based on the extent to which the objectives or purposes of the program are being achieved.
Assume the question was for C#, not C.
":" is syntax to extend a type. If the type extended from is another class, they form a class hierarchy and the "inheritance" is established:
For example:
class Base {}
class Derived : Base {}
Derived extends Base, and thus inherits from Base.
What is the definition of a base-class constructor?
A base class constructor is simply a constructor that is declared within a base class. There is nothing particularly special about them since all constructors are only of relevence and applicable to the classes in which they are declared.
How do you empty a file using C programming?
That depends on the type of file and what you mean by "empty". Generally, fopen() called on an existing file, with the "w" option instead of the "a" option will truncate the file to zero length. To delete a file completely is a different process. Function truncate is your friend.
What is hyper text markup language and describe its role in implementation of java applets?
Short for HyperText Markup Language, the authoring language for creating documents on the world wide web.HTML defines the structure and layout of a Web document by using a variety of tags and attributes.
The correct structure for an HTML document starts with
(enter here what document is about) and ends with < All the information you'd like to include in your Web page fits in between the and tags.HTML is very important in describe of java applets and its implementation.
An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled browser to view a page that contains an applet, the applet's code is transferred to your system and executed by the browser's Java Virtual Machine (JVM).
What are the best ways to learn and understand Java and what books are good for this?
Best way to learn Java is start from basic.Get a clear picture about JVM and JRE.Even if you write a simple program,try to understand what happens behind your code.I suggest you to read more about java at http://allinalljava.blogspot.com. At first while writing your code attach java source behind ,due to that you can easily admire real scenario happen in it.
I suggest you try http://academicjava.com. It's a resource of many example programs with explanations and there's a very good tutorial.
"Head first JAVA" is the book I recommend but it's a question of what's best for you. Go to a good bookshop and browse what's available.
At first, i would like to tell you the BEST way to learn JAVA is just "Type Java programs n execute them". start with simple programs...
"Head first JAVA" - It is the one of the best book to learn Java.
If you want to understand Java's advantages elaborately , then u can refer this page too
http://www.artima.com/insidejvm/ed2/
Best way to learn java is think of something real-world that you understand well and can automate. Write something like an electronic recipe organizer. The best book? Do a google search for "Java, The Complete Reference, J2se" Good luck!
That is a good book. Also try "Java In A Nutshell" from O'Reiley books. It makes an excellent quick reference and is very straightforward.
Yes, these are great resources and adding one more resource to the list which i found helpful while starting with Java --> the tutorials from Sun. You can find them here http://java.sun.com/docs/books/tutorial/
Happy Learning : )
A sub class is paired up with its super class. These can also be called a child and parent class.
The subclass will inherit all of the variables and methods from its superclass. And one superclass can have multiple subclasses, but a subclass can only have one superclass.
Here's an example:
public class childName extends parentName {
...
}
This means that childName will inherit everything from its superclass, which is parentName.
The advantage of this inheritance is that you do not need to copy/paste lots of code for many similar subclasses, and if you want to change something you only need to make one change in the superclass.
Describe three advantages of Java programming language?
Java has many more than 3 characteristics, which can be labelled "advantages"; of course, most of the following are shared by several other languages.
What is the use of throws io exception in java?
an IOException is any unexpected problem the compiler encounters while attempting to run a program. Possible problems the compiler may encounter are attempting to read from a file that does not exist, write to a file which has an invalid name (a slash or a question mark in the title should do it), or attempting to read the next token in a file when there are no more tokens.
What is classNotFound Exception in java?
If you are getting this error message, it means you are trying to use a class that is not located in your JVM classpath. In order to resolve this error, you must find the .class or the .jar file that contains the class you need, and add it to your classpath.
Depending on the application, it might be as simple as changing your CLASSPATH environment variable. Here is a good article on the Java classpath:
http://en.wikipedia.org/wiki/Classpath_(Java)
Here is a good online utility to help you quickly find the right jar and download it. It will save you hours of searching through various blog posts on the internet trying to find out which jar contains which class file!
http://www.ClassNotFound.com/
Write a program which uses Command Line Arguments?
IN C++
#include <iostream> int main(int argc, char *argv[]) { using namespace std; cout << "There are " << argc << " arguments:" << endl; // Loop through each argument and print its number and value for (int nArg=0; nArg < argc; nArg++) cout << nArg << " " << argv[nArg] << endl; return 0; }
What is the need of package in java?
Packages are containers-for-classes used to keep the class namespace compartmentalized.
Using Package,
1. We can define classes inside a package that are notaccessible by the code outside that package.
2. We can define class members that are only accessible by code inside that package.
3. We can have a class stored in a package withoutconcern that it will collide with some other class (havin same name), stored else where.
Package is basically a collection of predefined or ready-made classes that can be used in your java program to make shorter as well as easier. Package- import java.lang.*; is always implicitly called when you write a java program.
What is standalone application?
It means that it is by itself - as opposed to being bundled with other applications for example.
Java program that prints prime numbers between 1 to n?
The easiest way is to use a prime sieve (google Sieve of Eratosthenes).
Here is pseudo-code for the algorithm.
- create a boolean array of size n
- for every true index 2 through n
- - keep the index as true, mark all multiples of the index as false.
So, for example, if n=10
start with 2, keep 2 true. Mark 4,6,8,10 as false.
next is 3, keep it true. mark 6,9 as false (6 was already false).
next is 4, it is false, skip it.
next is 5, keep it true. mark 10 as false (it was already false).
6 is false, skip it
7 is true, keep it true. the next multiple of 7 is greater than 10
8,9, 10 are all false.
you are done - the values marked true (1,2, 3,5,7) are your primes.
Which keyword is used to declare a class?
There is no keyword for it. You can use a variable of 1 class in another only id the other class is derived from the 1st class.
Although you can use the variable of an object of a class in another class using object.variable
Inheritence and its types in object oriented programmings?
There are only two types of inheritance in object oriented programming:
Single inheritance: where a class inherits directly from just one base class.
Multiple inheritance: where a class inherits directly from two or more base classes.
Multi-level inheritance is often thought of as being a separate type of inheritance, however inheritance relates to a derived class and those that it directly inherits from. If a base class is itself a derived class (an intermediate class), then its base class or classes are simply indirect base classes of the derivative. But in isolation, the intermediate class either uses single or multiple inheritance, even if its base class or classes are also intermediates.
Virtual inheritance is also thought of as being a separate type, however virtual inheritance doesn't change the relationship between classes within the hierarchy. the only difference virtual inheritance makes is that the virtual base class or classes are constructed by the most-derived class within the current hierarchy, rather than by their most direct descendants. In this way, only one instance of each virtual base exists in the hierarchy, rather than multiple instance as would normally exist. The actual inheritance is still single or multiple, however.
How and where is the Java programming language used?
The computer-programming language Java is used when a powerful object-oriented programming language that can execute on a variety of operating systems, with little or no alterations to the code, is needed. Java "applets" are ideal for distribution over the internet owing to the diversity of systems that support Java and the inherently small size of the applet download.