aspose file tools*
The moose likes Java in General and the fly likes Java Cracked. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Cracked." Watch "Java Cracked." New topic
Author

Java Cracked.

Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Hello,
This thread is for discussing about the abnormal java.

Java states, we can do things in more than one way !.
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Some one told that one class must contain main method to start executing that class...but that is not the case....
see here

class Starter{
...
pubilc void doit(){ .. . }
. .
}

public class Start_It{
static{
(new Starter()).doit();
}

will work without Main() Method...but only drawback is it is unable to get the environment variables.......


any one know other methods to start a class executing without using the Main() method in that class......

if so please post it...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
And how do you propose to run class Start_It? Maybe with a main method

In other contexts you don't need a main method, e.g. applets or servlets, but they have other standardized methods of invocation.


Ping & DNS - my free Android networking tools app
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

Originally posted by j rangavallika:

Java states, we can do things in more than one way !.


I believe that is the Perl motto, There's more than one way to do it (TMTOWTDI).


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

You can start a "program" like this with the normal Java launcher; it loads the class in order to look for main(), and loading it will cause this code to run. If this initializer ever returns, though, you'll see the error message about not being able to find main!

That said, I should mention that this old chestnut has been known forever; every book that purports to teach you "advanced Java" trots it out and dusts it off.


[Jess in Action][AskingGoodQuestions]
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Originally posted by Ernest Friedman-Hill:
You can start a "program" like this with the normal Java launcher; it loads the class in order to look for main(), and loading it will cause this code to run. If this initializer ever returns, though, you'll see the error message about not being able to find main!

That said, I should mention that this old chestnut has been known forever; every book that purports to teach you "advanced Java" trots it out and dusts it off.



I don't think so........ there must be some other way the java virtual machine is doing in that....and i think static will not return anything....
can you explain with an example...please......
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

here is the next quest......


interface a{
....
....
}

interface b extends a {
....
...
}

now can i connect any other two classes by using these two interfaces.....
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
WTF?


Tony Morris
Java Q&A (FAQ, Trivia)
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

Originally posted by j rangavallika:

I don't think so........ there must be some other way the java virtual machine is doing in that....and i think static will not return anything....
can you explain with an example...please......


This code:

is a static initalizer block and is executed when the class is loaded (see here for more explanation). As Ernest points out, one could issue the command:

and the JVM would load the class to look for the main() method. The static initalizer is run and it invokes Starter. There is nothing to return because the initalizer is not a method. This is not "advanced" Java. It is obfuscated Java.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by j rangavallika:
here is the next quest......


interface a{
....
....
}

interface b extends a {
....
...
}

now can i connect any other two classes by using these two interfaces.....


What do you mean by "connect any other two classes"?

This sounds an awfully like a homework assignement and doesn't even seem like "advanced" Java. If you explain what you want to do and show us what you have tried already, we can help from there.

Layne


Java API Documentation
The Java Tutorial
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Joe Ess:

is a static initalizer block and is executed when the class is loaded (see here for more explanation). As Ernest points out, one could issue the command:

and the JVM would load the class to look for the main() method. The static initalizer is run and it invokes Starter. There is nothing to return because the initalizer is not a method. This is not "advanced" Java. It is obfuscated Java.


Is there an echo in here?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Layne Lund:
doesn't even seem like "advanced" Java.


Agreed. Moving to intermediate...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java Cracked.