Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Understanding Classes & Objects in Java

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Location
    India
    Posts
    20
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Understanding Classes & Objects in Java

    Hello Java enthusiasts,

    Today, we'll look at the core ideas of classes and objects in Java. We'll begin by looking at a code sample that shows the creation and use of classes and objects:

    // Defining a simple class in Java
    public class MyClass {
        // Member variables
        int myNumber;
        String myString;
     
        // Constructor
        public MyClass(int number, String text) {
            myNumber = number;
            myString = text;
        }
     
        // Method to display object state
        public void displayState() {
            System.out.println("Number: " + myNumber + ", String: " + myString);
        }
    }
     
    // Main class to demonstrate object creation and usage
    public class Main {
        public static void main(String[] args) {
            // Creating an object of MyClass
            MyClass myObject = new MyClass(10, "Hello");
     
            // Displaying object state
            myObject.displayState();
        }
    }

    Upon first inspection, this code appears basic. However, let's go deeper into the complexities of Classes and Objects in Java.

    Class Definition: The code creates a class called MyClass with two member variables (myNumber and myString) and a constructor that initializes these variables. While the class description appears to be adequate, there is opportunity for more investigation into the principles of encapsulation, inheritance, and polymorphism in Java classes.

    The constructor MyClass(int number, String text) sets the member variables myNumber and myString to their initial values. While the constructor essentially initializes the object state, reviewing constructor overloading, default constructors, and constructor chaining can help you grasp how constructors work in Java.

    Object Creation: The new keyword is used in the Main class to create an object named myObject of type MyClass. While the object formation process is presented, learning about object instantiation, object references, and object memory allocation in Java will help us better comprehend object-oriented programming ideas.

    The displayState() function is called on the myObject instance to show its current status. While this method invocation works as anticipated, learning about method overloading, overriding, and visibility modifiers in Java classes may help us better understand method invocation and usage.

    By studying and evaluating these components of the offered code snippet, we may obtain a better grasp of Java classes and objects, as well as their function in object-oriented programming.

    Could you elaborate on these four concepts and provide further explanations or examples to help us better grasp Classes and Objects in Java?

    Your contributions to this conversation will increase our understanding of Java programming fundamentals.

  2. #2
    Member Helium c2's Avatar
    Join Date
    Nov 2023
    Location
    Kekaha, Kaua'i
    Posts
    102
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Understanding Classes & Objects in Java

    I got a free website hosting service, http:www.webador.com/ . Free use of it. And Immediately published. Since they carry an enormous amounts of videos and pictures files, these websites are built on Java programs to store the files and better management of the files over the internet. Objects and class files flies through the internet and java programming makes it more efficient. I just built one and it works out fine. You can pay for the service, but simple ones unlimited pictures and videos. You can have your own email and domain for a price. They just assign me a free domain, so I just use that one. Full of pictures on my free website. With my URL. I'm assuming they use Docker containers to transport these pictures files. As they are more efficient in storing them and transporting them. Class files and objects. Using containers over the www web.

  3. #3
    Member Helium c2's Avatar
    Join Date
    Nov 2023
    Location
    Kekaha, Kaua'i
    Posts
    102
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Understanding Classes & Objects in Java

    package java21days;
     
    import javax.swing.*;
    import java.awt.*;
     
    public class ButtonsIcons extends JFrame {
        JButton load, save, subscribe, unsubscribe;
     
        public ButtonsIcons() {
            super("Icon Frame");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JPanel panel = new JPanel();
     
            //Icons
            ImageIcon loadIcon = new ImageIcon("load.gif");
            ImageIcon saveIcon = new ImageIcon("save.gif");
            ImageIcon subscribeIcon = new ImageIcon("subscribe.gif");
            ImageIcon unsubscribeIcon = new ImageIcon("unsubscribe.gif");
     
            //Buttons
            load = new JButton("Load", loadIcon);
            save = new JButton("Save", saveIcon);
            subscribe = new JButton("Subscribe", subscribeIcon);
            unsubscribe = new JButton("Unsubscribe", unsubscribeIcon);
     
            //Buttons To Panel
            panel.add(load);
            panel.add(save);
            panel.add(subscribe);
            panel.add(unsubscribe);
     
            //Panel To A Frame
            add(panel);
            pack();
            setVisible(true);
     
     
        } //end ButtonsIcon Constructor
     
        public static void main(String[] arguments) {
            ButtonsIcons ike = new ButtonsIcons();
     
        }
     
    } //end ButtonsIcon Class

    I saw this on stackoverflow on the internet. Can someone help me with the conceptual idea here. The person was trying to add a GIF file to a JButton. Options as Load, Save, Subscribe, and unsubscribe. Are they referring to developing a new system in place? There was no options at first on the web. This was taken from NetBeans program she was using. So are they making new task or functions to the web page? Using NetBeans. Not sure yet how all this set up works. But I'm interested in Java if what she's referring to is changing things around. Thanks for your input on the matter. Not sure how this whole setup is yet.

  4. #4
    Member Helium c2's Avatar
    Join Date
    Nov 2023
    Location
    Kekaha, Kaua'i
    Posts
    102
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Re: Understanding Classes & Objects in Java

    So assuming I want to put a GIF file smack right on this web page. It's a government web page. I put this URL in "https://www.kauai.gov/Government/Council/Councilmembers-2022-2024" which is the URL site for a picture. Java would then take over and place a JFrame with my GIF file and show it for everyone to see it. Is this the correct way? I'm going to try it out if it works. Using NetBeans. The program I already have it. Just need to learn a few more codes and class files to cover my "Okole" so that I don't get penalized for doing this. Just some programmer.

    The reason for the cover up, there is a few locals in Hawai'i who likes to go on computers also. And they'll point me out as coming from sports background in the 8th grade playing sports. Even though I've already shown a high school diploma, 2 year degree, now I have to show a certificate in Java, and a few 4 year college courses of which I had to bail out because by then it was too long in it already. And yet these locals will point me out and automatically give it to a judge via a cop or policemen. That's how they do it locally in Hawai'i. So I'll have to be the smartest programmer around and cover my "okole" and send my home lan ip address first to San Francisco. The main hub so nobody figures my address out from paper work. All this I'll fight in court. I plan to irritate the local government. Which is made up of former college football, baseball, high school, and track and field stars in the county government. That is it...

    This can be done. Java URL class files and from my computer to their server. JVM on my computer will be the / anchor tag for this setup. No one will ever know who's doing it. Definitely.

    --- Update ---

    As a matter of fact, anyone here on the forum can do that. This is the site you would be placing the JFrame and a gif file on. I don't know if you guys want to do it, but let's see if this works. Kaua'i County Government website. You're experts in the field of computers. No one will figure us out. Here is the link to that gif file.

    https://free-4630391.webadorsite.com/

    The Gif is the football player on the home page scoring a touchdown. If you want to help me out, I'll appreciate you. You do it. And I'll check the site out on my Lan home pc when or if you've place it up. Easy program to use and gif to download from the site. Thank you!

    And let's keep it quiet here if someone ever does decide to try this out. Okay?
    Last edited by Helium c2; April 6th, 2024 at 06:40 PM. Reason: add information

  5. #5
    Junior Member
    Join Date
    Jan 2024
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Understanding Classes & Objects in Java

    Thanks for sharing the Java code snippet! Let's break it down into simpler terms:

    Encapsulation, Inheritance, and Polymorphism: These are big words, but they're just about how objects work together in Java. Encapsulation is like keeping things organized in a box, Inheritance is like passing down traits from parents, and Polymorphism is like one thing being able to take on different forms.

    Constructors: Think of constructors as blueprints for creating objects. They set up the initial state of an object. We can have different blueprints for creating objects based on what we need them to do.

    Object Creation and References: Creating objects is like making cookies from a recipe. You use the "new" keyword to make a new cookie (or object) and give it a name (like myObject). References are like labels you put on the cookies so you can find them later.

    Methods and Visibility Modifiers: Methods are like the actions a cookie can perform, like baking or frosting. Visibility modifiers (like public or private) are like rules for who can see and use those actions.

    If you need extra help understanding these concepts or with your Java assignments, I recommend checking out https://www.programminghomeworkhelp.com/. They offer great resources and assistance for students learning Java.

Similar Threads

  1. Java Objects/Classes - Help please
    By mark87coys in forum Object Oriented Programming
    Replies: 2
    Last Post: March 4th, 2024, 03:49 AM
  2. [SOLVED] Basic java- objects & classes
    By TSSF44 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 5th, 2014, 09:14 PM
  3. CS 170 Java Objects And Classes Help
    By Tdc740 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 22nd, 2013, 12:18 PM
  4. Understanding Classes and Objects
    By AustinStanley in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 9th, 2012, 11:35 AM