473,378 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

provide objectname as command line argument

11
I am new programmer of java. I believe someone can help me out with following problem
Expand|Select|Wrap|Line Numbers
  1. class Employee
  2. {
  3.     string name1;
  4.     Employee()
  5.     {
  6.         Name="Amitabh";
  7.     }
  8.     Employee(String s)
  9.     {
  10.         Name=s;
  11.     }
  12.     public static void main(String[] args)
  13.     {
  14.         ???
  15.     }
  16. }
if I am running the above application as:
java Employee Mayuri

Then is it possible to initialize Mayuri(i.e. args[0]) as an object of class Employee?
I mean to say Is it possible to provide objectname as command line argument?
Feb 4 '08 #1
6 1208
BigDaddyLH
1,216 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. Employee emp = new Employee(args[0]);
Feb 4 '08 #2
jpr
11
Expand|Select|Wrap|Line Numbers
  1. Employee emp = new Employee(args[0]);
If I a not wrong above code is creating emp as an object of class Employee but I want to create args[0] as an object of class Employee.
Is it possible?
Feb 4 '08 #3
BigDaddyLH
1,216 Expert 1GB
If I a not wrong above code is creating emp as an object of class Employee but I want to create args[0] as an object of class Employee.
Is it possible?
I'm not sure I understand. You want the name of the variable to be the value of the given string args[0]? So if args[0] is "billgates", you want to define a variable:

Expand|Select|Wrap|Line Numbers
  1. Employee billgates;
Feb 4 '08 #4
jpr
11
I'm not sure I understand. You want the name of the variable to be the value of the given string args[0]? So if args[0] is "billgates", you want to define a variable:

Expand|Select|Wrap|Line Numbers
  1. Employee billgates;
Right, I want to define value of args[0] i.e. billgates(in case of your example) as object of class Employee.

so plz tell me is it possible?
Feb 4 '08 #5
BigDaddyLH
1,216 Expert 1GB
Right, I want to define value of args[0] i.e. billgates(in case of your example) as object of class Employee.

so plz tell me is it possible?
The short answer is no.

An alternative approach would be to define a java.util.Map and use the string as a key.

I can't say more because I have no idea what you are trying to do or why you want to name variables after strings.
Feb 4 '08 #6
yea i agree with the guy above.. i dunno why you would wanna name your variables after strings.. it would make things very hard to keep track of.. ud be better of naming it urself or using an array if ur grabbing lots of employees... its a lot easier for u as a programmer to keep track of the variables that way.
Feb 5 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Manlio Perillo | last post by:
Regards. In the standard library there are two modules for command line parsing: optparse and getopt. In the Python Cookbook there is another simple method for parsing, using a docstring. ...
7
by: Bernd Danberg | last post by:
Hi, I have a real strange problem with the command line arguments given to the main-function and together with using std::string: #include <string> int _tmain(int argc, _TCHAR* argv) {...
2
by: SunRise | last post by:
Hi I am creating a C Program , to extract only-Printable-characters from a file ( any type of file) and display them. OS: Windows-XP Ple help me to fix the Errors & Warnings and explain...
3
by: Shailesh Humbad | last post by:
I want to set a command-line argument for a Windows service that I programmed in VB.Net. This ought to be available from the service installer classes, but I can not find any such property. What...
1
by: amirmira | last post by:
I would like to set command line arguments to a service at install time. I need to do this because I need to get information from different registry locations depending on my command line argument....
34
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: ...
6
by: evantri | last post by:
I am developing a program that prompt the input from the command line argument. For example, this is the lists of command line arguments that I want to include: -fish -cat -dog -animal All...
2
by: Milan | last post by:
Hi, Please guide me how to set command line argument and how to retrive command line argument. Senario: vb.net application should be able to execute from command prompt by passing login and...
6
by: =?Utf-8?B?Rm9ycmVzdCBIZWxsZXI=?= | last post by:
The only code that is helpful is this: fp = New IO.StreamReader(filename, New System.Text.UnicodeEncoding(True, False), False) If I pass a command line argument to my program that is not from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.