Question:
Dynamic/Static code. Difference?
2007-11-07 07:54:42 UTC
Hey, I'm working on some Java here at school and we've been looking at some different types of code which I dont quite understand.

I'd like to hear an explanation, as well as some real life examples on the differences between Dynamic and Static code. (If you're very familiar with this, dont be affraid to ramble, I want to know =P ).

Thanks in advanced,

Tom.
Four answers:
stephene
2007-11-07 09:09:47 UTC
The question doesn't make sense in regards to the Java programming language. Which means there are lots of ways to answer your question.



Let's say you have 2 programs...



(Program 1)

System.out.println("Hello World");



(Program 2)

double randomNumber = Math.random();

if(randomNumber < .5)

System.out.println("Almost Nothing");

else

System.out.println("Almost Something");



While Program 1 will always do the same thing and Program 2 will print out 1 of 2 messages, the "code" for each program is static. The outcome of the code is different, but the code stays the same. Some programming languages like Lisp, Javascript allow the programmer to pass around pieces of code logic as variables. Java doesn't allow this type of behavior. So if you look at it in terms of degrees of "dynamic" you could say that Java is MORE dynamic than HTML, Lisp is MORE dynamic than Java, but that describes the behavior of the code. The code itself does not change.



Another angle that your static/dynamic question could mean may have to do with how the programs are executed. A program written in C++ is compiled (compiling turns code into programs) into a program, and that program can be executed on a computer directly by the operating system (Windows, Mac, Linux, etc.). Java programs are compiled into byte code that requires an "interpreter" to be executed. That interpreter is called the Java Virtual Machine (JVM). Sometimes... interpreted languages can be referred to as dynamic, whereas the former type can be referred to as static. Because it's theoretically possible for an interpreted language to change while its running, whereas a statically compiled language can not.
Haley
2007-11-07 17:05:48 UTC
From a Java/C++ standpoint, you may be talking about where Dynamic programming comes into play with inheritance. Using inheritance and virtual functions, I can know that you are perhaps dealing with a shape, but not what kind of shape, circle, square, whatever, but maybe I have made functions to do some basic things for each shape, such as drawing it to the screen. I could write code that says yourshape.draw() without knowing in advance what kind of shape I am actually working with because the inheritance will allow the correct draw function to be called.
Ti_Cool_Tech
2007-11-07 16:08:46 UTC
Simple



static code is stuff that stays the same.... html is a good example of static code.....



If you create a table in html it stays the same even if a user login or plays with a couple of drop down menus...



perl is a good example of dynamic code because on the server side, it can do alot of different stuff....



Say a user is playing with the drop down menus again....

perl can totally rewrite the webpage to show the results...



a comment form is a good example because if you happen to get to the submit page without filling out the comment form, you will get a processing error.... perl doesn't know what to give you back.... or it might rewrite the page code to redirect you to a help page..... Of even re-write a portion of the same page to to show you the help page embedded



or say if he happens to be on a comment form and we used a javascript to validate the form fields.... java would give you a bunch of errors on the page to help you along....



In short, you can do a lost of stuff, but it all depends on user experience..... the pages might be slow becuase you are doing a query in the backgound.... the query fails becuase some of the data is missing.....



if we validate the form before we submit, the user is kept busy completing the form, and the query would be fasters on submit because we wouldn't have to validate the data in the background.... it saves a step....



Hope this example helps....
1Man1God
2007-11-07 16:01:22 UTC
Dynamic is automatically set for you. Static is manually set. In Networking, you have static Ip's which are set by you or an admin, then dynamic which is set by the DHCP server.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...