java

Ovron

One of Freddy's beloved
Joined
Nov 4, 2004
Messages
471
Not really. Which bits do you specifically disagree with?

Pretty much what I quoted. The JVM will *never* be *faster* than what can be achieved in a strictly machine code compiled program. Just like the java compiler and JVM makes optimizations as it sees fit, so do the good C compilers.

For "normal" applications it is besides the point, though. Java is being blamed on too much due to poor coders, but it can never be faster than (since we're talking about C) C, compiled by a good compiler.

C++ has more overhead than C, while it does provide a larger standard library. It is a trade-off. It is very unlikely that an operating system that would want to compete with the linux kernel for instance, to be written in anything but C/asm even this day. C is as close to asm you get, with no magic in the background. OO etc are virtual constructs / paradigms that require magic to happen in the background.

Note that I am not saying Java is bad, it just cannot be compared to C (and other to-machine-code compiled languages). What should be discussed over language, is the compiler though. Majority of my work is compiled using the GCC, and nvidia's SDK for CUDA. I work with HPC, specifically computational chemistry, both on SMP and distributed CPU and GPGPU systems. C and Fortran are kings in this area - and it is that for a reason.

p.s. as a side note, try hiring good C programmers and then compare to your Java code base ;).
 

Chilly

Balls of steel
Joined
Dec 22, 2003
Messages
9,047
Oooo 70k/sec?

Try this one for size.

Data feed streaming updates at a constant 120 Mbps rising to in excess of 320 Mbps at US markets open. Overall we have seen data rates in over 7.1 million messages per second through our ticker plant.

Our processing for all of this real time data? Java. :)

Exactly. Good man :)
 

Chilly

Balls of steel
Joined
Dec 22, 2003
Messages
9,047
Pretty much what I quoted. The JVM will *never* be *faster* than what can be achieved in a strictly machine code compiled program. Just like the java compiler and JVM makes optimizations as it sees fit, so do the good C compilers.

For "normal" applications it is besides the point, though. Java is being blamed on too much due to poor coders, but it can never be faster than (since we're talking about C) C, compiled by a good compiler.

C++ has more overhead than C, while it does provide a larger standard library. It is a trade-off. It is very unlikely that an operating system that would want to compete with the linux kernel for instance, to be written in anything but C/asm even this day. C is as close to asm you get, with no magic in the background. OO etc are virtual constructs / paradigms that require magic to happen in the background.

Note that I am not saying Java is bad, it just cannot be compared to C (and other to-machine-code compiled languages). What should be discussed over language, is the compiler though. Majority of my work is compiled using the GCC, and nvidia's SDK for CUDA. I work with HPC, specifically computational chemistry, both on SMP and distributed CPU and GPGPU systems. C and Fortran are kings in this area - and it is that for a reason.

p.s. as a side note, try hiring good C programmers and then compare to your Java code base ;).


The problem is that the best optimistions in java are actually impossible in C. Even the best C optimising compiler (with all the beards and sandals you throw at it) can't predict actual patterns of data. The JVM will take stats in real time and then recompile the classes on the fly to better match the load profile (think probabilistic forking based on external inputs, not deterministic behaviour).

Java is a lot stricter in what you can do that C which allows lots of other types of optimisations that you cant get away with in C because it's not very type safe.

Have a look at this:

Java vs. C benchmark « Stefan Krause.blog()

ICC compiled C is generally quickest for a well defined scientific problem. That's fine.

What java is exceptionally good at is managing dirty great slabs of threads efficiently with a non deterministic input driving behaviour, again referring to on the fly recompilation.

For "normal" applications it is besides the point, though. Java is being blamed on too much due to poor coders, but it can never be faster than (since we're talking about C) C, compiled by a good compiler.

Is simply untrue. Java is compiled, albeit via a JIT. It's that JIT which allows it to pull some insane performance out of the bag in certain cases and it's also that JIT that means java is slow as a dog for the first seconds of the JVMs life. Java bytecode is compiled to platform specific machine code on the fly as the jvm executes. That compiled dobject code is then cached for later and revisitied (often many times a second if the JVM thinks it's worth it).

I'd go further and say that C can *never* be as fast as Java (ignoring startup) purely because a Java optimising JIT has more information than a static C optimising compiler. Therefore, in the perfect end case, a JIT can do better, since it has more to work with.

Java USED to be slow. It used to be interpreted and not JIT'd. This is not the case any more.

I'll back down on my "dont use C" and "use C++ for OSs", though, as you make good points there.
 

Deebs

Chief Arsewipe
Staff member
Moderator
FH Subscriber
Joined
Dec 11, 1997
Messages
9,077,018
Deebs: hire better coders. I'm sorry, but the JVM today is a thing of beauty. If it's guzzling memory and CPU then your developers are shit.

/edit - to clarify:
There are plenty of shit frameworks for doing "enterprisey things". And if your architecture team (COUGH) lets you use them, then that's your own stupid fucking fault. There are plenty of equivalently crap frameworks in C++ (or indeed any language).

Real world experience HERE tells me it's shit hot if we want it to be. We serve all our price requests and bet statement requests (up to 70k/sec) purely from java applications that exist in a few gigs of memory across a handful of servers.

Well I guess the likes of IBM need you on their development team to show them how to code :p Also add in Checkpoint and HP into the mix as well.

All I am saying that if I had two applications, both doing the same job, one written in Java and one written in C, guess which one always wins hands down on performance on the same piece of tin, it is not Java.
 

Chilly

Balls of steel
Joined
Dec 22, 2003
Messages
9,047
I misread your post, you are referring to commercial off the shelf stuff, right?

I dont care about that. I'm talking scientifically here. At work, we roll our own stuff because what's available often is too slow or doesnt do what we need.

I'm not saying I'm awesome, I'm saying that perhaps IBM and HP are not targetting performance rather than time to market and functional quality. And lets not even talk about the sweatshops in India where this software is written by this years graduates.
 

Deebs

Chief Arsewipe
Staff member
Moderator
FH Subscriber
Joined
Dec 11, 1997
Messages
9,077,018
I misread your post, you are referring to commercial off the shelf stuff, right?

I dont care about that. I'm talking scientifically here. At work, we roll our own stuff because what's available often is too slow or doesnt do what we need.

I'm not saying I'm awesome, I'm saying that perhaps IBM and HP are not targetting performance rather than time to market and functional quality. And lets not even talk about the sweatshops in India where this software is written by this years graduates.

Yes, off the shelf products written by the "big boys". I have no doubt in my mind that some geek hidden away for a year can produce some awesome java code but the point I am trying to make is that most IT folk will see Java via some commercial product and as you quite rightly point out, the "big boys" are not interested in squeezing the best out of the tin etc.

That leads to one thing, many people will have a tainted view of Java performance.....

Prime example, I use 3PAR SANs and at the beginning the management application was written in C. It used hardly any memory and was fast, they moved to a Java version, it consumes tons of memory and leaks like fuck, oh and it is slow..... Get my point?
 

Ovron

One of Freddy's beloved
Joined
Nov 4, 2004
Messages
471
Nothing can be faster than executing an opcode on the CPU. asm is a 1:1 map to these opcodes. A C compiler builds this as it sees fit taking in account padding and alignment, if instructed to. The data structures that you will be using are defined at compile-time, and won't be changing. They are padded and aligned on compile-time to allow for fastest possible memory access on the platform it is being compiled on. If you don't like something that the compiler produces for a certain chain, you can override it with inline asm.

With the alignment and padding applied, the memory can be seen as linear in regards to performance.

I'd love a source on your statement that the JVM somehow recompiles classes to better fit the load profile. I don't see how this could have any impact what so ever on anything. Classes in compilers and when executing, are nothing like one would think when writing them. The CPU does not know about them. As mentioned before, they are artificial/virtual constructs. It applied to C++, and it applies to Java.

Comparing two different implementations in two or more languages, not taking in account for compiler and platform specific conditions leaves much to desire in a benchmark like the linked one. The author acknowledges this.

Nothing will be faster than properly written asm, and C is as close as you get. In this comparison, Java will never be faster - it can be as fast, minus overhead that it is doing for housekeeping.
 

Ovron

One of Freddy's beloved
Joined
Nov 4, 2004
Messages
471
Have a read of this: The Java HotSpot Performance Engine Architecture

Your argument about ASM is not relevant. Java is ultimately compiled to the same machine code C programs are, there is no intermediate layer once the JIT has done its business (anything from a few second to a few minutes).

Have you even read what you linked? If you actually had read what you linked, you'd know how funny your last statement is. Given that you actually understand what you read.

Also, my argument about asm is very much relevant.
 

Chilly

Balls of steel
Joined
Dec 22, 2003
Messages
9,047
I've read it several times.

Can you actually explain what you mean rather than just getting all snobbish about it?

You seem to think java is interpreted. It isnt, once the JIT has done it's work.

You seem to think a C optimiser is better than the JIT. I say the JIT can and does do things a C optimiser simply cannot.

Which of those two statements do you disagree with and why?
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
Prime example, I use 3PAR SANs and at the beginning the management application was written in C. It used hardly any memory and was fast, they moved to a Java version, it consumes tons of memory and leaks like fuck, oh and it is slow..... Get my point?

dude, we have loads of "off the shelf, enterprizey doodads" in java and they're all shit. tbh I agree with Chilly here. Good programmers = all the difference. Not to be rude to the nice men at IBM / whatever, but...actually yeah, I am rude to the nice men at IBM, because I am forced to use some of their products and they are shit, because their code is shit, and frankly they should be ashamed that they put such tripe on the market.

the only reason we use those products at all is because the men who beat the drums here at BigCompany want to use the "must work out of the box" idea, because that means vendor junkets, getting phat cuts and 1000$ blowjobs. Most of my time is spent on making the products that I am forced to use actually work with our systems, even though they were sold to us as "works out of the box". why'd you think I have gray hair haha :-/
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,473
why'd you think I have gray hair haha :-/
Your vastly superior collection of "years alive" would have been my starting point ;)
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
36! Deebs is like...17 years older than me :eek:
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
meh well I am kind of done with it, so I may as well post and undergo your ridicule :)

I suppose the underlying idea of this exercise was to learn about different classes, objects, using an arraylist, and some other fun things. layout is attached in the image.

Please note there is a lot of Dutch in there. Anyway here it is:

Database:
Code:
import java.util.ArrayList;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 
 * In de database worden de personen, eg docenten en studenten opgeslagen. Er zijn methoden om een persoon toe te voegen of te verwijderen. 
 * Er zijn methoden om een complete namenlijst af te drukken, een persoon op naam te zoeken en een lijst te maken van alle SLB-studenten van een docent.
 * @author () 
 * 
 */

public class Database
{
    // initeer de arraylist 
    private ArrayList<Persoon> studocent;
    
    /**
     * Maak een lege database.
     */
    
    public Database()
    {
        // creeer de arraylist
        studocent = new ArrayList<Persoon>();
    }

    /**
     * Voeg een docent of student toe aan de database
     */
    
    public void addPersoon(Persoon p_soon)
    {
        // add arraylist methode
        studocent.add(p_soon);
    }
       
    /**
     * Docent of Student verwijderen.
     */

    public void removePersoon(Persoon p_soon)
    {
        // remove arraylist methode
        studocent.remove(p_soon);
    }
    
    /**
     * Docent of Student zoeken.
    */
   
    public void zoekPersoon(String zoek)
    {
       int foundP = 0;    
       // wij gaan door de database met Iterator 
       Iterator<Persoon> it = studocent.iterator();
       Pattern p = Pattern.compile(zoek);
      
        while (it.hasNext())
        {
            Persoon p_soon = it.next();
            // DEBUG
            // System.out.println(p_soon.achternaam);
            // DEBUG

            Matcher m = p.matcher(p_soon.achternaam);
            // DEBUG
            // System.out.println(matcher.lookingAt());
            // DEBUG
            if (m.matches()) // gelijk raak
            {
                p_soon.print();
                foundP =1;
            }
            else
            {
            // if (m.lookingAt()) // zoeken vanaf het begin
            // {
            //    p_soon.print();
            //    foundP = 1;
            // }
                if (m.find()) // vanaf begin zoeken hoeft niet
                {
                    p_soon.print();
                    foundP = 1;
                }
                else // we hebben nog niet gevonden
                {
                    zoek = zoek.substring(0,1).toUpperCase() + zoek.substring(1).toLowerCase(); // zet de eerste letter van de pattern op UPPERCASE
                    Pattern pc = Pattern.compile(zoek);
                    Matcher mc = pc.matcher(p_soon.achternaam);
                    
                  
                    if (mc.lookingAt()) // zoeken vanaf het begin. deze moet raak zijn anders falen we
                    {
                        p_soon.print();
                        foundP = 1;
                    }
                    mc.reset();
                }
            }
            
         m.reset();
        }
        if (foundP == 0)
        {
        // zero rows returned
            System.out.println("Persoon niet gevonden ");
        }
    }
   
   
    
    /**
     * Print de lijst van de slb studenten van de docent.
     */
    
    public void zoekStudentSlb(Docent myslb)
    {
        String slb = myslb.docentcode; // haal de docentcode uit de docent die genoemd wordt als myslb
        for(Persoon p : studocent)
        {
            if (p instanceof Student) // alleen studenten hebben een SLBer. p moet van het type Student zijn!
            {
            Student heeftslb=(Student) p;
                if (heeftslb.slbegeleider.equals(slb))
                // als de gezochte SLBer dezelfde is als de SLBer in het object, print deze dan 
                {
                    heeftslb.print();
                }
            }
        }
    }
       
    /**
     * Print de lijst van alle docenten en studenten.
     */
    
    public void list()
    {
        for(Persoon persoon : studocent)
        {
            // print iedere persoon in de database   
            // persoon.print(this); <-aan Ben vragen
            persoon.print();
        }
    }
}

Persoon superclass:
Code:
import java.util.Calendar;

/**
 *  
 * Dit is de superklasse voor docent en studenten.
 * De klasse Persoon heeft tenminste de variabelen naam, voornaam, geslacht en geboortedatum (gebruik java.util.Date of java.util.Calendar). 
 * @author () 
 * 
 */

/**
 * constructor superklasse
 */

public class Persoon
{
 // initieer superklasse velden
 public String achternaam;
 private String tussenvoegsel;
 private String voornaam;
 private String geslacht;
 private Calendar geboortedatum = Calendar.getInstance();
     
 // superklasse constructor
 public Persoon(String a_naam, String t_voegsel, String v_naam, String gesl, int jaar, int maand, int dag )
 {
        // verander de invoer opdat de eerste letter altijd een HOOFDLETTER is en de rest altijd een kleine letter
        achternaam = a_naam.substring(0,1).toUpperCase() + a_naam.substring(1).toLowerCase();
        tussenvoegsel = t_voegsel;
        voornaam = v_naam.substring(0,1).toUpperCase() + v_naam.substring(1).toLowerCase();
        geslacht = gesl;
        geboortedatum.clear();
        geboortedatum.set(jaar, maand, dag);    
 }
    
 /**
 * Laat de achternaam zien.
 */    

 public String getAchternaam()
 {
       return achternaam;
 }    

 /**
 * Verander de achternaam
 */   
   
 public void setAchternaam(String a_naam )
 {
       // verander de invoer opdat de eerste letter altijd een HOOFDLETTER is en de rest altijd een kleine letter
       achternaam = a_naam.substring(0,1).toUpperCase() + a_naam.substring(1).toLowerCase();
 }
   
 /**
 * Laat het tussenvoegsel zien.
 */    

 public String getTussenvoegsel()
 {
       return tussenvoegsel;
 }    

 /**
 * Verander het tussenvoegsel
 */   
   
 public void setTussenvoegsel(String t_voegsel )
 {
       tussenvoegsel = t_voegsel;       
 }  
   
 /**
 * Laat de voornaam zien.
 */    

 public String getVoornaam()
 {
       return voornaam;
 }    

 /**
 * Verander de voornaam
 */   
   
 public void setVoornaam(String v_naam)
 {
       // verander de invoer opdat de eerste letter altijd een HOOFDLETTER is en de rest altijd een kleine letter
       voornaam = v_naam.substring(0,1).toUpperCase() + v_naam.substring(1).toLowerCase();       
 }    
       
 /**
 * Laat het geslacht zien.
 */    

 public String getGeslacht()
 {
       return geslacht;
 }    

 /**
 * Verander het geslacht
 */   
   
 public void setGeslacht(String gesl)
 {
       // wij zijn zeer ruimdenkend
       geslacht = gesl;       
 }    

 /**
 * Laat de geboortedatum zien.
 */    

 public String getGeboortedatum()
 {
       // wij gebruiken hierbij Calendar ; zie ook de import statement
       int dag = geboortedatum.get(Calendar.DAY_OF_MONTH);
       int maand = geboortedatum.get(Calendar.MONTH);
       int jaar = geboortedatum.get(Calendar.YEAR);
       String geb_datum = ( dag + "-" + maand + "-" + jaar );
       return geb_datum;
 }    

 /**
 * Verander de geboortedatum
 */   
   
 public void setgeboortedatum(int jaar, int maand, int dag )
 {
       // clear en set zijn Calendar methods
       geboortedatum.clear();
       geboortedatum.set(jaar, maand, dag);   
 }     
       
 /**
 * Methode om de leeftijd te vergelijken
 */
  
 public static void vergelijkLeeftijd(Persoon persoon1, Persoon persoon2 )
 {
       // before en after zijn Calendar methodes (eigenlijk util methods)
       if ( persoon1.geboortedatum.before(persoon2.geboortedatum) )
       {
           // persoon1 is ouder
           System.out.println( persoon1.achternaam + " is ouder dan " + persoon2.achternaam );
       }
       else if ( persoon1.geboortedatum.after(persoon2.geboortedatum) )
       {
           // persoon2 is ouder
           System.out.println( persoon1.achternaam + " is jonger dan " + persoon2.achternaam );
       }    
       else
       {
           // persoon1 en persoon2 hebben zelfde leeftijd
           System.out.println(persoon1 + " is even oud als " + persoon2); 
       }    
 }      
    
 /**
 * Methode om de achternaam te vergelijken
 */
  
 public static void vergelijkAchternaam(Persoon persoon1, Persoon persoon2)
 {
       // ik plak de achternaam en voornaam aan elkaar vast 
       // vergelijk van achter naar voor ivm gelijke achternamen
         
         //Collator myDefaultCollator = Collator.getInstance();
              
       String astr1 = (persoon1.achternaam);
       String vstr1 = (persoon1.voornaam);
       String astr2 = (persoon2.achternaam);
       String vstr2 = (persoon2.voornaam);
       
       String vergelijk1 = astr1.concat(vstr1);
       String vergelijk2 = astr2.concat(vstr2);

       //DEBUG
       // System.out.println(vergelijk1);
       // System.out.println(vergelijk2);
       //DEBUG
       // String persoon1anaam = persoon1.achternaam;
       // String persoon1vnaam = persoon1.voornaam;
       // String persoon2anaam = persoon2.achternaam;
       // String persoon2vnaam = persoon2.voornaam;
       
       // if (myDefaultCollator.compare(vergelijk1, vergelijk2) < 0)
       
       // compareTo objecten vergelijken
       if (vergelijk1.compareTo(vergelijk2) == 0)
       {
        System.out.println(persoon1+" heeft dezelfde naam als "+persoon2);
       }
       else
       if (vergelijk1.compareTo(vergelijk2) < 0)
       {
           System.out.println(vstr1+" "+astr1+" komt eerder in het alfabet voor dan "+vstr2+" "+astr2);
       }
       else
       {
           System.out.println(vstr2+" "+astr2+" komt eerder in het alfabet voor dan "+vstr1+" "+astr1); 
       }    
 }    



 /**
 * Standaard printfunctionaliteit voor de superklasse, wordt in de subklasses aangevuld met de
 * voor de subklasse specifieke velden
 */    
    
 public void print()
 {
        if ( tussenvoegsel.equals(""))
        { 
            // wij houden rekening met het ontbreken van een tussenvoegsel
            System.out.println("Naam              : " + voornaam + " " + achternaam);
        } 
        else
        {
            System.out.println("Naam              : " + voornaam + " " + tussenvoegsel + " " + achternaam);
        }    
        
        if ( geslacht.equals(""))
        {
            // mogelijk dat geslacht nog niet is ingevuld...
            System.out.println("Geslacht          : " + geslacht);
        }
        else
        {
            System.out.println("Geslacht          : " + geslacht);
        }
        
        System.out.println("Geboortedatum     : " + geboortedatum.get(Calendar.DAY_OF_MONTH) + "-" + geboortedatum.get(Calendar.MONTH) + "-" + geboortedatum.get(Calendar.YEAR));
        
 }
}

Student class:
Code:
/**
 * 
 * De klasse Student is een uitbreiding van Persoon met de uitbreiding van Student specifieke kenmerken en methodes
 * De student heeft als extra informatie de studierichting en een verwijzing naar de docent die zijn of haar SLB-er is. 
 * Er is een aangepaste print-methode en methoden om de extra variabelen op te vragen of te veranderen
 * @author () 
 * 
 */

public class Student extends Persoon
{
 private String studierichting;
 public String slbegeleider;
 /**
 * Constructor voor de sub klasse Student met Student specifieke velden
 */    

   public Student(String a_naam, String t_voegsel, String v_naam, String gesl, int jaar, int maand, int dag, String s_richting, Docent slb )
    {
        super(a_naam, t_voegsel, v_naam, gesl, jaar, maand, dag);
        studierichting = s_richting;
        slbegeleider = slb.docentcode;
    }    

 /**
 * Laat de studierichting zien.
 */    

   public String getStudierichting()
   {
       return studierichting;
   }    

 /**
 * Verander de studierichting
 */   
   
   public void setStudierichting(String s_richting )
   {
       studierichting = s_richting;
   }    

 /**
 * Laat de studie loopbaan begeleider zien.
 */    

   public String getStudieloopbaanbegeleider()
   {
       return slbegeleider;
   }    

 /**
 * Verander de studierichting
 */   
   
   public void setStudierichting(Docent slb)
   {
       slbegeleider = slb.docentcode;
   }   
      
 /**
 * Printfunctie waarbij de print functie uit de superklasse aangevuld wordt met specifieke velden
 * uit de subklasse
 */    
   public void print()
    { 
        // print de info uit de superklasse eerst
        super.print();
        // print de locale velden
        System.out.println("Studierichting    : " + studierichting);
        System.out.println("Studiebegeleider  : " + slbegeleider);
        System.out.println();       
    }   
    
}

Docent class:
Code:
/**
 * 
 * De klasse Docent is een uitbreiding van Persoon met de uitbreiding van Docent specifieke kenmerken en methodes
 * Er is een aangepaste print-methode en methoden om de extra variabelen op te vragen of te veranderen.
 * Docent bevat extra informatie: docentcode en salarisschaal. 
 * @author () 
 * 
 */

public class Docent extends Persoon
{
 public String docentcode;
 private int salarisschaal;
   
 /**
 * Constructor voor de sub klasse Docent met Docent specifieke velden
 */  

   public Docent(String a_naam, String t_voegsel, String v_naam, String gesl, int jaar, int maand, int dag, String d_code, int s_schaal )
   {
        super(a_naam, t_voegsel, v_naam, gesl, jaar, maand, dag );
        docentcode = d_code;
        salarisschaal = s_schaal;
   }    

 /**
 * Laat de docentcode zien.
 */    

   public String getDocentcode()
   {
       return docentcode;
   }    

 /**
 * Verander de docentcode
 */   
   
   public void setDocentcode(String d_code )
   {
       docentcode = d_code;
   }    

 /**
 * Laat de salarisschaal zien.
 */    

   public int getSalarisschaal()
   {
       return salarisschaal;
   }    

 /**
 * Verander de salarisschaal
 */   
   
   public void setSalarisschaal(int s_schaal)
   {
       salarisschaal = s_schaal;
   }   
   
   
 /**
 * Printfunctie waarbij de print functie uit de superklasse aangevuld wordt met specifieke velden
 * uit de subklasse
 */ 

   public void print()
   { 
       // print de info uit de superklasse eerst 
       super.print();
       // print de locale velden
       System.out.println("Docentcode        : " + docentcode);
       System.out.println("Salarisschaal     : " + salarisschaal);
       System.out.println();       
   }    
}
 

Attachments

  • layout.png
    layout.png
    15 KB · Views: 37

Jupitus

Old and short, no wonder I'm grumpy!
Staff member
Moderator
FH Subscriber
Joined
Dec 14, 2003
Messages
3,396
Fucking LOL!!!! :lol::lol:








































:worthy:
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
hah, given I knew nothing of this until recently I'm not horribly displeased.

constructive criticism is welcome. if you're going to show me something weird, please explain what it is :D
 

JingleBells

FH is my second home
Joined
Mar 25, 2004
Messages
2,224
hah, given I knew nothing of this until recently I'm not horribly displeased.

constructive criticism is welcome. if you're going to show me something weird, please explain what it is :D

Did you have to implement print like that? I'd have done it using an overridden toString method so you can just do System.out.println(myStoodent) and instead of getting Stoodent@[12312313 you get what you want for your stoodent.

The advantage of this is that you remove System.out.println method calls from your object code and you can use them (or alternatively a nice log4j/sl4j log file) in code that actually uses the object - using System.out.println by default is annoying you're running it from a j2ee container :)
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
yeah JB I know what you mean. we've only learned about System.out.println() atm so that is more or less what I am forced to use. As you can see, I have to be creative to get around the fact that printing objects with populated fields doesn't return a list of said fields, but as you say, the class name and the hash code.

I will rewrite the code with the custom toString() method and show it to you guys. Please note: this kinda is my homework, so please don't help me with super duper stuff I won't understand hehe :)
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
yo! I did some experimenting with the custom toString(), especially as I have to have the text coming out look reasonably formatted. At first I couldn't get it to look nice, but then I hit on the idea to send some newline codes along with the return and now all is spanky.

This is what I came up with, now to faff it into the other code :)
std (sic) student class
Code:
public class std {
	
	public String gn;
	public String sn;
	public int ag;
	
	public std(String gn, String sn, int ag)
	{
		this.gn = gn;
		this.sn = sn;
		this.ag = ag;
	}
	
	// custom toString()
	public String toString() {
		return "Given name= " +gn+ "\n" + "Surname= " +sn+ "\n" + "Age= " +ag;
	}
}

test print class to faff
Code:
public class tp {

	public static void main(String args[])
	{
		std student = new std("Teedlar","Giantcox",36);
		System.out.println(student);
		System.out.println();
	}
}
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
it's been integrated into the other program and works a charm! booyah!
 

Users who are viewing this thread

Top Bottom