Page 1 of 3 123 LastLast
Results 1 to 20 of 43
Like Tree6Likes

Thread: Basic but important

  1. #1
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Basic but important

    You may think this is some joke, but the fact is I really want to know this.

    When I say a superclass has some properties and subclass has superclass properties along with its own properties, how do I convey this to the JVM/compiler/CPU that this superclass should have these properties and subclass should have properties along with other properties. Is it some kind of training which is given to the JVM/compiler/CPU?

    In continuation to that, what if as a guy who created java wanted to use clazz instead of class(spelling change) would have that been possible?

    Sorry for the stupid question but I am not a computer science major.

  2. #2
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Re: Basic but important

    Dont mistake me. My question is there some kind of training?

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,143
    Rep Power
    15

    Default Re: Basic but important

    I don't really understand your question. What kind of "training" are you talking about? You might want to check out the JLS: Java SE Specifications

    And sure, if the designers of Java had wanted to call them clazzes instead of classes, they could have. They could have called them FluffyPinkElephants.

    (Btw, that post title is not very informative, so chances are people who might have been able to answer your question will just ignore it. Lesson for next time.)
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Basic but important

    For you first question,

    Java Code:
    class A {
       // properties of class A (including methods and fields)
    }
    
    class B extends A {
       // properties of B which includes properties of A which are visible (i.e public or protected).
    }
    For your third paragraph. The syntax and keywords and other features of any programming language are entirely up to the designer of the language. So class could have been clazz. Most keywords today are similar across most languages. This is because they are well chosen (in most cases). They also make languages easier to learn if you are already familiar with one.

    The designers of Java could have added other constructs like:

    Java Code:
    if (condition1) {
    
    }  unless (condition2) {
    }
    
    //or
    do {
    
    } until(condition);
    But they didn't (and they aren't really necessary).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Re: Basic but important

    For you first question,

    Java Code:
    1
    2
    3
    4
    5
    6
    7

    class A {
    // properties of class A (including methods and fields)
    }

    class B extends A {
    // properties of B which includes properties of A which are visible (i.e public or protected).
    }


    Sorry, but you misunderstood my question. How does the compiler/JVM/CPU/whatever understand what I am trying to do. Afterall, the compiler/JVM/CPU/whatever is more like a machine which has no intelligence. The question is a level deeper than what you have posted.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Basic but important

    How does the compiler/JVM/CPU/whatever understand what I am trying to do
    It doesn't. It does exactly what you tell it to do.
    gimbal2 likes this.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Basic but important

    Exactly as Norm said. It will do just what you tell it. If you are computing an average of an array of numbers, the JVM has no idea what you are trying to do (any more than a TV understands the images on a screen). It just executes the instructions (or byte codes) the compiler generated. And if you tell it incorrectly you will get incorrect answers. As the old saying goes, "Garbage in, Garbage out."

    Regards,
    Jim
    gimbal2 likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Basic but important

    It understands in exactly the same way as a car understands to go faster when you push the accelerator.
    In other words, it doesn't. It does what the designers/engineers decided it should do when you push the accelerator.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Re: Basic but important

    I had taken a subject called Artifical Intelligence and Robotics. In that we first train the robot and then passed the values and checked the accuracy with the output.

    So I am asking if something similiar is done in order to make the JVM understand what I am trying to do. Or the JVM has some built-in properties which in turn understands the command I am trying to execute.

    Although jim829 has answered partially in post #4, I cannot suppress my curioisity to ask the following question. Suppose instead of Code 1, as a Java creator, I wanted the code to be like the one in Code 2. Would it have been possible?

    Code 1:
    Java Code:
    Class B extends A{}
    Code 2:
    Java Code:
    Class B is_extending A{}

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Basic but important

    That's down to the compiler.
    Look up Scala.
    It's a completely different language to Java, but it compiles to class files that run on the JVM.
    Here's a class def:
    Java Code:
    class Person(val name: String, val age: Int) {
        override def toString = s"$name ($age)"
    }
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Basic but important

    I wanted the code to be like the one in Code 2. Would it have been possible?
    Yes.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Re: Basic but important

    Quote Originally Posted by Norm View Post
    Yes.
    When I use the import keyword, a class(or package) is imported and when I mention class A{}, a class is defined.

    So we are talking about two keywords, import and class. So how does the JVM understand when I am using import keyword that a class(or package) needs to be imported and when I use keyword class, a class has to be created?

    Suppose I was the creator of Java, I used class using 2 curly brace pair and method using 1 curly brace pair. Now I am using single curly brace pair for a class in my program. So how does the compiler detect that single curly brace pair has been used for class and an error needs to be thrown?

    Thanks
    Last edited by jmohandos304; 05-27-2014 at 10:36 AM.

  13. #13
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    7

    Default Re: Basic but important

    Hi,

    I am just wondering: You want to understand, how compiler work? How they scan their source, check the syntax and then make something useful out of it?

    That is a complex thing and to much for a forum in my eyes. Maybe you look for some tutorials on the net. I found http://www.stack.nl/~marcov/compiler.pdf but didn't check it on my own.
    There are also great books. I read a german book covering that topic in the past (and it was coming in two big parts!).

    But there are multiple steps in the process:
    - Parsing - So from the simple text you build units that the compile know. So you might have a comment or a for loop or a class.
    - Then the core compile is done. You want to have a result. In java it is some bytecode that a JVM can run. But that could be something else, too.
    - Then maybe other steps are required. For Java this could be the creation of a JAR file. Other environments might need a linker. Whatever ...

    With kind regards,

    Konrad

  14. #14
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Re: Basic but important

    My doubt is very generalized. How do I make a JVM/compiler/whatever understand what I am trying to do? After all it does not have intelligence of its own.

    Also, as per few members of this forum, the keywords were actually made by the creator of the language. So it rules out that JVM has some properties which make it to understand a set of keywords of its own. Also the members said there is no training.

    So I am back to the question. So how does the JVM/compiler understand my command and execute it?

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Basic but important

    1. It's not the JVM. The JVM only understands byte code, from class files.

    2. Learn about compilers.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  16. #16
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    7

    Default Re: Basic but important

    Yeah, it is very generalized. And as I said: If you really want to understand the full thing, then you should really learn about compiler theory. So stop talking about Java and concentrate on really simply things.

    So I gave you some first structure with
    - Parser
    - Compiler
    - "Linker"

    Just investigate further on that. And then concentrate on simple examples! And I really mean simple examples.

    Just imagine that you have some code that simply allows 4 things:
    a
    b
    c
    "Some text in quotes"

    And of course there are rules. Something always has to start with an a and end with a c. In between can be whatever you want but a c can never follow an a.
    So you could have:
    abc
    aab"something"abcbc
    But not:
    bac - Does not start with an a
    acc - c can only follow after a b
    abb - ac must be at the end.

    And if you ask yourself what all this means: That is completely out of scope. A parser is just responsible for the syntax. It does not know anything about the semantics.

    So what could a parser do? It could create a list of items. So maybe it has some classes like
    Item
    AItem extends Item
    BItem extends Item
    CItem extends Item
    QuotedItem extends item

    And now the parser could go through any file. You can decide if it first breaks up everything or if you just include some checks. It is easier to have multiple runs so we separate it.
    S what is the parser doing?
    It reads a character and checks it. It can be a,b,c or " - if it finds something else, an error is printed.
    If it is an a, it creates an AItem and puts it in a List. Same with b and c.
    With a ", it continues to read character after character till it finds another ". Then the QuoteItem is created (including the characters read). Of course: if no " is found, an error is raised.

    So heya - you parsed the file. Now let us check the rules.
    - Is the first item an AItem?
    - Is the last item a CItem?
    - Is the item in front of each CItem a BItem?
    If that is the case, your parser is done and the result can be given to the compiler.
    The compiler could do something. It can be straight forward, because each item could have a translation logic. But here we need another simple example.

    Imaginge we have an IfItem which holds an expression, an true block and an false block.
    So the translation could be
    <Translation of expression>
    Conditional Jump :True<IdOfIfItem>
    <Translation falseBlock>
    Jump :End<IdOffItem>
    :True<IdOfItem>
    <Translation trueBlock>
    .EndIdOfItem

    And heya - you translated something into assembler. The first c compilers did something like that! of course - you simply have to replace the (Conditional) Jump with the correct assembler command but all assemblers that I saw so far had such a command.
    And you got all the jump points ...

    Did that help a little bit to get a rough idea what could be going on?

    Konrad

  17. #17
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Re: Basic but important

    - Parser
    - Compiler
    - "Linker"


    Ok. Thanks for taking time for writing such a long post.

    The three components(parser, compiler, linker) are capable of doing their task on its own(I mean does it have properties of its own which helps it do its job) or it is trained to do it?

  18. #18
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Re: Basic but important

    I would like to give a simple analogy to make you all understand what I am asking.

    When young we would have learnt that a magnet has the magnetic property. That is a property of the magnet. We are not externally doing something to give it the magnetic property.

    Similarly a compiler does it have the property of compiling or is it trained externally?

    The two words to note are : "PROPERTY" or "TRAINED"

  19. #19
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    7

    Default Re: Basic but important

    Right now I do not understand what you mean.

    Compiler are normal applications. They do exactly what is written in their code and not more and not less.

    There is no artificial intelligence which is doing anything there and which must be trained first.

    And they are even straight forward. A lot of code but the logic behind is mostly straight forward.
    The complexity comes from 2 areas:
    a) Stuff is not done in multiple runs.
    b) Optimizations must be included. (But here the optimization itself can be hard and not the implementation of it)

    And there are even tools like "Compiler Compiler". So you do not have to write a lot of code on your own. You can define the compiler work in a special language and then a compiler generates the compiler you wanted to have.
    Some commonly used open source tools are bison and yacc. But if you didn't understand what compilers are doing, then this is going to far already.

    But maybe you just want to look up wikipedia and read about different terms there. Compiler is there and I am quite sure that Parser is also described. And Compiler-Compiler is also on wikipedia.

    With kind regards,

    Konrad

  20. #20
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Basic but important

    Quote Originally Posted by jmohandos304 View Post
    - Parser
    - Compiler
    - "Linker"


    Ok. Thanks for taking time for writing such a long post.

    The three components(parser, compiler, linker) are capable of doing their task on its own(I mean does it have properties of its own which helps it do its job) or it is trained to do it?
    And I will point you back to my earlier post about cars and the accelerator.
    Is your car "trained" to react to the accelerator pedal, or is it simply designed that way?

    Answer that question and you will answer your own.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Page 1 of 3 123 LastLast

Similar Threads

  1. please Need help very important !
    By Magnificenturk in forum New To Java
    Replies: 1
    Last Post: 05-06-2013, 02:03 AM
  2. Please help me in this task. very important for me .
    By kumar_ravi in forum New To Java
    Replies: 3
    Last Post: 07-31-2012, 11:31 PM
  3. What exactly is networking and why is it important?
    By ricardodav in forum Networking
    Replies: 2
    Last Post: 11-23-2010, 02:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •