Page 1 of 11 1234 ... LastLast
Results 1 to 10 of 107

Thread: Java (Q & A)

  1. #1

    Default Java (Q & A)


    Mga pre! Naa na man jud SQL ug C/C++ nga question question nga thread.. Himo sad ta ug Java.. Sa intresado lang gud..Â*
    Sige ako una..


    What will be the output of the following code?

    public class CompareStrings {
    Â* Â* public static void main(String [] args) {
    Â* Â* Â* Â* Â* Â*String str1 = "string";
    Â* Â* Â* Â* Â* Â*String str2 = "string";
    Â* Â* Â* Â* Â* Â*if (str1 == str2) {
    Â* Â* Â* Â* Â* Â* Â* Â*System.out.println("equal");
    Â* Â* Â* Â* Â* Â*} else {
    Â* Â* Â* Â* Â* Â* Â* Â*System.out.println("not equal");
    Â* Â* Â* Â* Â* Â*}
    Â* Â* }
    }


  2. #2

    Default Re: Java (Q & A) (Mods pls move to Programming board..Thanks!)

    equal ang output...

  3. #3

    Default Re: Java (Q & A) (Mods pls move to Programming board..Thanks!)

    hoy zengatsu, kamao ka unsaon pag kustomize sa Metal Look and Feel? gusto nako na akong own choices of colors muy akong gamiton for the GUI.. naa kay nahibalan na software na mo cusomtize?

  4. #4

    Default Re: Java (Q & A) (Mods pls move to Programming board..Thanks!)

    One way to change the colors for the MetalLookAndFeel is to create your own look and feel that extends the MetalLookAndFeel, overriding its initSystemColorDefaults method. Ing ani ang example bay:

    //Mao ni ang file nga ni extend sa MetalLookAndFeel
    package javaapplication;

    import javax.swing.UIDefaults;
    import javax.swing.plaf.ColorUIResource;
    import javax.swing.plaf.metal.MetalLookAndFeel;

    public class CustomLF extends MetalLookAndFeel {

    protected void initSystemColorDefaults(UIDefaults table)
    {
    super.initSystemColorDefaults(table);
    table.put("control", new ColorUIResource(123, 123, 123));
    }

    }

    //Mao ni and sample UI nga file
    package javaapplication;

    public class WhateverUI extends javax.swing.JFrame {

    public WhateverUI() {
    initComponents();
    }

    private void initComponents() {
    jButton1 = new javax.swing.JButton();

    getContentPane().setLayout(new java.awt.GridBagLayout());

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
    jButton1.setText("jButton1");
    getContentPane().add(jButton1, new java.awt.GridBagConstraints());

    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize ();
    setBounds((screenSize.width-234)/2, (screenSize.height-185)/2, 234, 185);
    }

    private javax.swing.JButton jButton1;
    }

    //Then kani ang file nga naa main() method
    package javaapplication;

    import javax.swing.UIManager;

    public class Main {
    public static void main(String[] args) {
    try {
    UIManager.setLookAndFeel("javaapplication.CustomLF ");
    } catch (Exception e) {
    e.printStackTrace();
    }

    WhateverUI wui = new WhateverUI();
    wui.setVisible(true);
    }
    }

    I-research lang ang properties sa mga components nga imong i customize ang colors then i set lang sila sa initSystemColorDefaults method nga imong gi override.


    Another way would be i change nimo ang properties sa UI attributes before nimo i-add ang UI component. I think mas sayon ni cya nga way. An example would be ing ani

    Container c = frame.getContentPane();
    UIManager.put("Button.background", Color.BLUE);
    JButton blue = new JButton("BLUE");
    c.add(blue, BorderLayout.CENTER);

    naa pa jud other way pero kuti na kaayo..imo i extend ang per ComponentUI na then override dayon..then imo dayon i set sa UIManager ang kadto nga UI nga imong gihimo

    hope nakatabang..

  5. #5

    Default Re: Java (Q & A)

    murag lisod lisod pud da.. but ill give it a try. salamat kaayo bay...

  6. #6

    Default Re: Java (Q & A)

    Answer to Question 1.
    The output is 'equal'. The reason is that both string variables are assigned the same string, and both string objects were not created using the new String() method. Since the strings were not created using the new String() method, the strings were placed in the string pool, then the reference to those strings is assigned to the String variables. And, since the reference to the string pool for the same string is the same, the == comparison will return the value true. If the string objects were created using the new String() method, the reference assigned to the String variables would have been different and the == operator would have returned the value false.

    Sakto ka godCode! :mrgreen:

  7. #7

    Default Re: Java (Q & A)

    Question 2:

    What will happen if you compile/run the following code?

    1: public class Main
    2: {
    3: static String str1 = "String[] args";
    4: static String str2 = "int[] args";
    5:
    6: public static void main(String[] args)
    7: {
    8: System.out.println(str1);
    9: }
    10:
    11: public static void main(int[] args)
    12: {
    13: System.out.println(str2);
    14: }
    15: }

    A) Duplicate entry point main(), compilation error at line 6.
    B) Duplicate entry point main(), compilation error at line 11.
    C) Prints 'String[] args'.
    D) Prints 'int[] args'.

  8. #8

    Default Re: Java (Q & A)

    prints String[] args

  9. #9

    Default Re: Java (Q & A)

    Answer to Question 2.
    C) Prints 'String[] args'. Its really just overloading and not creating another entry point for the application.

    Sakto ka spikes! :mrgreen:

  10. #10

    Default Re: Java (Q & A)

    Question 3.

    Which of the following signatures are valid for the main() method entry point of an application?
    (Choose all that apply.)
    A. public static void main()
    B. public static void main(String arg[])
    C. public void main(String [] arg)
    D. public static void main(String[] args)
    E. public static int main(String [] arg)

  11.    Advertisement

Page 1 of 11 1234 ... LastLast

Similar Threads

 
  1. Advance Java
    By gloryhunter in forum Programming
    Replies: 25
    Last Post: 11-15-2007, 10:14 AM
  2. SE K500i 3D Java Games/Application.. (?)
    By mE_bytes in forum Gizmos & Gadgets (Old)
    Replies: 1
    Last Post: 07-14-2005, 11:14 PM
  3. Java Seminar
    By polie in forum Business, Finance & Economics Discussions
    Replies: 5
    Last Post: 07-09-2005, 01:38 AM
  4. Mobile Java Games
    By Nezumix22 in forum Gizmos & Gadgets (Old)
    Replies: 23
    Last Post: 05-06-2005, 05:33 PM
  5. how to install java apps/games in motorola c651
    By 8088 in forum Gizmos & Gadgets (Old)
    Replies: 4
    Last Post: 04-18-2005, 03:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top