473,324 Members | 2,268 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,324 software developers and data experts.

Global variables in Java

184 100+
Hi,
Why there are no global variables in Java?
please anyone brief it out..

-Thanks & Regards,
Hamsa
Apr 11 '08 #1
4 1949
sukatoa
539 512MB
Hi,
Why there are no global variables in Java?
please anyone brief it out..

-Thanks & Regards,
Hamsa
String s = new String("chupakabras");

if that initialization are inside a class but outside a method? is it possible?
How do you call the s?
Apr 11 '08 #2
gaya3
184 100+
String s = new String("chupakabras");

if that initialization are inside a class but outside a method? is it possible?
How do you call the s?

I think instance variable;correct me if I'm wrong..

-Thanks & Regards,
Hamsa
Apr 11 '08 #3
sukatoa
539 512MB
I think instance variable;correct me if I'm wrong..

-Thanks & Regards,
Hamsa
have lots of terms,

you may read this if you want.

sukatoa
Apr 11 '08 #4
JosAH
11,448 Expert 8TB
If you really, absolutely, positively, definitely, surely, urgently need global variables
you can have them in Java:

Expand|Select|Wrap|Line Numbers
  1. public class Globals {
  2.  
  3.    // all your 'globals' here:
  4.    static int foo;
  5.    static double bar;  
  6.    static String baz;
  7. }
  8.  
Because all of the variables are static and public you can access/modify them
in any other class and method:

Expand|Select|Wrap|Line Numbers
  1. class AnotherClass {
  2.    final static double pi= Global.bar;
  3.    final int buz= Global.foo;
  4.    String myBaz;
  5.    public AnotherClass(String baz) { Global.baz= myBaz= baz; }
  6. }
  7.  
I consider coding like this as Basic and Fortran coding *yeach*

kind regards.

Jos
Apr 11 '08 #5

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

Similar topics

12
by: David WOO | last post by:
Hi, I am a newbie on C++, I need to define some global variables which should be accessible to most classes. In the mean time, I don't won't the global variables be modified freely at most of...
18
by: robert | last post by:
Using global variables in Python often raises chaos. Other languages use a clear prefix for globals. * you forget to declare a global * or you declare a global too much or in conflict * you...
23
by: Anil Gupte | last post by:
I am trying to set up a function that connects to the database that I can then use gloablly. I set up a class called L3Global in which I have a function as follows: Public Function...
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.