Java Queries Here..

TheSloth

The Slowest One
did you find any reliable source for learning spring framework?Are free tutorials for it available online?Also can you suggest from where can one learn other frameworks like strutts,hibernate etc?

Also can anyone tell me what are node js and angular js?Do they have any similarity with OOPs languages like java?Is it particularly challenging to learn for beginners?

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
 

TheSloth

The Slowest One
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.
 

quicky008

Technomancer
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?
 

Desmond

Destroy Erase Improve
Staff member
Admin
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?
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.
 

quicky008

Technomancer
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?
 

TheSloth

The Slowest One
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?
Did you fix the issue?? How did you fix it??
 

quicky008

Technomancer
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.
 

quicky008

Technomancer
^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.
 

quicky008

Technomancer
can anyone help me print this pattern in java:
(please refer to the image given below):

p1
 
Last edited:

Desmond

Destroy Erase Improve
Staff member
Admin
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:

quicky008

Technomancer
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?
 

Desmond

Destroy Erase Improve
Staff member
Admin
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
 

Desmond

Destroy Erase Improve
Staff member
Admin
@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

Technomancer
can anyone help me solve this problem:

Q)Complete the code segment to call the default method in the interface First and Second.

Ans:-

Code:
interface First{

    // default method

    default void show(){
        System.out.println("Default method implementation of First interface.");
    }

}

 

interface Second{

    // Default method

    default void show(){
        System.out.println("Default method implementation of Second interface.");
    }

}

// Implementation class code

class Question44 implements First, Second{

    // Overriding default show method

    public void show(){

// Call show() of First interface.

// Call show() of Second interface.

}

    public static void main(String args[]){
        Question44 q = new Question44();
        q.show();
    }
}
 
Last edited by a moderator:

Desmond

Destroy Erase Improve
Staff member
Admin
Got this to run by using this implementation:
Code:
class Question44 implements First, Second {

   // Overriding default show method

   public void show() {

       // Call show() of First interface.
       First.super.show();
       // Call show() of Second interface.
       Second.super.show();
   }

   public static void main(String args[]) {
       Question44 q = new Question44();
       q.show();
   }
}
 

quicky008

Technomancer
^thanks a lot for the reply,but why has the super been used in this case?Can we call the default function of an interface by using the interface's name,followed by the super keyword?
 
Top Bottom