Sharp AL 1631 Copier Logo

Related Topics:

Posted on Feb 17, 2008

Java-collection frame work, Arraylist datastruture

Student class as two instance variables sno and sname how create four objects for this student class and return this four objects to Arraylist

4 Answers

A

Anonymous

Class DD
{
public static void main()
{
student s=new Student[4];
for(int i=0;i<4;i++)
{
S[i].get();
s[i].put;
}
}
}

A

Anonymous

Class DD
{
public static void main()
{
student s=new Student[4];
for(int i=0;i<4;i++)
{
S[i].get();
s[i].put;
}
}
}

Ad
A

Anonymous

Class DD
{
public static void main()
{
student s=new Student[4];
for(int i=0;i<4;i++)
{
S[i].get();
s[i].put;
}
}
}

A

Anonymous

Class DD
{
public static void main()
{
student s=new Student[4];
for(int i=0;i<4;i++)
{
S[i].get();
s[i].put;
}
}
}

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

0helpful
1answer

What is difference between a class and an object with respect to Java?

This kind of question is a test of your knowledge of the terminology associated with object oriented programming. You should note that this question could just as well be asked in the context of a C++ programmer interview, or any programming position that requires object oriented programming for that matter.
The terms 'class' and 'object' are definitely related to one another, but each term holds its own distinct meaning. Let's start out by explaining what the term "class" means in the context of OOP. The term 'class' refers to the actual written piece of code which is used to define the behavior of any given class. So, a class is a static piece of code that consists of attributes which don't change during the execution of a program - like the method definitions within a class.
An object is an instance of a class The term 'object', however, refers to an actual instance of a class. Every object must belong to a class. Objects are created and eventually destroyed - so they only live in the program for a limited time. While objects are 'living' their properties may also be changed signficantly.
An example will help clarify what we've said. Suppose we have a class called 'Animal'. All Animals have bodies and brains - and these could be the attributes of our fictional Animal class. We can also add some methods that would be common to all Animals - like "movement", because all animals can move (maybe you can think of a better example for methods, but hopefully you get the point). So, the idea you really want to enforce in your own mind is that this very general 'template' of an Animal does not change - it's simply just some lines of code that define the Animal class.
An instance of the Animal class would be a specific animal - like a lion, a cat, or a zebra. These instances of the Animal class would be called objects. Whereas the Animal class is a general concept, the instances of that class - the lions, cats, etc - take that general concept and create a real instance of it. That is why programmers define constructors for their classes - so that when someone wants to create an object of the class, he/she can just pass in the actual properties that he/she wants the object to have - like what kind of animal it is, the name, the weight, etc. So, you can think of a constructor as something that brings the class to life - which is why it is called a constructor, because it constructs a specific instance of a class.
Objects have a lifespan but classes do not And, as our Animal example clearly shows, every object has a lifespan associated with it - a cat or zebra can not live forever. And, the properties of those objects can change as well while they 'live'; if we have a 'size' variable defined in the class that would of course change as the cat object grows bigger.
Object versus class summary So, we can say that whereas a class is a general concept (like an Animal), an object is a very specific embodiment of that class, with a limited lifespan (like a lion, cat, or a zebra). Another way of thinking about the difference between a class and an object is that a class provides a template for something more specific that the programmer has to define, which he/she will do when creating an object of that class.
Objects have a lifespan but classes do not And, as our Animal example clearly shows, every object has a lifespan associated with it - a cat or zebra can not live forever. And, the properties of those objects can change as well while they 'live'; if we have a 'size' variable defined in the class that would of course change as the cat object grows bigger.
Object versus class summary So, we can say that whereas a class is a general concept (like an Animal), an object is a very specific embodiment of that class, with a limited lifespan (like a lion, cat, or a zebra). Another way of thinking about the difference between a class and an object is that a class provides a template for something more specific that the programmer has to define, which he/she will do when creating an object of that class.
0helpful
1answer

What is singleton model

The Java Singleton pattern belongs to the family of design patterns that governs the instantiation process. A Singleton is an object that cannot be instantiated. This design pattern suggests that at any time there can only be one instance of a Singleton (object) created by the JVM. You implement the pattern by creating a class with a method that creates a new instance of the class if one does not exist. If an instance of the class exists, it simply returns a reference to that object
0helpful
1answer

Why main function is made static in java

Hi,
Its very easy dear. In java everything is object oriented. You will call a function through an object. Now we are calling the main method without any object as we do not create any object of the class that contains a main method. So call the main method we need to declare main as static methos so its not a part of an object but a class so that mian method can be called without having creating any object of the class.
Regards, polysandy
0helpful
1answer

Differentiate between nested and inner classes.Explain with examole

best shot that can attempt, hope it helps

Nested Classes vs. Inner Classes
A nested class is a class whose definition appears inside the definition of another class, as if it were a member of the other class. For example, if a program contains class A { class B { // fields, methods of class B... } // fields, methods of class A... } then class B is a nested class of class A. Code outside of the methods of class A can refer to class B by calling it A.B, using the same dot notation as for field and method references. Within the methods of class A class B can be used without qualifying the name. B could be hidden from code outside of class A by declaring it private, just as with fields and methods.
A nested class like B is known as an inner class. An inner class has access to the fields of an instance of its enclosing class. For this reason, an instance of B can only be created in association with an instance of A, using the expression /it instanceA.new A.B(...) outside of A's methods, where instanceA is an instance of A, and
new B(...) inside of A's methods. The new instance of B also knows about the enclosing instance of A, and can refer to it using the expression
A.this We can think of an instance of an inner class as having two this pointers, one for itself and one for its enclosing instance. An inner class may be nested within another inner class, so an inner class can even have multiple levels of this pointers. A nesting depth more than one level is quite uncommon, however, and should usually be avoided.
A nested class can be declared static, in which case it has reduced access to its enclosing class. For example, if B were declared static above, it could no longer access the instance variables of A, and there would be no associated instance A.this. Static nested classes are known as nested top-level classes, because they are exactly like classes declared outside any other class, except for the way they are named. Instances of a static nested class are created using regular new, as in new A.B(...)
0helpful
2answers

I'm getting an error "Instance Failure" in C#.net windows based application in the login form after entering the correct info in login form

instance failure appears wen u have created an object for a class that instantiated it during run time. that is check ur classes for which u created objects and see with which object u have accessed the action of login form.
0helpful
1answer

How to write jdbc connections

http://www.jdbc-tutorial.com/

window.google_render_ad();

welcome_title_image.gif Java JDBC Tutorial Java JDBC Tutorial
The JDBC ( Java Database Connectivity) API defines interfaces and classes for writing database applications in Java by making database connections. Using JDBC you can send SQL, PL/SQL statements to almost any relational database. JDBC is a Java API for executing SQL statements and supports basic SQL functionality. It provides RDBMS access by allowing you to embed SQL inside Java code. Because Java can run on a thin client, applets embedded in Web pages can contain downloadable JDBC code to enable remote database access. You will learn how to create a table, insert values into it, query the table, retrieve results, and update the table with the help of a JDBC Program example.


window.google_render_ad();
Although JDBC was designed specifically to provide a Java interface to relational databases, you may find that you need to write Java code to access non-relational databases as well.
JDBC Architecture jdbc.jpg Java application calls the JDBC library. JDBC loads a driver which talks to the database. We can change database engines without changing database code.
JDBC Basics - Java Database Connectivity Steps Before you can create a java jdbc connection to the database, you must first import the
java.sql package.
import java.sql.*; The star ( * ) indicates that all of the classes in the package java.sql are to be imported.
1. Loading a database driver,
In this step of the jdbc connection process, we load the driver class by calling Class.forName() with the Driver class name as an argument. Once loaded, the Driver class creates an instance of itself. A client can connect to Database Server through JDBC Driver. Since most of the Database servers support ODBC driver therefore JDBC-ODBC Bridge driver is commonly used.
The return type of the Class.forName (String ClassName) method is “Class”. Class is a class in
java.lang package.
try { Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”); //Or any other driver } catch(Exception x){ System.out.println( “Unable to load the driver class!” ); } 2. Creating a oracle jdbc Connection

The JDBC DriverManager class defines objects which can connect Java applications to a JDBC driver. DriverManager is considered the backbone of JDBC architecture. DriverManager class manages the JDBC drivers that are installed on the system. Its getConnection() method is used to establish a connection to a database. It uses a username, password, and a jdbc url to establish a connection to the database and returns a connection object. A jdbc Connection represents a session/connection with a specific database. Within the context of a Connection, SQL, PL/SQL statements are executed and results are returned. An application can have one or more connections with a single database, or it can have many connections with different databases. A Connection object provides metadata i.e. information about the database, tables, and fields. It also contains methods to deal with transactions.
JDBC URL Syntax:: jdbc: <subprotocol>: <subname> JDBC URL Example:: jdbc: <subprotocol>: <subname>•Each driver
1helpful
1answer

Unable to View Java Applet

"load: class JFI.class not found."
Based on the console output, it means that it cannot find the java applet class. In other words, the applet is missing on the server side. There is nothing that you can do about it, unless you know the person who created the applet. Good luck :)
0helpful
1answer

Java gui code

Okay. I'll try and explain what this code is doing for you.

First thing you need to understand is your "gui" is what is known as "Standard Out" and "Standard In", this is how Java outputs text to the console, and how it inputs text written by a user from the console. A function like "System.out.println([some string])" will print out that line to the console.

Second thing is the idea of classes. A class can be thought of like a code "blueprint". You write the blueprint, and then you create individual "objects" based on that class in your code. While each object is independant, and has it's own properties, functions, and its own spot in memory, it is based on the same code.

If I made a class called, say, "Shape", and I gave it two properties, "Size" and "Color", then I could in my program make lots of different "Shape" objects and they would each have their own independant sizes and colors. Yet, if I made a function in the class called "Draw" which magically drew it on the screen in the appropriate size and color that I had specified, I could call "Draw" for each object, and each shape would be drawn on teh screen. The same code is being executed for each shape, but with different values for the size and color, since each shape object is its own unique entity with its own size and color.

The whole point of classes is so that you don't rewrite code. If you needed to have 1000 shapes on the screen, it would be silly to write the drawing code out 1000 times, one for each shape. It's much easier to write a single blueprint that applies to all shapes.

That said, your code above has a number of "classes" at work.

The "Products" class is a class which stores information about a "Product". In your case, this info looks like it is the name of the product, it's price, how many are in stock etc.

The "Inventory" class is a class who's purpose it is to keep track of an array of products. There are a bunch of functions inside this class. I'll describe what they do below


The buildinventory() function appears to build up a list of products for use in the inventory. Notice how it calls the line:

product[0] = new Product(1, "socket set", 3, 19.99);
filling up the "product" array? Each call there created a new "Product" object which was based on the "Product" class. So each object has it's own name, inventory number, stock, price etc, but they all have the same set of functions to do things like, say, get the price of the product (the getPrice() function), or get the name of the product (the getName() function). It's the same function, as defined in the Product class, but when called on a different product object, it will return different results. This works well for an inventory program.

The "DisplayInventory" function loops through all of the products that the inventory class has created, and outputs information about each one to the screen. By the looks of it it is also keeping track of the total value of the inventory, in a variable called "totalPrice". Every time it loops through a product, it adds the product's price onto the total. The idea is once that while loop has finished, that variable will hold the final "total" of the inventory. After the loop has finished you can do a System.out.println() and use that variable to display the final total. This is probably part of what your project is asking you to do.

The "SortInventoryByName" function simply sorts the list of products that the Inventory class has created based on the name of the product. It does this using a build in Java class that you don't need to worry about.

You'll notice a function that is just called "Inventory()" near the top. This is called the "constructor". When you create a class, the class sometimes has to do a bit of initialization work before it is usable. This function is called as soon as the class is instantiated as an object somewhere in your code. So in this case, when you eventually create an inventory object, that function will be called and the inventory will be built (by calling buildInventory()), sorted (by calling sortInventoryByName()), and displayed (by calling displayInventory()).

------------

So it looks like you have this great Inventory class that does everything you need it to do. So now what? It still doesn't do anything! The reason is because it itself is just a class. It's a BLUEPRINT for an inventory. You need a Java program to USE the inventory class to actually do something useful.

You need to make a java program with a sub main() in it (just like every program you've ever made in this class). And inside there initialize a new inventory object, just like how the inventory object made product objects.
e.g.
Inventory myInventory = new Inventory();

Remember the Inventory() constructor! It will get called here, and the inventory class will go ahead and build an inventory, sort it, and display it on the screen.


So hopefully this will help you to understand your class a bit better. Again, real programmers don't just take classes and use them, they need to understand how they work. It's true that occasionally you can find something that does what you need it to do, and you don't need to "Reinvent" the wheel, but if you are unable to understand what it is doing, you can never modify it or tweak it, and if your problem isn't perfectly solved using the class, the class is useless to you. Programmers write their own modules and re-use them as they see fit, and occasionally they use someone else's code as a template. This is why you are learning how to modify an existing class.
Not finding what you are looking for?

610 views

Ask a Question

Usually answered in minutes!

Top Sharp Office Equipment & Supplies Experts

k24674

Level 3 Expert

8093 Answers

ZJ Limited
ZJ Limited

Level 3 Expert

17989 Answers

Norman Weimar
Norman Weimar

Level 3 Expert

7035 Answers

Are you a Sharp Office Equipment and Supply Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...