Java programming Tips
By suryan
@suryan (45)
India
December 21, 2006 11:59am CST
1)Do you know in java Programming when constructor are given return type then it acts as a normal function.And if static keyword is given before constructor then while compiling it ask for return type.If we give return type before static keyword then it acts like normal functions.
2)In every program we use public static void main but instead of that if we use public static void mian .That is instead of main we misspell as mian Do you know what will happen.Most of them will think it will not compile and execute.But this is not true.It will compile and generate error when it try to execute it.Reason is while it executes JVM start searching for main and as main is not present it generates error.
3)Anyone of you know How to find the size of object.And people will think as there is no sizeof operator in java we can't find.But this is not true.We can find the size of object with the class name Runtime.we have get the size by the using the code Runtime r = Runtime.getRuntime(); before and after the creation of the new objects you can check the memeory and by subtraction you can get the memory like sizeof operator in C.
4)how to write a Java application without a main method
class MainMethodNot
{
static
{
System.out.println("Hello Java");
System.exit(0);
}
}
As there is no main method you will think how the program will compile and execute.But it will do.When it find static keyword it enter in the loop and print Hello Java and before JVM find main method it there is exit command and it terminates before searching main.
5)Do you konw in JVM there are 3 things.First is class Loader.Second is class Verifier.Third is Java Interpreter.class Loader loads the dot class file(.class) which contains bytecode and byte code means it doesnot have one's and zero format rather than bytecode is in form of assembly language. class verifier checks for errors and java Interpreter converts machine independent code to machine dependent code.And when we try to execute with keyword
java filename.the java invokes JVM and class Loader and the file is loaded in RAM.
6)If you think my Java Tips was useful and if you are intrested to learn more We can be a good friend and share more tips and information.I think this much information is good to for Today.I will give more such Tips afterwards.
3 people like this
22 responses
@amitavroy (4819)
• India
21 Dec 06
well i have a little bit of knowledge about java
and the technology is rocking
it saves a lot of loading time for your sites and also it put less pressure on the server becasue
it is client side technology.
i am thinking of learnig it.
but you know what i am a designer who does the html part also and i m very good at it
but i am not able to understand should i do java
cause i dnt have any programming background.
can any one advice me
@ivbsav (193)
• Indonesia
22 Dec 06
hello everybody, I'm very glad join this topic.
Actually I'm a programmer who develop a Java Programming for SMS. If you interested deeply. Please send me a PM.
I will give you the URL because the terms of this services not permitted me to promote my URL.
Good Job guys
@anup12 (4177)
• India
22 Dec 06
I would just add on to your first point although a constructor can have return type it is not retruning anything
Refer the code below:
class Example4
{
void Example4()
{
System.out.println("Constructor can have return type");
}
void display()
{
System.out.println("Empty");
}
public static void main(String args[])
{
Example4 e=new Example4();
e.display();
}
}
The System.out.rpitnln statements is not gettinmg executed in this program just check it
@calvin222 (1606)
• India
22 Dec 06
I have no idea about JAVA.
what is it used for? is it difficult to learn?
can i get a good job if i do?
@jessie_marcelo (146)
• Philippines
22 Dec 06
Nice tips from you. I really appreciate them. I haven't known about those tips until you said them . Thank you! Maybe, you are a Java expert already. Can you teach Java because I want to learn it more?
@subbusa (106)
• India
22 Dec 06
Java is an object-oriented programming language developed by Sun Microsystems in the early 1990s. Java applications are, in the official implementation, compiled to bytecode, which is compiled to native machine code at runtime.
in java v need the important tink named JAVA VIRTUEL MACHINE......java s a poratable language it can b used n any systems
@classmates2006 (32)
• India
22 Dec 06
ya this was a good discussion.am eager to know more ..i myself is a computer engineer but haven't started doing projects yet...so it will be kind of you if you share such tips
@essytssy (125)
• India
22 Dec 06
even though these are basic thing or concept that every programmer has 2 know...so i guess ur a good programmer...ll keep in touch..