Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Java does not have global variables or functions

Posted on 2014-03-25
6
Medium Priority
?
280 Views
Last Modified: 2014-04-24
Hi,

I was reading as below
All code in Java program is encapsulated within classes therefore Java does not have global variables or functions.

I have not understood what it means by
Java does not have global variables or functions.

Please advice.
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 36

Expert Comment

by:mccarl
ID: 39954698
Basically, it just means that you can define a function/variable that is available to your entire application, without it being defined inside a class.

For example, you can't define say a function called "doSomething()" that is available to be called from anywhere in your application using that syntax above. Your only option is to define that function inside a class, eg...
public class ABC {
    public static void doSomething() {
        // do something here
    }
}

Open in new window

And then you call that function by first qualifying it with the class name, ie. ABC.doSomething();

Or in other words, you can't have a function/variable that is NOT associated with a class (or an object of that class)
0
 
LVL 7

Author Comment

by:gudii9
ID: 39995089
For example, you can't define say a function called "doSomething()" that is available to be called from anywhere in your application using that syntax above.

which syntax above?

please advise. I only see code below which is clear.
0
 
LVL 36

Expert Comment

by:mccarl
ID: 39996969
I was referring to the "doSomething()" bit. So to expand, I was basically saying that you can't have a function called "doSomething()" and be able to call that code using a line like....
doSomething();

Open in new window

...from anywhere in your code.
0
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 
LVL 7

Author Comment

by:gudii9
ID: 40005167
:

I was referring to the "doSomething()" bit. So to expand, I was basically saying that you can't have a function called "doSomething()" and be able to call that code using a line like....

doSomething();
                                           


within same class we can do that right. please advise with complete example
0
 
LVL 36

Accepted Solution

by:
mccarl earned 2000 total points
ID: 40005595
within same class we can do that right
Yes, that is the ONLY way you can do it. But that was the point that I was making, if it is within the class it is therefore NOT global.

please advise with complete example
It's impossible to give you an example, since we are talking about something that you CAN'T do.
0
 
LVL 7

Author Comment

by:gudii9
ID: 40006981
I do not know much about 'Java does not have global variables or functions' if they are c++ or c# terms 'global variables or functions' .

I was thinking ' global variables or functions' means 'Static variables nd static functions' as per my java knowledge. Please correct me if i am wrong.
0

Featured Post

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question