1. Hi Guest
    We are running a survey about laptop service in India, and we'd love your inputs. Please help us improve the quality of laptop servicing, and if you've had any bad experiences, now is the time to be heard.
    Take the survey

Java Queries Here..

Discussion in 'Programming' started by furious_gamer, Aug 4, 2008.

  1. meetdilip

    meetdilip Computer Addict

    Joined:
    Apr 22, 2009
    Messages:
    1,212
    Likes Received:
    84
    Trophy Points:
    48
    Node JS = Server side JS

    Angular JS = Google made JS framework
     
  2. TheSloth

    TheSloth The Slowest One

    Joined:
    May 24, 2012
    Messages:
    1,572
    Likes Received:
    88
    Trophy Points:
    48
    Location:
    Bed
    For (decent) basic knowledge, JavaBrains on youtube is good. I learned throught that. Someone might know of something better. But they have all tutorials you have mentioned in your post. Good place to start I would suggest.

    I am yet to start JS but as far as I know and heard of, JS is very different from typical OO languages like C++ and Java. Can't really say if hard or not as it depends on person understaking the course , but, people say its hard(well, fu'k'em, you can start if you want, just make sure you start from the first, means, JavaScript). And as dilip mentioned, node.js is for server side. angular is mostly used front end. Really good to have in current market if one wants to be frontend or fullstack developer
     
    quicky008 likes this.
  3. TheSloth

    TheSloth The Slowest One

    Joined:
    May 24, 2012
    Messages:
    1,572
    Likes Received:
    88
    Trophy Points:
    48
    Location:
    Bed
    Hmmm, I should also follow things people are following over stackoverflow, not to give the complete code at firsthand. For future, if anyone is going to ask the code, better post the tries made by you and then we will try to suggest things to improve that code :) . Also, do not hesitate.
     
  4. quicky008

    quicky008 Well-Known Member

    Joined:
    Nov 27, 2007
    Messages:
    1,606
    Likes Received:
    49
    Trophy Points:
    48
    Location:
    Kolkata
    Can anyone tell me what conditions should a class fulfill to be fully encapsulated?Does one need to declare all the class variables as well as methods as private in order to achieve that?Can a class in which the variables have been declared as private but the methods are public be considered encapsulated?
     
  5. Desmond David

    Desmond David Destroy Erase Improve

    Joined:
    Apr 9, 2005
    Messages:
    6,294
    Likes Received:
    162
    Trophy Points:
    63
    Location:
    Pune
    As long as all your class variables are not directly accessible from outside, your class can be considered encapsulated. As per the Javabeans standards, you must define public getter and setter methods to get or set the values of the variables. Also, you must define public methods to operate on your class variables. Your class variables should remain private at all times.
     
    ariftwister, TheSloth and quicky008 like this.
  6. quicky008

    quicky008 Well-Known Member

    Joined:
    Nov 27, 2007
    Messages:
    1,606
    Likes Received:
    49
    Trophy Points:
    48
    Location:
    Kolkata
    i recently installed Eclipse kepler on my system-after installing it i tried launching kepler with my pre-existing workspace that was formerly used with eclipse mars-kepler suggested that i should ├╝pgrade"my workspace to make the workspace files compatible with kepler-however finally when kepler started once the upgrade process finished none of the programs that were in my workspace were working-eclipse shows a red exclamation mark for every line of code in all programs and displays a "jni error"when i try to run them.Can anyone suggest what am i doing wrong?Are the older programs incompatible as they were created using eclipse mars?Is there any way i can fix this issue?
     
  7. TheSloth

    TheSloth The Slowest One

    Joined:
    May 24, 2012
    Messages:
    1,572
    Likes Received:
    88
    Trophy Points:
    48
    Location:
    Bed
    Did you fix the issue?? How did you fix it??
     
  8. quicky008

    quicky008 Well-Known Member

    Joined:
    Nov 27, 2007
    Messages:
    1,606
    Likes Received:
    49
    Trophy Points:
    48
    Location:
    Kolkata
    turns out the version of eclipse that i was using ie kepler didn't support java 8 or higher,i had java 8 installed on my system and so it kept throwing errors and simply refused to work-i finally resolved the issue by installing the latest version of eclipse,that is eclipse O2.
     
    TheSloth likes this.
  9. Desmond David

    Desmond David Destroy Erase Improve

    Joined:
    Apr 9, 2005
    Messages:
    6,294
    Likes Received:
    162
    Trophy Points:
    63
    Location:
    Pune
    You can also install JDK7 parallely with JDK8 and use Kepler with JDK7 if needed.
     
    TheSloth likes this.
  10. quicky008

    quicky008 Well-Known Member

    Joined:
    Nov 27, 2007
    Messages:
    1,606
    Likes Received:
    49
    Trophy Points:
    48
    Location:
    Kolkata
    ^thanks,thats indeed a really useful bit of info-i had no idea that one could use multiple versions of jdk on the same system.
     
  11. quicky008

    quicky008 Well-Known Member

    Joined:
    Nov 27, 2007
    Messages:
    1,606
    Likes Received:
    49
    Trophy Points:
    48
    Location:
    Kolkata
    can anyone help me print this pattern in java:
    (please refer to the image given below):

    p1
     
    Last edited: Jun 7, 2018
  12. Desmond David

    Desmond David Destroy Erase Improve

    Joined:
    Apr 9, 2005
    Messages:
    6,294
    Likes Received:
    162
    Trophy Points:
    63
    Location:
    Pune
    Is this a fixed pattern or does it depend on a configurable number of iterations?

    In either case, you could do something like this:

    Code:
    (pseudocode)
    loop i from 1 to maxIterations
        spaceCount = maxIterations - (i*2);  //Since there are two stars
        loop j from 1 to i
            str = str + "*"
        end loop
        loop j from 1 to spaceCount
            str = str + " "  //append space
        end loop
        loop j from 1 to i
            str = str + "*"  //Ending stars
        end loop
        print str
    end loop
    
    Note that this code does not account for proper conditions for terminating the loop. So I leave that to you to figure out how you want to implement that.

    I would personally prefer to use something like StringBuilder though, instead of appending into string.

    Edit: Also, instead of the middle loop for appending space, I would personally prefer to create a maximum length space string and append a substring of it.
     
    Last edited: Jun 8, 2018
    quicky008 likes this.
  13. quicky008

    quicky008 Well-Known Member

    Joined:
    Nov 27, 2007
    Messages:
    1,606
    Likes Received:
    49
    Trophy Points:
    48
    Location:
    Kolkata
    recently i was trying to run this program that was created in swing:

    import javax.swing.*;
    import java.awt.*;

    public class rectangle3 {



    public static void main(String[] args) {

    JFrame f1=new JFrame("myrect")
    {
    public void paint(Graphics g)
    {

    g.drawString("Hello", 90,80);
    }

    };
    f1.setSize(500,500);
    f1.setVisible(true);
    f1.setDefaultCloseOperation(f1.EXIT_ON_CLOSE);


    }

    }

    On being executed,the text "Hello" did show up,but quite inexplicably,instead of the frame being opaque,it contained an image of the window in the background(ie it looked like someone had taken a screenshot of the window where the program had been written and had set it as the background image of the frame)-this was really weird,i couldn't understand what went wrong here.

    Can anyone suggest what caused this strange behaviour while running this code?also is there any possible way to resolve this issue?
     
  14. Desmond David

    Desmond David Destroy Erase Improve

    Joined:
    Apr 9, 2005
    Messages:
    6,294
    Likes Received:
    162
    Trophy Points:
    63
    Location:
    Pune
    I will have to try running this code and debug it to see what's actually going on.

    But from what you've described it looks like you are drawing the text but haven't set any background color for the frame and that is probably causing this issue.

    Sent from my A0001 using Tapatalk
     
  15. Desmond David

    Desmond David Destroy Erase Improve

    Joined:
    Apr 9, 2005
    Messages:
    6,294
    Likes Received:
    162
    Trophy Points:
    63
    Location:
    Pune
    @quicky008 try this:

    Code:
    import java.awt.Color;
    import java.awt.Graphics;
    
    import javax.swing.JFrame;
    
    public class rectangle3 {
    
        public static void main(String[] args) {
    
            JFrame f1 = new JFrame("myrect") {           
                
                public void paint(Graphics g) {
                    g.setColor(Color.WHITE);
                    g.fillRect(0, 0, 500, 500);
                    g.setColor(Color.BLACK);
                    g.drawString("Hello", 90, 80);
                }
    
            };
            f1.setSize(500, 500);
            f1.setVisible(true);
            f1.setDefaultCloseOperation(f1.EXIT_ON_CLOSE);
    
        }
    
    }
     
    quicky008 likes this.
  16. quicky008

    quicky008 Well-Known Member

    Joined:
    Nov 27, 2007
    Messages:
    1,606
    Likes Received:
    49
    Trophy Points:
    48
    Location:
    Kolkata
    Thank you, i will try this out now.
     

Share This Page