aspose file tools*
The moose likes Beginning Java and the fly likes Core Java Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Core Java Question" Watch "Core Java Question" New topic
Author

Core Java Question

Sailendra Jena
Greenhorn

Joined: Aug 30, 2010
Posts: 9

Hi,

Can anybody help me on this question.

1. In which scenarios we will use static method in Java Program & in which scenarios we will not use static method in Java Program?

2. How to compile Java Program without using javac command?

Thanks & Regards
Sailendra Jena


sailendra.n.jena@hotmail.com
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
Hi Sailendra Jena,

When there is a requirement to share a method or a variable between multiple objects of a class
instead of creating separate copies for each object, we use static keyword to make a method or variable shared for all objects.



Regards,
James
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14432
    
  23

About your second question:

IDEs such as Eclipse have a built-in Java compiler. You don't need to invoke javac yourself when you use Eclipse.

Also, when you're working on a larger project, you will typically use a build tool such as Ant or Maven to manage building, automatic tests, and dependencies for your project - it would be far too cumbersome to compile lots of class files manually by using the javac command directly.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Jesper, I have a query. We have these IDE's and build tools right. So , how exactly do the class / package inter-dependencies get resolved? How does the inbuilt compiler inside the IDE come to know in which order to compile the files?


~ Mansukh
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
I think you can download the source code for Eclipse; I think it is open source. Then you can read it for yourself.
Jinu Vijay
Greenhorn

Joined: Sep 19, 2011
Posts: 20

You'd typically use static methods when you want to access / change the value of a parameter across objects.

BE CAREFUL to not use it if not required. Else, you'd have object updating this parameter and the behavior might be absurd!!!

Besides, static methods are typically used in utility classes (where there is only static some data check / manipulation ). No class objects need to be created here to access these methods. e.g. Math class.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14432
    
  23

Mansukhdeep Thind wrote:Jesper, I have a query. We have these IDE's and build tools right. So , how exactly do the class / package inter-dependencies get resolved? How does the inbuilt compiler inside the IDE come to know in which order to compile the files?

The compiler first parses the source code and notices names of classes etc. that are being used, and so it can make a graph of dependencies, which it uses to determine the order in which to compile the source files.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

OK. So before we had these IDEs and tools to help us, how did developers accomplish this task? It would have been very time consuming and tedious work. Correct?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
IDEs have been around for a long time. If you are not using an IDE for a large program, you would write a makefile.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Ok.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jesper de Jong wrote:The compiler first parses the source code and notices names of classes etc. that are being used, and so it can make a graph of dependencies, which it uses to determine the order in which to compile the source files.


However, Java does allow circular dependences between classes. I don't know what the exact mechanism is, but the following is perfectly legal, and it works whether we do javac Y.java Z.java or javac Z.java Y.java.

Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

However, Java does allow circular dependences between classes.

You mean the order in which we name the sources does not matter. Essentially, what you are saying is that, somehow, there is a mechanism that works out which source file is the bottleneck and compiles it first, regardless of the order in which we give the file names. Correct?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Mansukhdeep Thind wrote:
However, Java does allow circular dependences between classes.

You mean the order in which we name the sources does not matter. Essentially, what you are saying is that, somehow, there is a mechanism that works out which source file is the bottleneck and compiles it first, regardless of the order in which we give the file names. Correct?


I think it's more like "compilation order doesn't matter." In my example, both Y and Z depend on each other. Neither order has any advantage over the other in that they both end up with us compiling a file where a class it depends on has not yet been compiled.

I don't know the details of the rules or the implementation, but I will add that I'm pretty sure I have seen "circular dependency" errors on occasion. I think they were within a single class and had to do with member variables.

When all is said and done, though, it's not something we usually need to worry about. The IDE or the compiler or the build tool (ant, maven) will figure it out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Core Java Question